Skip to main content
GameDev.net gamedev.net
🔒 Locked

Modelview matrix

Started by beavis6325 Jan 1, 2005 at 3:34 AM 14 replies 1.2k views
Original Post
beavis6325
beavis6325
Hi, I am implementing something in directx while using a openGL program as a reference and I came across a modelview matrix. I was just making sure this is the same as the view matrix in directx. The camera transformation matrix. Thanks, Chase
nts
nts
With respect to DX i think the direct equivalent would be a 'view * world' matrix. I'm not too familiar with DX (worked with 7, 8 and very limited in 9) so someone correct me if i'm wrong.
blizzard999
blizzard999
OpenGL modelview matrix should be the DX transposed...
NLDEV
NLDEV
Quote:
Original post by blizzard999
OpenGL modelview matrix should be the DX transposed...


I don't think so. DirectX maintains a different concept than OpenGL--it has seperate World and View matrices, whereas OpenGL has a combined ModelView matrix. In this respect nts is correct.

It is true, however, that DirectX matrices' are column major (where OpenGL's are row-major by default).
blizzard999
blizzard999
Quote:
Original post by MikeMJH
I don't think so. DirectX maintains a different concept than OpenGL--it has seperate World and View matrices, whereas OpenGL has a combined ModelView matrix. In this respect nts is correct.


You are right but...world and view matrices are not different concepts!

Nts is right too

[GL modelview] = transposed([DX view] * [DX world])

Load the same matrix and you get the same results.
Khaosifix
Khaosifix
Quote:
Original post by MikeMJH
Quote:
Original post by blizzard999
OpenGL modelview matrix should be the DX transposed...


I don't think so. DirectX maintains a different concept than OpenGL--it has seperate World and View matrices, whereas OpenGL has a combined ModelView matrix. In this respect nts is correct.

It is true, however, that DirectX matrices' are column major (where OpenGL's are row-major by default).


Um matrices in Direct3D are row-major while matrices in OpenGL are column-major.
---http://www.michaelbolton.comI constantly dream about Michael Bolton.
blizzard999
blizzard999
translation matrix

DX1 0 0 x   0 1 0 y   0 0 1 z   0 0 0 1GL1 0 0 0   0 1 0 0   0 0 1 0   x y z 1
kSquared
kSquared
From here:

Quote:
9.005 Are OpenGL matrices column-major or row-major?

For programming purposes, OpenGL matrices are 16-value arrays with base vectors laid out contiguously in memory. The translation components occupy the 13th, 14th, and 15th elements of the 16-element matrix.

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.
- k2 "Choose a job you love, and you'll never have to work a day in your life." — Confucius"Logic will get you from A to B. Imagination will get you everywhere." — Albert Einstein"Money is the most egalitarian force in society. It confers power on whoever holds it." — Roger Starr{General Programming Forum FAQ<
Khaosifix
Khaosifix
No sir thats not right. According to a very reliable source[MSDN] the translation matrix in OpenGL goes more like this :

| 1 0 0 x || 0 1 0 y || 0 0 1 z || 0 0 0 1 |


For Direct3D you'd have to transpose the above matrix into row-major.
---http://www.michaelbolton.comI constantly dream about Michael Bolton.
Khaosifix
Khaosifix
Instead of rating me down why don't you google it for yourself? Or visit MSDN.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/opengl/glfunc03_9a05.asp
---http://www.michaelbolton.comI constantly dream about Michael Bolton.
blizzard999
blizzard999
Original post by Khaosifix
No sir thats not right. According to a very reliable source[MSDN] the translation matrix in OpenGL goes more like this :

1 0 0 x 0 1 0 y0 0 1 z0 0 0 1


For Direct3D you'd have to transpose the above matrix into row-major.[/quote]

****************************************************************************

Instead of report me what MSDN says...try this

...glMatrixMode(GL_MODELVIEW);glLoadIdentity();glTranslatef(4,5,6);float pf[16];glGetFloatv(GL_MODELVIEW_MATRIX, pf);...


Debug Output : pf[0], pf[1],...,pf[15]

1,0,0,0,0,1,0,0,0,0,1,0,4,5,6,1


That is

1 0 0 00 1 0 00 0 1 0x y z 1


And please...check your assertions as I do when answer to someone :)
_the_phantom_
_the_phantom_
Khaosifix's translation matrix is indeed right, heck if you want a more relieable source then check page 700 of the OpenGL Red Book (1.4 revision, so might be a different page in the free online one/earlier)

The only difference is in how you read the data out, you are reading its
pf[0]    pf[1]    pf[2]    pf[3]pf[4]    pf[5]    pf[6]    pf[7]pf[8]    pf[9]    pf[10]   pf[11]pf[12]   pf[13]   pf[14]   pf[15]


which is infact the transpose, as OpenGL treats it as
pf[0]    pf[4]    pf[8]    pf[12]pf[1]    pf[5]    pf[9]    pf[13]pf[2]    pf[6]    pf[10]   pf[14]pf[3]    pf[7]    pf[11]   pf[15]
blizzard999
blizzard999
I presume that it is more important from a programmer point of view to know how a library stores data in memory (for example to implement a compatible matrix class).
From a math point of view there is no doubt that the common form is

1 0 0 x
0 1 0 y
0 0 1 z
0 0 0 1

_the_phantom_
_the_phantom_
indeed, personally I find it easier to visualise the matrix as column major, it makes the maths easier to die the matrix positions together with the array access.
Khaosifix
Khaosifix
Actually row-major is easier for me to understand and do math on. But I guess thats just me.
---http://www.michaelbolton.comI constantly dream about Michael Bolton.
blizzard999
blizzard999
I use OpenGL so I stored elements in this way so I have no need to transpose it.
It's not that problem: write once use forever...the only thing is: if you have to load a matrix it must be in the same form of the library.
When you have your matrix and vector classes you can forget about 'low' level problems...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.