Archived

This topic is now archived and is closed to further replies.

Help with modelview matrix!

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

I have posted the message in NeHe forum but I''ll try here too. I have read the OpenGL red book but I still can''t understand exactly how the modelview matrix works. Generally (api independently) , I know these about transformations: We have the coords of an object in local space and with a matrix , let''s say it the world matrix , we transform them in world coordinates. Then with another matrix , let''s call it the view matrix , we transform them in camera space coords. And then the projection transform comes. Correct me if I''m wrong so far. So what the modelview matrix has to do with all these? I have read somewhere that the submatrix 3x3 of the modelview matrix contains the up,right and lookAt vector of camera. An explanation of how modelview matrix works , what it contains and to which coordinate space it refers woulb be very helpful. In DX things were more clarified but I have stuck in OpenGL. Thanks in advance.

Share this post


Link to post
Share on other sites
I don''t see how this is still difficult for you to understand. OpenGL doesn''t have a view matrix or a "world matrix". Instead, it has a modelview matrix, which serves as both. It''s as simple as that.


How appropriate. You fight like a cow.

Share this post


Link to post
Share on other sites
I have a problem understanding the billboarding method of "OpenGL Game Programming" book. Why do we use the transpose(inverse because it''s orthogonal) 3x3 submatrix of the modelview matrix? Does it has to do with the camera vectors or with the opposite of the camera vectors? That''a all. Thanks

Share this post


Link to post
Share on other sites
ok.. your typical 4x4 matrix contains right, up, forward and position. in case of your "camera" this doesnt help, because for the (model)view matrix you want to move everything the other way, hence the inverse. in other words, the modelview itself wont help, because its the inverse of your "cameras" actual position/orientation.

btw. once you feel comfortable with matrices it will make it easy for you to do culling, because for every point you know how far along the up or right vector it can be depending on its distance along the forward vector of your "camera".

Share this post


Link to post
Share on other sites
To understand better , the inverse of the modelview matrix contains the up,right and forward vectors of the camera or the modelview itself?
Thanks for the answer

Share this post


Link to post
Share on other sites
quote:
Original post by mits
I have a problem understanding the billboarding method of "OpenGL Game Programming" book. Why do we use the transpose(inverse because it's orthogonal) 3x3 submatrix of the modelview matrix? Does it has to do with the camera vectors or with the opposite of the camera vectors? That'a all. Thanks



The 3x3 submatrix describes the rotation with the translation parts removed. The transpose of this 3x3 matrix is the inverse of the rotation matrix (as you point out, because the matrix is orthogonal).

The point of this is that by multiplying your billboards by the inverse of the rotation matrix, you remove the rotation from the original camera transform, so the billboard always faces the camera.

[edited by - benjamin bunny on November 6, 2003 3:59:17 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
http://www.sjbaker.org/steve/omniv/matrices_can_be_your_friends.html

Share this post


Link to post
Share on other sites
*s* nice link, i guess that saves me from going over and translating my matrix stuff.

and no, the inverse of the modelview is not always your camera vectors, only if you didnt do anything but set up the view at this point (ie, glulookat or any other way). at any other point it just represents the position/orientation of the object youre going to draw using this matrix (without inverting it), but this also includes the opposite of the camera position/orientation, because in the end there is no camera.

Share this post


Link to post
Share on other sites
ModelView camera can always be seen as three vectors representing frame-axis...in practice

m is the 4x4 float matrix

look = -Vector(m[2],m[6],m[10])
up = Vector(m[1],m[5],m[9])
side = up^look

Note that this vectors are stored in the upper 3x3 matrix

And the origin is given by

T = Vector(m[12],m[13],m[14])

R = [transposed of the 3x3 sub_matrix]

origin = -R*T

In practice we must recompute original position that is expressed respect (x,y,z) and then invert it because ''view moves in opposite direction''...

The matrix is a base-change (a topic in basic linear algebra)...in other words you project vertices on this new base (multiplying them by the matrix)

If you apply other object transform you change the modelview matrix and of course the frame you can compute from it.
To avoid hair-loss I think that a good practice is to push always modelview matrix originated by gluLookAt or similar...

PS: The transposed of the 3x3 upper sub-matrix is its inverse ONLY if it is ortho-normal that is you have applied only roto-translations (no scaling or non-linear op).




Share this post


Link to post
Share on other sites