Sign in to follow this  

Tranformation Matrixes

This topic is 3459 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

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 this post


Link to post
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 this post


Link to post
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 this post


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

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 this post


Link to post
Share on other sites
Quote:
Original post by thre3dee
Isn't the memory layout of an OpenGL matrix transposed from [i][j] to [j][i]?

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
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.

Share this post


Link to post
Share on other sites

This topic is 3459 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.

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