Question

Im having an issue with calculating screen coordinates of a vertex. this is not a specifically a webgl issue, more of a general 3d graphics issue.

the sequence of matrix transformations that Im using is:

result_vec4 = perspective_matrix * camera_matrix * model_matrix * vertex_coords_vec4

model_matrix being the transformation of a vertex in its local coordinate system into the global scene coord system. so my understanding is that the final result_vec4 is in clip space? which should then be in the [-1,1] range. which is not what Im getting... result_vec4 just ends up containing some standard values for the coords, not corresponding to the correct screen position of the vertex.

does anyone have any ideas as to what might be the issue here? thank you very much for any thoughts.

Was it helpful?

Solution

To go in clip space you need to project result_vec4 on the hyperplane w=1 using:

result_vec4 /= result_vec4.w

By applying this perspective division result_vec4.xyz will be in [-1,1].

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top