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



Recommended Posts

Xnin    122
Hello Im just a little confused with opengl and matrix and things. What i want to know is what exactly is a matrix in opengl? I mean i know what it is and i know how to multiply matrices etc...but how are they used in translating of an object or rotation etc...? Thanks heaps.

Share this post

Link to post
Share on other sites
yodaman    188
Ive been recently researching this myself, I think a good way of explain it would be... ok a matracie say a 4x4 would hold the translation and x,y,z rotations.
glTranslatef(0.0,0.0,-2.0); (origin)
glRotatef(0.0,1.0,0.0,0.0); (x)
glRotatef(0.0,0.0,1.0,0.0); (y)
glRotatef(0.0,0.0,0.0,1.0); (z)

and a matracie version:

M1[16] = {0.0,0.0,0.0,-2.0,

ok, then to actually rotate something (opengl does this automaticly on any vertex send thru glBegin()...glEnd()
but to do it on your own you would have to apply the matrix straight to the vertex of say your quad.
ok, now when you define a quad you usualy type out

glVertex3f(-1.0,1.0,-1.0); (x,y,z)
glVertex3f( 1.0,1.0,-1.0);

ok, now when you rotate something, your just telling the verticies to move to a new location... decrement z by -1.0 everyframe. this would send the quad spinning in the -z direction
so, when you have a matrix, say a 3x3, all thats holding is info
on each rotation angle (x,0.0,0.0),(0.0,y,0.0),(0.0,0.0,z)

this is kinda hard to explain, but i hope it helped you to understand a little easyer. (actually i understood it better by writting this


[edited by - yodaman on March 5, 2003 3:23:54 PM]

Share this post

Link to post
Share on other sites
Xnin    122
Thanks for the replies guys. Great explanation yodaman, thanks allot. And thanks for the links, great sites and explanations. *adds to bookmarks

Share this post

Link to post
Share on other sites
K-1    122
One thing to look out for is the way OpenGL stores it''s matrix elements. It stores them in Column major order instead of Row major like C/C++.

So, the matrix

{1, 2}
{3, 4}


{1, 3, 2, 4} in OpenGL and {1, 2, 3, 4} in C/C++

Share this post

Link to post
Share on other sites