Public Group

Tranformation Matrixes

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

Recommended Posts

Hi everyone, I'm stuck at converting a left-handed matrix to a right-handed one, or vice versa. I need this so that my graphics engine can support both OpenGL and DirectX without the need of changing the game code. Could you please tell me how can I convert a right-handed matrix to a left-handed one? Is there a global formula or for each kind of matrix(perspective projection, orthographic projection and ...) has a distinct formula? Thanks in advance. KSP

Share on other sites
DirectX and OpenGL both support LH and RH matrices. My suggestion would be not to bother with this conversion stuff and just to pick one format and use it in both cases.

Share on other sites
Read this. The matrix itself doesn't have a handedness, the transform being applied does.

The equations used for LH and RH transforms are usually documented by the API -- for example, the D3D SDK tells you the formula used to generate the matrices it produces from the D3DXMATRIX functions.

Share on other sites
To change change from a RH to LH coordinate space and vice versa flip the sign of the z-cooridante of all your vertices.

Share on other sites
Decide yourself which handedness to use throughout your game, so that all model/world transformations are in the one system. Then adapt the global-to-view transformation. What exactly to do depends on how the camera "sees" the world.

E.g. OpenGL uses a RHS w/ a camera looking against the local z-axis. If your game uses LHS w/ a camera looking along the local z-axis, then the necessary transformation is simply a mirroring of the z-dimension (i.e. scaling by -1). So the VIEW matrix would be build as
S(1,1,-1) * C-1
where S(1,1,-1) is the said mirroring, C the global matrix of the camera (its orientation and position, as usual).

If your viewing system differs in other issues, too, then additional transformations are needed.

Share on other sites
Wow,
Thanks everyone! Thanks for your support. I think I'm gonna use DX standards and write an OGL engine that can deal with it.

Yours,
KSP.

Share on other sites
Isn't the memory layout of an OpenGL matrix transposed from [j] to [j]?

I.e. OpenGL:

11 21 31 41
12 22 32 42
13 23 33 43
14 24 34 44

where DirectX D3DMATRIX struct looks like:

11 12 13 14
21 22 23 24
31 32 33 34
41 42 43 44

Share on other sites
Quote:
 Original post by thre3deeIsn't the memory layout of an OpenGL matrix transposed from [j] to [j]?I.e. OpenGL:11 21 31 4112 22 32 4213 23 33 4314 24 34 44where DirectX D3DMATRIX struct looks like:11 12 13 1421 22 23 2431 32 33 3441 42 43 44
You're correct that DirectX matrices are laid out in row-major order, while OpenGL matrices are treated as being column-major.

However, in both DirectX/D3D and OpenGL, the elements of the matrix basis vectors are contiguous in memory, so you can actually pass an 'OpenGL matrix' to D3D and vice versa with no ill effect.

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• Forum Statistics

• Total Topics
633303
• Total Posts
3011278
• Who's Online (See full list)

There are no registered users currently online

×