How are 3D coordinates related to perspective projection?

How are 3D coordinates related to perspective projection?

Basically, every object has a Z even though it is in 2D, and similarly to parallax layers their position, scale and rotation speed vary based on their Z. I guess this would be a perspective projection. But I am having trouble converting the objects’ 3D coordinates into the 2D space of the screen so that everything has correct perspective and scale.

How to map 3D object coordinates to 2D screen?

You can do this simply by converting [-1,+1] to [0,+1] (add 1, multiply by 0.5) then scale appropriately (multiply by width or height). This can be put in matrix form if that’s easier for you. I notice that you aren’t using homogenous coordinates for your transformation.

How to convert 3D object coordinates to homogenous coordinates?

Converting to homogenous coordinates is next as RobCurr pointed out (my Vector3 implementation has a w component) and finally to clip and screen space. The perspective projection done in toClipSpace using a perspective transform matrix does not give me the screencoordinates yet and still stores the depth of each vertex in the z component.

How to get perspective corrected co ordinates in Java?

To obtain the perspective-corrected co-ordinates, just divide by the z co-ordinate: The above works assuming that the camera is at (0, 0, 0) and you are projecting onto the plane at z = 1 — you need to translate the co-ords relative to the camera otherwise.

How to get coordinates of Mouse in 3D space?

This question looks like a similar issue but doesn’t have a solution: Getting coordinates of the mouse in relation to 3D space in THREE.js

How to convert a 3D object to a 2D point?

Just in the last toScreenSpace operation I convert the 3D point into a 2D point. Because I previously converted the vertex into normal devices space, zero is in the center of the screen and values range between +1 and -1. Simply dividing by z gives you the depth.