Calculating the new x position

Honestly I have no goddamn clue what the hell is going on with this I want it to rotate around the camera via the y axis it doesnt even make a square it just shoots around the place for no reason…

package lcass.com.graphics;

import lcass.com.control.Camera;
import lcass.com.core.core;
import lcass.com.graphics.objects.vertex;

public class RENDER3D {
	private core core;

	public RENDER3D(core core) {
		this.core = core;
	}

	public void drawvertex(vertex v, Camera c,double rotx,double roty) {
	
		double cz = c.z;
		
		double dist = Math.abs(v.z - cz);
		double tx = v.x - c.x;
		double ty = v.y - c.y;
		double tz = v.z - c.z;
		
		double nx = tx * Math.cos(roty) - ty * Math.sin(roty);
		double ny = tx * Math.sin(rotx) + ty * Math.cos(rotx);
		double nz = tz* Math.cos(roty);
		double adist = Math.abs(nz-c.z);
		double dx = 0;
		double dy = 0;
		System.out.println(dist);
		double scale = 512 /adist;
		
	
			dx = (nx) * (scale /adist)+ (core.WIDTH / 2);
			dy = (ny)* (scale / adist)+ (core.HEIGHT / 2);
		
		
		if (dx < core.WIDTH && dy < core.HEIGHT) {
			if (dx > 0 && dy > 0 && nz >=0) {
				core.screen.map[(int) dx][(int) dy] = 0xFF00FF;
			}
		}
	}
}

Ok so this code works for moving foward backward up down left right but how would I rotate For example minecraft rotation like that turning the camera.

public class RENDER3D {
	private core core;

	public RENDER3D(core core) {
		this.core = core;
	}

	public void drawvertex(vertex v, Camera c,double rotx,double roty) {
	
		double cz = c.z;
		
		double dist = Math.abs(v.z - cz);
		double tx = v.x - c.x;
		double ty = v.y - c.y;
		double tz = v.z - c.z;
		double dx = 0;
		double dy = 0;
		double scale = 512 /dist;
		
	
			dx = (tx) * (scale /
					tz)+ (core.WIDTH / 2);
			dy = (ty)* (scale / tz)+ (core.HEIGHT / 2);
		
		
		if (dx < core.WIDTH && dy < core.HEIGHT) {
			if (dx > 0 && dy > 0 ) {
				core.screen.map[(int) dx][(int) dy] = 0xFF00FF;
			}
		}
	}
}

No wonder its not rotating, you’re not doing anything with your input params rotx and roty.

Take a look at http://www.genesis3d.com/~kdtop/Quaternions-UsingToRepresentRotation.htm , that should get you started.

I know that :stuck_out_tongue: that is the code I was using for moving that worked.

I think instead of sin sin its sin cos also would the radius be cuberoot(x-xx)2+(y-yy)2+(z-zz)2) with the 2 being square?

x’=zsin(yaw)+xcos(yaw)
y’=y
z’=zcos(yaw)-xsin(yaw)

x"=x’
y"=y’*cos(pitch)-z’*sin(pitch)
z"=y’*sin(pitch)+z’*cos(pitch)

x"’=y"*sin(roll)+x"*cos(roll)
y"’=y"*cos(roll)-x"*sin(roll)
z"’=z"

No, the formula I posted works.

okly just checking :slight_smile:

Opiop in your code what is the radius equal to is it the sqrt((xx)+(yy)+(z*z)) ??

No, the radius is just half the size of the sphere. So say you want to have your code pick an object 4 tiles ahead of you, you would set the radius to 4. Thats it!

Oh thanks lol I was vizualising it in my head thing this is a bit odd :slight_smile: