Sign in to follow this  
smally

OpenGL Viewing Matrix problems

Recommended Posts

Hi, I need some help to do with my viewing matrix in OpenGL. I am new to open and used to using Direct3D so bear with me. I am trying to set the Viewmatrix, previously I have just be doing: glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); // Eyepos, InterestPos, Up vec glu( 3, 4, 5, 0, 0, 0, 0, 1, 0 ); But I have now implemented a moving camera, in Direct3D I did it like this: D3DXMATRIX rotateHeading, rotateIncline, playerPos, cameraPos; D3DXMatrixRotationY (&rotateHeading, heading); D3DXMatrixRotationX (&rotateIncline, incline); D3DXMatrixTranslation(&playerPos, position.x, position.y, position.z); D3DXMatrixTranslation(&cameraPos, cameraPosX, cameraPosY, cameraPosZ); D3DXMATRIX StepOne = rotateHeading * rotateIncline; D3DXMATRIX StepTwo = playerPos * StepOne; D3DXMATRIX StepThree = cameraPos * StepTwo; d3dDevice->SetTransform(D3DTS_VIEW, &StepThree); This is my flexible camera withough the use of the matrix LookAt, how do I go about doing this but for OpenGL? [Edited by - smally on May 23, 2007 1:35:00 PM]

Share this post


Link to post
Share on other sites
In OpenGL you don't have a matrix class so you'll have to use a 3rd party library or create your own matrix class.

I also started with DirectX but then moved on to OpenGL. However, I had my own matrix class from the beginning which I use to create the camera matrix from scratch and load it to D3D/OpenGL. This class supports the general matrix operations like multiplication, transposing etc. and has constructors for various matrix types (like translation, rotation, camera like gluLookAt() ).

When converting from D3D to OpenGL you should remember that OpenGL and D3D may use different matrix layouts, so transposing the matrice might me necessary.

Share this post


Link to post
Share on other sites
Quote:
Original post by Lord_Evil
When converting from D3D to OpenGL you should remember that OpenGL and D3D may use different matrix layouts, so transposing the matrice might me necessary.


In particular, matrices in OpenGL are column-major, whereas in DirectX they are row-major (or, more specifically, D3DMATRIX is).

Also, OpenGL has some support for simple matrix operations. Functions such as glRotate* and glTranslate* will do pretty much what you expect them to do with the current matrix stack.

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