PDA

View Full Version : more lame questions...



lateniteoverdose
08-14-2002, 05:59 AM
Some one should be able to answer this one easy! (I hope) I know there are you basic matrix modes to be operated on in OpenGL, the model_view , projection, texture. Now when do i have to change matrix mode, and why? Also I know that matrices in openGL are 4 x 4 matrices, what does each element in the matrix represent? I know these are questions that could be answered with the openGL red or blue book,which ive ordered but still waiting for so no flaming! thanx again Mike

Robbo
08-14-2002, 06:08 AM
Generally, you will only change to GL_PERSPECTIVE once - or when your window changes size (or you a rendering a scene with a different frustum for any other number of reasons). Basically, GL_PERSPECTIVE sets the perspective transformation to be appiled to your 3d points **after** they have been transformed by the modelview matrix.

Modelview matrix can be set once just before you need to use it (assuming you didn't push\pop matrix state) and is used to transform a single object - in either position, rotation or scale etc.

Texture matrix is for advanced use - and for a beginner you don't need to touch it, but you would change to texture matrix if you want to modify your texture coords in some way before render (advanced lighting, projection techniques etc.).

in the 4v4 matrix, you have the following values:

r r r sx
r r r sy
r r r sz
tx ty tz 1

Where r is rotation, s is scale and t is translation. This is of course a `noddy' version - there are plenty of tuts out there and samples\explainations of how these values actually get set.

Morglum
08-15-2002, 11:05 AM
Originally posted by Robbo:

r r r sx
r r r sy
r r r sz
tx ty tz 1



No, it's :
rs rs rs tx
rs rs rs ty
rs rs rs tz
0 0 0 1

Where the t's are for translation, and
rs rs rs
rs rs rs
rs rs rs
is for both rotation and scaling. If there is only scaling, it's
sx 0 0
0 sy 0
0 0 sz.
If there is a rotation, that's a bit more complicated. For example, for a rotation of angle a around the y axis, it's
cos (a) 0 -sin (a)
0 0 0
sin (a) 0 cos (a)

lateniteoverdose,

To understand where all this comes from, you have to know how a matrix is interpreted as a transformation. This is explained in the SuperBible (among others). A link to this book has been posted very recently on this forum.

Morglum

Robbo
08-15-2002, 10:42 PM
Doh! Of course thats right. Sorry.

Morglum
08-16-2002, 12:29 AM
No problem http://www.opengl.org/discussion_boards/ubb/smile.gif

Relic
08-16-2002, 01:32 AM
Some nitpicking. http://www.opengl.org/discussion_boards/ubb/wink.gif
A rotation of angle a around the y axis (in OpenGL), is actually this



cos(a) 0 sin(a)
0 1 0
-sin(a) 0 cos(a)

Matrices in OpenGL are left multiplied, model system is right handed, and there needs to be 1 in the y column.

Morglum
08-16-2002, 03:02 AM
Now it's my turn to say 'Doh' ! http://www.opengl.org/discussion_boards/ubb/redface.gif

Yes you're absolutely right about the 1. With a 0 it would squish the y-coord to 0.
Thanx http://www.opengl.org/discussion_boards/ubb/smile.gif
Morglum