#### Archived

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

# Matrices?

## Recommended Posts

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 on other sites
check out the tutorials at OPENGLFORUMS.COM

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

##### Share on other sites

| - Project-X - my mega project.. yup, still cracking along - | - adDeath - an ad blocker I made - | - email me - |

##### Share on other sites
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

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]

##### Share on other sites
oops, replied twice

[edited by - yodaman on March 5, 2003 3:20:55 PM]

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

##### Share on other sites
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++

• ### Forum Statistics

• Total Topics
628320
• Total Posts
2982057

• 12
• 9
• 9
• 13
• 11