Jump to content
• Advertisement

#### Archived

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

# Matrices?

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

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

##### Share on other sites
Advertisement
check out the tutorials at OPENGLFORUMS.COM

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

#### Share this post

##### Share on other sites
read up

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

#### Share this post

##### 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

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]

#### Share this post

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

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

#### Share this post

##### 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 this post

##### 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++

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Now

• 10
• 19
• 14
• 19
• 15
• Advertisement
• Advertisement
×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!