Jump to content
  • Advertisement
Sign in to follow this  
Eastern

OpenGL OpenGL's modelView to DirectX World matrix

This topic is 4377 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello. I'm writing a rendering library for this application that originally uses OpenGL. I am to write an alternative DirectX renderer. So my problem is, what do I have to do to the OpenGL modelView matrix to be able to use it as the World matrix in DirectX? This is the projection matrix setup used in OpenGL: gluPerspective(45.0f, (GLfloat)width/(GLfloat)height, 0.1f, 100.0f); This is my DirectX Projection matrix setup: D3DXMatrixPerspectiveFovLH(&proj, D3DX_PI * 0.25f, width / height, 0.1f, 100.0f); I set my View matrix to identity. I'm using the same vertex coordinates as in OpenGL, and need to (obviously) get them to transform to the same coordinates on screen. So I need to do *something* to the modelView matrix and pop it inside D3DTS_WORLD. I've spent hours trying to find this information on the net. The only semi-useful thing I've found was to multiply certain members of the modelView matrix with -1. Specifically, the following members: (0,2) (2,0) (2,1) (1,2) and (3,2). This proved correct, but only in some cases... It seems to work only if the modelView matrix is formed by a specific set of transformations. Something like one translation and one rotation. I need this to work regardless of what transformations were used, as my library doesn't get to see individual transformations, but only the resulting modelView matrix. Alternatively, if someone can tell me (or point me to) the exact sequence of calculations OpenGL and DirectX use to transform vertex coordinates into the screen coordinate system via their respective matrices, I should be able to work it out on my own. (if you go down this route, please tell me what's on the left and what's on the right for multiplications!) Any help would be much appreciated.

Share this post


Link to post
Share on other sites
Advertisement
Okay, my buddy and I have finally found the solution. For anyone who stumbles onto this problem: All you need to do is scale the modelview matrix by (1,1,-1).

Share this post


Link to post
Share on other sites
It's a little more subtle than that; OpenGL's modelview matrix contains both the model->world (D3D "world" matrix) and world->view (D3D "view") matrix. So, depending on how you're using the modelview matrix stack on the GL side, you might experience strange inconsistencies, especially when using the fixed-function pipeline.

The easiest way to deal with this is to expose D3D's conception (three seperate transforms) from the API, and do the appropriate conversions internally.

Share this post


Link to post
Share on other sites
I think you could also use D3DXMatrixPerspectiveFovRH, since OpenGL uses a right handed coordinate system. But your scaling by (1,1,-1) probably had the same effect.

Share this post


Link to post
Share on other sites
Quote:
Original post by jpetrie
It's a little more subtle than that; OpenGL's modelview matrix contains both the model->world (D3D "world" matrix) and world->view (D3D "view") matrix. So, depending on how you're using the modelview matrix stack on the GL side, you might experience strange inconsistencies, especially when using the fixed-function pipeline.

The easiest way to deal with this is to expose D3D's conception (three seperate transforms) from the API, and do the appropriate conversions internally.


But if you set your DX View matrix to identity, you are effectively moving it out of the picture, and you can then have a consistent correlation between World and modelView matrices -- at least that's what my experimenting has shown thus far. Am I mistaken?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!