Jump to content
  • Advertisement
Sign in to follow this  
kcauwert

OpenGL GL_PROJECTION and GL_MODELVIEW matrices

This topic is 4564 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

Hi all, I want to display some OpenGl cubes on top of an image taken by a camera. The equations to convert from world coord system(XYZ) to image coordinates(uv) are given below. How can I plug in the focal length(fx,fy) and principal point(cx,cy) into the OpenGL projection matrix? How do I have to set the GL_PROJECTION and GL_MODELVIEW matrices to obtain the same projection result as in the case of using the equations below? /******************************************** // Projection equations. // (R,T,fx,fy,cx,cy are know after a calibration step) double x = R[0]*X + R[1]*Y + R[2]*Z + T[0]; double y = R[3]*X + R[4]*Y + R[5]*Z + T[1]; double z = R[6]*X + R[7]*Y + R[8]*Z + T[2]; z = z ? 1./z : 1; x *= z; y *= z; int u = x*fx+cx; int v = y*fy+cy; Thanks

Share this post


Link to post
Share on other sites
Advertisement
Quote:
double x = R[0]*X + R[1]*Y + R[2]*Z + T[0];
double y = R[3]*X + R[4]*Y + R[5]*Z + T[1];
double z = R[6]*X + R[7]*Y + R[8]*Z + T[2];


The above easily fits into a modelview matrix.
R[0], R[1], R[2], T[0]
R[3], R[4], R[5], T[1]
R[6], R[7], R[8], T[2]
0, 0, 0, 1

Quote:
z = z ? 1./z : 1;
x *= z; y *= z;
int u = x*fx+cx;
int v = y*fy+cy;


I think
1, 0, 0, 0
0, 1, 0, 0
0, 0, 1, 0
0, 0, -1, 0

will do the first 2 lines. I don't know about the last 2.
Is u and v suppose to be screen space?
The GL viewport works in a different way.
Have you considered writing a vertex shader.

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!