I am trying to project a series of three-dimensional points onto a screen using a perspective camera matrix. I donβt have world space (or consider it to be a single matrix) and my camera does not have space for the camera (or consider it an identity matrix), I have a 4x4 matrix for my object space.
I take the object matrix and multiply it by the camera perspective matrix created in the following way:
Matrix4 createPerspectiveMatrix( Float fov, Float aspect, Float near, Float far ) { Float fov2 = (fov/2) * (Math.PI/180); Float tan = Math.tan(fov2); Float f = 1 / tan; return new Matrix4 ( f/aspect, 0, 0, 0, 0, f, 0, 0, 0, 0, -((near+far)/(near-far)), (2*far*near)/(near-far), 0, 0, 1, 0 ); }
Then I take my point [x, y, z, 1] and multiplying it by the result of multiplying the perspective matrix and the object matrix.
In the next part, I get confuzzled, I am sure that I need to get these points within the ranges -1 or 1, or 0 and 1, and, if there was a first set of values, I would then multiply the points by the width and height of the screen for the coordinate x and y of the screen in the same way or multiplied the values ββby the screen height / 2 and width / 2 and added the same values ββto the corresponding points.
Any step by step telling me how this can be achieved, or where I could go wrong with any of this, would be very helpful !: D
Best wishes!
PS In the example of the identity / translation matrix, my matrix format is in my model:
[1, 0, 0, tx, 0, 1, 0, ty, 0, 0, 1, tz, 0, 0, 0, 1 ]