Public Group

# Tranformation Matrixes

This topic is 3824 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
Transpose the matrix

in DirectX you have D3DXMatrixTranspose()

##### Share on other sites
Quote:
 Original post by Molle85Transpose the matrixin DirectX you have D3DXMatrixTranspose()

Uhhh wut? That doesn't do what you think it does.

##### Share on other sites
Quote:
Original post by fpsgamer
Quote:
 Original post by Molle85Transpose the matrixin DirectX you have D3DXMatrixTranspose()

Uhhh wut? That doesn't do what you think it does.

DirectX:
matrix = scale * rotation * translation

translation:
| 1 0 0 0 |
| 0 1 0 0 |
| 0 0 1 0 |
| X Y Z 1 |

OpenGL:
matrix = translation * rotation * scale

translation:
| 1 0 0 X |
| 0 1 0 Y |
| 0 0 1 Z |
| 0 0 0 1 |

Right-/left handed projection matrices are differed with Z being signed or unsigned.
But I guess he meant that he needs to convert the different matrices to work with each other, since it was a question of matrices in general not only projection.

##### Share on other sites
Quote:
Original post by Molle85
Quote:
Original post by fpsgamer
Quote:
 Original post by Molle85Transpose the matrixin DirectX you have D3DXMatrixTranspose()

Uhhh wut? That doesn't do what you think it does.

DirectX:
matrix = scale * rotation * translation

translation:
| 1 0 0 0 |
| 0 1 0 0 |
| 0 0 1 0 |
| X Y Z 1 |

OpenGL:
matrix = translation * rotation * scale

translation:
| 1 0 0 X |
| 0 1 0 Y |
| 0 0 1 Z |
| 0 0 0 1 |

Right-/left handed projection matrices are differed with Z being signed or unsigned.
But I guess he meant that he needs to convert the different matrices to work with each other, since it was a question of matrices in general not only projection.

Thoes matrices are neither right-handed, nor left-handed. Matrices do not have handedness.

What you have is a row-major matrix and a column-major matrix.

##### Share on other sites
Quote:
 Original post by fpsgamerThoes matrices are neither right-handed, nor left-handed. Matrices do not have handedness.

Not matrices in general but projection matrices are left/right handed.

Quote:
 Original post by fpsgamerWhat you have is a row-major matrix and a column-major matrix.

Yes, that what i meant, I think that is what he meant too.

##### Share on other sites
Quote:
 What you have is a row-major matrix and a column-major matrix.
Those who are familiar with DirectX and OpenGL know that they use row-major and column-major storage, respectively. However, it's probably worth clarifying that the example the above statement was in reference to shows row- and column-basis matrices (there's nothing in the example that indicates the 'majorness' of the matrices).
Quote:
Quote:
 Original post by fpsgamerWhat you have is a row-major matrix and a column-major matrix.

Yes, that what i meant, I think that is what he meant too.
The OP referred to handedness, which has nothing to do with 'majorness'.

To help prevent further confusion, here's a quick summary of the terms in question:

Handedness

What we might call 'spatial' handedness (as opposed to mathematical) refers to how the basis vectors are oriented with respect to one another. As has been noted, simple transform matrices (such as scale, rotation, etc.) do not have a handedness. It is only when we wish to visualize geometry that handedness comes into play.

The differences between (typical) OpenGL and DirectX projection and view transforms have to do with the z-clip range, and with which way the +z axis points in camera space. DirectX supports both right- and left-handed view and projection transforms, and AFAIK you can use either with OpenGL as well.

Majorness

This refers to how the matrix is stored in memory (i.e. by row or by column).

Row- and column vector notation

This refers to whether row-vectors (1xN) or column-vectors (Nx1) are being used, and determines (among other things) how transform matrices are constructed, and in what order the transform matrices must be multiplied.

##### Share on other sites
Hi.
Thanks everyone for quick replies. Well you've solved a big part of the problem for me, and thank you for that. But a part of the problem still remains. If I'm using say left-handed code in my game code and the graphics API uses opengl(right-handed), how can I convert my game-code matrix to opengl matrix (or to DX matrix if game code uses right handed system)? As you've mentioned it should only matter in projection matrix. This information is necessary because it's not possible to know if the engine will choose OGL or DX in the target machine at runtime.

Thanks,
KSP.

##### Share on other sites
KSP, look at your 2nd instance of this thread, there is already an answer.

1. 1
2. 2
3. 3
Rutin
19
4. 4
khawk
14
5. 5
frob
12

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633659
• Total Posts
3013207
×