Jump to content
  • Advertisement
Sign in to follow this  

Convert to Viewport Coordinates

This topic is 4774 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How do I Convert a point in model world coordinates to window coordinates? Sorry, It sounds obvious. But the fact is this: I have a point given in world coordinates: P = {x1, y1, z1} The main task is to convert that point to viewport coordinates, The viewport has the following rules: struct VIEWPORT { float m_left; /// =0 minimun value float m_right; ///=1.0f maximun value float m_top; //=0 minimun value float m_bottom; //=1.0f maximun value float m_znear; ///=0.0f minimun value float m_zfar; ///=1.0f maximun value } The camera system is given as a 4x4 matrix: C = | l1 u1 d1 t1| | l2 u2 d2 t2| | l3 u3 d3 t3| | 0 0 0 1 | At last, the projection matrix Proj is calculated as following: /* l is Frustum left = -0.5 r is Frustum Right = 0.5 t is Frustum Top = 0.5 b is Frustum Bottom = -0.5 zn is Frustum Near = 1.0 zf is Frustum Far = 100.0 */ Matrix4Zero(Proj ); ///convert to 0 matrix Proj._11 =2*zn/(r-l); Proj._22 =2*zn/(t-b); Proj._13 =(r+l)/(r-l); Proj._23 =(t+b)/(t-b); Proj._33 =-(zf+zn)/(zf-zn); Proj._43 =-1; Proj._34 =-2*zn*zf/(zf-zn); Well, at this point, I think that to convert a point to viewport coordinates I have to do this: Cinv = Matrix4Inverse(C); //convert point to camera space Pc = Cinv*P; ///project point to screen Pv = Proj * Pc So, I expect that Pv.x is in range of {0,1} Pv.y is in range of {0,1}, inverted Pv.z is in range of {0,1} But It doesn't Happen! Pv has strange values, and I don't understand why, If C and Proj were the matrices that I pass to OpenGL and they work fine, but when I try to do the transformation by hand, It doesn't work! Thanks.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!