wangdiweilu 122 Report post Posted May 11, 2007 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)? 0 Share this post Link to post Share on other sites
Lord_Evil 680 Report post Posted May 11, 2007 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. 0 Share this post Link to post Share on other sites
Necator 239 Report post Posted May 11, 2007 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 caluclaterightVector = forwardVector x upVectornewUpVector = rightVector x forwardVectorin order to obtain an ortho base (normalization is also performed).Sorry if the explanation is a bit messy, a bit tired atm =) 0 Share this post Link to post Share on other sites
wangdiweilu 122 Report post Posted May 12, 2007 if I don't set gluLookAt(),the system can give a default the gluLookAt? if themodelview matrix is changing continuously ,the default gluLookAt also changes ? 0 Share this post Link to post Share on other sites
Richy2k 313 Report post Posted May 13, 2007 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 ). 0 Share this post Link to post Share on other sites
V-man 813 Report post Posted May 14, 2007 Quote:Original post by Lord_EvilglMatrixMode(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) 0 Share this post Link to post Share on other sites