Sign in to follow this  
D3DXVECTOR3

Help me identify these matrices created by...

Recommended Posts

gluPerspective = world matrix!? gluLookAt = view matrix!? GL_MODELVIEW_MATRIX = model*view!? if this all is true then why is my world*view != GL_MODELVIEW_MATRIX :( im comming from direct3d and i got my matrices with: pd3dDevice->GetTransform(D3DTS_WORLD, ...) pd3dDevice->GetTransform(D3DTS_VIEW, ...) pd3dDevice->GetTransform(D3DTS_PROJECTION, ...) edit: ehm... i just found that gluPerspective sets up a perspective projection matrix and not a world matix... now to find out how to create a world matrix... [Edited by - D3DXVECTOR3 on June 11, 2006 2:09:55 PM]

Share this post


Link to post
Share on other sites
The concept of modelview matrix in openGL combines the camera/view transformation, which you can create yourself or use gluLookAt, and the object/world transformation which is for rotating and positioning the objects in your scene, thus model + view.

Creating your "world matrix" would likely be any combination of glTranslatef and glRotatef to rotate and position your objects in the scene. To allow adjustable viewing in your scene with a camera, you'd apply the "view" matrix from your camera at the start of the render loop. Something like:


// clear the buffers and reset modelview matrix
glClear(...)
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

// set your "view" transformation first
camera.applyView();

// or

gluLookAt(...);

// render objects

glTranslatef(...);
glRotatef(...);

object.draw();


Hope that helps!

Share this post


Link to post
Share on other sites
thx for the reply, but my problems is that I need to have the view, model and proj matrix seperate to use with shaders.

if I have these 3 main matrices:World, View, Projection I can build any other matrices. inverse, transpose etc

[Edited by - D3DXVECTOR3 on June 13, 2006 12:02:51 AM]

Share this post


Link to post
Share on other sites
Then apply your view transformation (using a camera object, a combination of glTranslatef/glRotatef, or whatever else you choose), then retrieve and store the matrix:


// clear the buffers and reset modelview matrix
glClear(...)
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

float viewMatrix[16];
// set your "view" transformation first
camera.applyView();
glGetFloatv(GL_MODELVIEW_MATRIX, viewMatrix);

// clear it again
glLoadIdentity();

// set your "world" matrix transformations
glTranslatef(...)
glRotatef(...)
// whatever else...

float worldMatrix[16];
glGetFloatv(GL_MODELVIEW_MATRIX, worldMatrix);


As a side note, if you're using a camera object (I do), you'd probably already have the matrix stored somewhere, so retrieving it would be a matter of grabbing data from the class, but that's extra. :P

Is that how you wanted it?

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