Sign in to follow this  
wangdiweilu

The relation between glLookAt() and GL_MODELVIEW

Recommended Posts

wangdiweilu    122
Can Glmatrixmode(GL_MODELVIEW) and glLookAt be setted at the same time?how can I obtain the 9 parameters of glLookAt from Glmatrixmode(GL_MODELVIEW)?

Share this post


Link to post
Share on other sites
Lord_Evil    680
glMatrixMode(GL_MODELVIEW) means that every call to one of OpenGL's matrix functions like glIdentity, glMultMatrix etc. now will affect the modelview matrix instead of the projection matrix.

glLookAt creates a basic modelview matrix that represents the camera position and orientation and IIRC it calls glLoadMatrix(cameramatrix) internally. So it sets the current matrix to the camera matrix. You need to call glMatrixMode(GL_MODELVIEW) to ensure that the modelview matrix and not the projection matrix is set.

Share this post


Link to post
Share on other sites
Necator    239
I think you might have the concepts a bit mixed.

The matrix mode decides which matrix you will affect when changing any built-in OpenGL matricies.

The gluLookAt command basically calculates a view matrix for the camera given the positions given in the call. It then multiplies it to the current matrix.

For obtaining the 9 parameters, you can't. At least not exactly the ones you created the matrix with.

You can obtain the camera position by multiplying the matrix with a (0,0,0,1) vector which will give you the translation. The forward and up vectors can be obtained in a similar way. Given that the coordinate system of the camera has the Z pointing into the screen and Y pointing up, you can obtain the forward vector by multiplying (0,0,1,0) and the up vector with (0,1,0,0).

Then you can caulculate a point in the forward direction by cameraPos+forwardVector*length, however it will not necessarily be the same point since you don't know what length was origionally used.

The up vector can be calculated in a similar manner, note however that the up vector is usually not preserved correctly since you basically caluclate

rightVector = forwardVector x upVector
newUpVector = rightVector x forwardVector

in order to obtain an ortho base (normalization is also performed).

Sorry if the explanation is a bit messy, a bit tired atm =)

Share this post


Link to post
Share on other sites
wangdiweilu    122
if I don't set gluLookAt(),the system can give a default the gluLookAt? if the
modelview matrix is changing continuously ,the default gluLookAt also changes ?

Share this post


Link to post
Share on other sites
Richy2k    313
gluLookAt is simply to build a lookat matrix which is used as the modelview. You can partially get the look at parameters back with a bit of work, but I wouldn't really bother to be honest.

As far as I know there is no default matrix, although typically a default would be an identity matrix. That pretty much leaves you looking down the Z axis and the up vector as ( 0, 1, 0 ).

Share this post


Link to post
Share on other sites
V-man    813
Quote:
Original post by Lord_Evil
glMatrixMode(GL_MODELVIEW) means that every call to one of OpenGL's matrix functions like glIdentity, glMultMatrix etc. now will affect the modelview matrix instead of the projection matrix.

glLookAt creates a basic modelview matrix that represents the camera position and orientation and IIRC it calls glLoadMatrix(cameramatrix) internally. So it sets the current matrix to the camera matrix. You need to call glMatrixMode(GL_MODELVIEW) to ensure that the modelview matrix and not the projection matrix is set.



In the source code of GLU, it isn't glLoadMatrixf(cameramatrix), it is glMultMatrixf(cameramatrix)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this