View Full Version : help to set up correct model view matrix

xueming1164

02-27-2009, 01:28 PM

Hi,

I have a very simple problem, but I can not figure out what is wrong.. Basically, I manually set up a model view matrix (e.g. modelview[16], and projection matrix for off screen rendering.. When I use gluproject to check, I find out that winx is correct, but winy is up-side down and winz > 1.0. So when I try to use glreadpixel to get the color back, all I get is background color. I think it must be caused by the flip sign in modelview matrix. Can somebody help?

Thanks.

dletozeun

02-27-2009, 02:35 PM

Does gluProject returns GL_FALSE? If it does, your perpective matrix might be set up badly. gluPorject returns false, when the 4th coordinate is zero after perspective transformation.

xueming1164

02-27-2009, 02:52 PM

it returns 1. Thanks for the answering.. I think the view somehow gets flipped, but I don't know how to fix it.

Abdallah DIB

02-27-2009, 03:03 PM

opengl is a right handed coordinate system ; where positive z axis pointing out of the screen and positive x axes points from left to right and positive y axes is the up

when u try to contstruct ur modelview matrix verify well the sign of ur translation vector and rotation matrix,

for constructing ur projection matrix , it depends on the focal length (fx and fy in pixels) of the camera and the optical center(cx,cy), and the width and height of the camera image

then ur frustum will be :

glFrustum(-znear*cx/fx,znear*(width-cx)/fx,-znear*cy/fy,znear*(height-cy)/fy,znear,zfar);

note here that opengl dont generate distorted images!only linear.

than call glGetDoublev( GL_PROJECTION_MATRIX, ProjectionMatrix);

opengl will return for u the approriate ProjectionMatrix for ur frustum( if u like to construct manualy the projection matrix check doc of glFrustum)

overlay

02-27-2009, 05:15 PM

No, OpenGL is not right-handed. I did not say is left-handed either... :-)

It depends of which coordinate system you are talking about and it depends on the values of the parameters you use:

#1 From the spec page 309 (pdf page 323), item 15: "OpenGL does not force left- or right-handedness on any of its coordinates systems. Consider, however, the following conditions:

o (1) the object coordinate system is right-handed;

o (2) the only commands used to manipulate the model-view matrix are Scale (with positive scaling values only), Rotate, and Translate;

o (3) exactly one of either Frustum or Ortho is used to set the projection matrix;

o (4) the near value is less than the far value for DepthRange.

If these conditions are all satisfied, then the eye coordinate system is right-handed and the clip, normalized device, and window coordinate systems are left-handed."

#2 From the OpenGL FAQ 9.150: "9.150 Can I make OpenGL use a left-handed coordinate space? OpenGL doesn't have a mode switch to change from right- to left-handed coordinates. However, you can easily obtain a left-handed coordinate system by multiplying a negative Z scale onto the ModelView matrix. For example:

glMatrixMode (GL_MODELVIEW); glLoadIdentity (); glScalef (1., 1., -1.); /* multiply view transforms as usual... */ /* multiply model transforms as usual... */

#3 From the spec page 45 (pdf page 59), about the Rotate function: "The computed matrix is a counter-clockwise rotation about the line through the origin with the specified axis when that axis is pointing up (i.e. the right-hand rule determines the sense of the rotation angle).

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.