Matrices?

Started by
5 comments, last by Xnin 21 years, 1 month ago
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.
Advertisement
check out the tutorials at OPENGLFORUMS.COM

otherwise the OPENGL redbook is available for download somewhere, though i forgot where.
read up

| - Project-X - my mega project.. yup, still cracking along - | - adDeath - an ad blocker I made - | - email me - |
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,
0.0,1.0,0.0,0.0,
0.0,0.0,1.0,0.0,
0.0,0.0,0.0,1.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

glBegin(GL_QUADS);
glVertex3f(-1.0,1.0,-1.0); (x,y,z)
glVertex3f( 1.0,1.0,-1.0);
glVertex3f(1.0,-1.0,-1.0);
glVertex3f(-1.0,-1.0,-1.0);
glEnd();

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

-Jason

[edited by - yodaman on March 5, 2003 3:23:54 PM]
www.jinx.com www.thebroken.org www.suprnova.org www.mozilla.org
oops, replied twice

[edited by - yodaman on March 5, 2003 3:20:55 PM]
www.jinx.com www.thebroken.org www.suprnova.org www.mozilla.org
Thanks for the replies guys. Great explanation yodaman, thanks allot. And thanks for the links, great sites and explanations. *adds to bookmarks
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}

is

{1, 3, 2, 4} in OpenGL and {1, 2, 3, 4} in C/C++
---K-1 Productions: Come visit us here.

This topic is closed to new replies.

Advertisement