Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

As I read in OpenGL matrices are column major. It means that if I create a 16 element array first four elements are the first column in matrix. Is it the same for Direct3D or any transformation's required.

share|improve this question
add comment

3 Answers

Heishe is right about memory layout and matrices being the same, but his answer is somewhat misleading. Such things as right-handed or left-handed matrices don't exist. Be it a right- or left- handed coordinate system, math and the matrix stays the same, matrix operations give the same result for both of these systems. How we will interpret the data later, thats the difference.

In OpenGL, matrix operations are pre-concatenated, which means concatenated transformations are applied from right to left. Direct3D, however, applies concatenated transformations from left to right.

So what you need to do is to match the order of operation in OpenGL to the order of Direct3D. When writing OpenGL code, you apply the transform that you want to occur first last; when writing DirectX you're doing the opposite. Let's say you just transformed vector v in OpenGL by matrices A and B: v' = ABv In Direct3D the same transformation would be v' = vBA.

share|improve this answer
    
Thanks for the clear explanation. Could you please tell whether the storage I.e. memory layout of a matrix class matters in the system (OpenGL or DirectX) used? –  legends2k Jan 30 '13 at 7:46
add comment

DirectX matrices are right-handed and OpenGL requires left handed matrices, but while OpenGLs matrices are column-major, DirectX's matrices are row-major, so they're layout in memory is the same.

share|improve this answer
    
OpenGL matrices are definitely NOT left-handed (and cooridnate systems neither). –  Christian Rau Aug 15 '11 at 17:38
add comment

Neither D3D nor OpenGL specify or enforce a matrix handedness. True, the matrix stack functions in OpenGL are RH, but there's absolutely nothing to stop you from writing your own matrix library (or using a 3rd party one) that uses LH coords and loading the result using glLoadMatrixf. Likewise D3D has a full set of both RH and LH matrix functions. This is an old old old misunderstanding and needs to be put to bed.

Regarding row-major vs column major, please see the following: http://www.opengl.org/resources/faq/technical/transformations.htm:

Column-major versus row-major is purely a notational convention. Note that post-multiplying with column-major matrices produces the same result as pre-multiplying with row-major matrices. The OpenGL Specification and the OpenGL Reference Manual both use column-major notation. You can use any notation, as long as it's clearly stated.

Sadly, the use of column-major format in the spec and blue book has resulted in endless confusion in the OpenGL programming community. Column-major notation suggests that matrices are not laid out in memory as a programmer would expect.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.