Positive z-value flips 3d program (Pure Java)

Hey guys,

so I have been coding a 3d projection in Java2D (don’t judge me, testing purposes only :point:) and I ran into this problem: when the camera Z is greater than 0, the program flips and acts in reverse(see gif) when in reality, the camera should just pass the cube. Any ideas.

http://zippy.gfycat.com/TartEcstaticCopepod.gif

This converts 3d points into 2d for drawing



	public Vector3 processPoint(Vector3 point) {//point : the original point
		Vector3 projection = new Vector3();//output point

		if (orthographic) {
			projection.xyz[0] = position.x() + this.position.x();//position : the camera position ->Vector3
			projection.xyz[1] = position.y() + this.position.y() + position.z();
		} else {

			double zdis = point.z() - position.z();
			if (position.z() > 0) {
				Math.abs(point.z() - position.z());
			}
			point.rotateXAround(Math.toRadians(rotX), position);//rotX = 0
			point.rotateYAround(Math.toRadians(rotY), position);//rotY = 0
			point.rotateZAround(Math.toRadians(rotZ), position);//rotZ = 0

			projection.xyz[0] = ((-position.x() + point.x()) * (MainWindow.frame
					.getWidth() / zdis)) + MainWindow.frame.getWidth() / 2;//new x value
			projection.xyz[1] = ((-position.y() + point.y()) * (MainWindow.frame
					.getHeight() / zdis)) + MainWindow.frame.getHeight() / 2;//new y value

		}
		return projection;//this works great with camera z values below 0

	}


That’s what happens in 3D projection when you have no front clip.

Oh ok, I fixed it now thanks! One more question, how can I make a 3d point rotate around another point? My current method doesn’t work:


	public void rotateYAround(double angle, Vector3 origin) {
		if (angle != 0) {
			Float oldZ = (float) xyz[2];
			/*z*/xyz[2] = (float) ((xyz[2]-origin.z()) * Math.cos(angle) - (xyz[0]-origin.x()) * Math.sin(angle));
			/*x*/xyz[0] = (float) ((oldZ-origin.z()) * Math.sin(angle) + (xyz[0]) * Math.cos(angle));
		}
	}