Considering as a perspective matrix the result of multiplying a view matrix (in opengl GL_MODELVIEW) by a projection matrix (GL_PROJECTION) how can I get the coordenates of the origin (the point of intersection of the lateral fustrum planes, or top of the pyramid)?
persp_mat_4x4 = view_mat_4x4 × proj_mat_4x4
If I had the view_matrix available, I could calculate the origin simply by calculating the inverse of that matrix and reading the values in the 4th column.
orig = (viewmat_inv_4x4[0][3], viewmat_inv_4x4[1][3], viewmat_inv_4x4[2][3])
One option would be to calculate the intersection point of 3 planes of the fustrum. (homogeneous 4d vector representations of planes):
plane_orig_v4 = persp_mat_4x4[3].xyzw
plane_left_v4 = plane_orig_v4 + persp_mat_4x4[0].xyzw
plane_bott_v4 = plane_orig_v4 + persp_mat_4x4[1].xyzw
orig = intersect_plane_plane_plane(plane_orig_v4, plane_left_v4, plane_bott_v4)
But this solution is neither accurate nor efficient. I wanted a simple algorithm to calculate that orig. I hope I have been clear and that you can help me :)
After much analysis, I have found that the best solution is to obtain the intersection of the 3 planes v4 represented by lines 0, 1 and 3 of the matrix.
Here is a pseudo code: