View Full Version : camera simulation

04-08-2005, 02:49 AM
Hi, I would like to simulate a camera under opengl.
I use glFrustrum and I know the matrix 3 by 4 which maps a world coordinate point to pixel coordinates.

However when I print the projection matrix (4 by 4!), it does not look like my 3 by 4 matrix!
I set the modelview to identity and the viewport to:

What is the mathematical relationship between these matrices?


04-08-2005, 03:31 AM
Can you give more precision ? Regarding this is an topic on the advanced forum, I guess this is not because of how gl representates a matrix. If so, we're expecting a bit of code.

04-08-2005, 03:43 AM
The projection matrix transforms vertices to clip space. That is, you have not exactly the pixel coordinates of the vertex, but the coordinates in the range -1..1 (after division by w).

To get pixel coordinates, you have to scale the x and y coordinates to the correct width and height (x *= width/2), and offset the coordinates by width/2, height/2 (0.0 is the center of the screen, not an edge...).

EDIT: Whoops, sorry. Corrected the coordinate range, of course it is -1..1, not 0..1 ;)