equivelant matrices in OGL/D3D
Ok. I have been working with D3D for some time now. I have also used OpenGl. There is something that puzzles me about the way matrices work in OpenGl
in Direct3D you have the:
D3DTRANSFORMSTATE_WORLD: i use this for setting the matrix of my models
D3DTRANSFORMSTATE_VIEW i use the inverse of my camera matrix for this
D3DTRANSFORMSTATE_PROJECTION a projection matrix which converts finilized 3D points to 2D points
this all seems very logical. In openGl however things are different. There is only 2 matrices which i can work with:
GL_MODELVIEW which i assume i would use for the models'' matrices
and GL_PROJECTION which would be the projection matrix. There seems to be a missing GL_VIEW or GL_CAMERA. What am i supposed to do? where exactly should i apply the matrix for my camera? To get around this before, i pre-multiplied the inverse of camera matrix with the matrix of every model, every frame. This is not exactly an efficient way though. Could anyone give me any hints?
Thanks
Ooops wrong Forum. Sorry. But I guess whoever reads the DX/OGL forum, reads this one as well
Modeling and Viewing use the same matrix in OpenGL, GL_MODELVIEW. It makes sense if you think about it. What''s the difference in moving the world back x units or moving the camera forward x units? The result will look the same either way.
Okay, I have experience with this craziness. ![](wink.gif)
For some reason, DirectX splits the ModelView matrix into two seperate matrices. In the same respect, for some reason OpenGL has them as one... No matter... Here is how I handle things.
Before I render a scene in OpenGL I initialize the modelview matrix to the camera''s matrix, which as you said before can be taken as being the inverse of a any normal (4 x 4 with 3 x 3 being orientation and last row being translation) orientation matrix.
This can be achieved either by doing a glLoadMatrix on the modelview with the camera matrix as an argument, or glMatMult... It depends on if you want any basic transformation performed on the camera matrix to begin with... for instance, converting between right-handed and left-handed if you like.
I then push this view matrix...
When I am about to draw a model I perform a glMultMat with that models'' matrix thus multiplying the Model''s matrix with the Camera (View) matrix... This is the part of the pipeline DirectX sort of does for you.
Once you''ve drawn the model, you POP the matrix thus restoring the original view matrix, and continue the process.
Render() {
glMatrixMode(GL_MODELVIEW); // make sure we are in modelview
glPushMatrix(); // store the BASE view matrix.
glMatrixMultf((float *)&m_camera); // put in new camera.
for(i = 0; i < modelCount; i++) {
glPushMatrix(); // store this camera for the entire scene.
// multiply in model''s matrix
glMatrixMultf((float *)&m_modelList.myMatrix);
//// ////
// MODEL DRAWING CODE GOES HERE //
//// ////
glPopMatrix(); // restore camera for next model.
}
glPopMatrix();
}
I''m not 100% sure about the names of the gl functions... I can never remember those silly things off hand.. could be glMatrixPush instead.![](wink.gif)
Anyways, that''s the basic idea... This works just fine... The project matrices are handled the same way... OpenGL also has a GL_TEXTURE_MATRIX which is used in it''s automatic texture generation system... I haven''t gotten to mess with this TOO much though.
Danny
![](wink.gif)
For some reason, DirectX splits the ModelView matrix into two seperate matrices. In the same respect, for some reason OpenGL has them as one... No matter... Here is how I handle things.
Before I render a scene in OpenGL I initialize the modelview matrix to the camera''s matrix, which as you said before can be taken as being the inverse of a any normal (4 x 4 with 3 x 3 being orientation and last row being translation) orientation matrix.
This can be achieved either by doing a glLoadMatrix on the modelview with the camera matrix as an argument, or glMatMult... It depends on if you want any basic transformation performed on the camera matrix to begin with... for instance, converting between right-handed and left-handed if you like.
I then push this view matrix...
When I am about to draw a model I perform a glMultMat with that models'' matrix thus multiplying the Model''s matrix with the Camera (View) matrix... This is the part of the pipeline DirectX sort of does for you.
Once you''ve drawn the model, you POP the matrix thus restoring the original view matrix, and continue the process.
Render() {
glMatrixMode(GL_MODELVIEW); // make sure we are in modelview
glPushMatrix(); // store the BASE view matrix.
glMatrixMultf((float *)&m_camera); // put in new camera.
for(i = 0; i < modelCount; i++) {
glPushMatrix(); // store this camera for the entire scene.
// multiply in model''s matrix
glMatrixMultf((float *)&m_modelList.myMatrix);
//// ////
// MODEL DRAWING CODE GOES HERE //
//// ////
glPopMatrix(); // restore camera for next model.
}
glPopMatrix();
}
I''m not 100% sure about the names of the gl functions... I can never remember those silly things off hand.. could be glMatrixPush instead.
![](wink.gif)
Anyways, that''s the basic idea... This works just fine... The project matrices are handled the same way... OpenGL also has a GL_TEXTURE_MATRIX which is used in it''s automatic texture generation system... I haven''t gotten to mess with this TOO much though.
Danny
May 06, 2001 12:51 AM
But the question is, if you are using both D3D and OpenGL in the same program,
can you use the same matrices for both?
In D3D, you have:
D3DXMATRIX M = D3DXMATRIX ( x,x,x,x,
x,x,x,x,
x,x,x,x,
x,x,x,x );
And in OpenGL, you have:
FLOAT M[16] = { x,x,x,x,
x,x,x,x,
x,x,x,x,
x,x,x,x };
Can you use the same matrix math for both to do transformations and such?
Rotating, translating, scaling, etc..?
can you use the same matrices for both?
In D3D, you have:
D3DXMATRIX M = D3DXMATRIX ( x,x,x,x,
x,x,x,x,
x,x,x,x,
x,x,x,x );
And in OpenGL, you have:
FLOAT M[16] = { x,x,x,x,
x,x,x,x,
x,x,x,x,
x,x,x,x };
Can you use the same matrix math for both to do transformations and such?
Rotating, translating, scaling, etc..?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement