• ### Announcements

#### Archived

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

# Identity matrix

## Recommended Posts

Hi, I''ve stumbled upon a problem while trying to learn OpenGL; Identity matrices. I can read everywhere what they do and what they are, but I have no clue why they look as they do and why it works. Thanks for any (simple) explainations/ -Lord Maz-

##### Share on other sites
Matrices are a way to organize a series of simultaneous equations so that they can be manipulated in a more orderly way.

The identity matrix is equivalent to a one. If you multiple two 4x4 matrices together, or two 3x3, etc, and one of them is the identity matrix, then the resulting matrix will be the other:

e.g. M = I M

If you want to know exactly why this is so, then there is a rather long winded manipulation which allows you to multiply two matrices together. It''s been worked out here:

http://nehe.gamedev.net/trentp/gametutorials/lesson02.asp

Plug in the values for an identity matrix and another arbitrary matrix and see what you get.

##### Share on other sites
Humm, If you want to know what glLoadIdentity() does, not just what an Identity matrix IS, it sets the "stack" to the identity..

basically, OpenGL combines a bunch of operations(translations, rotations, etc) into a single stack entry. then you pass a point to openGL (glVertex3f(x,x,x) and it multiplies the point with the "bunch of operations" in the stack.

So if you "clear" a stack, (set it to zero) then anything combined with zero is zero.

0 * Rotation * Translation = 0 (no translation or rotation has been recorded)

however, if you set the stack to the identity(1) then anything combined with the idenity is itself, so its kinda like a building block.

1 * Rotation * Translation = ?someMatrix?

and then OpenGL uses ?someMatrix? to rotate and translate your points...

here''s a conceptual verson of OpenGL

|-----------------|
|Perspective Stack|
|-----------------|
|ModelView |
|-----------------|

So during our program, we have something like this

|-----------------|
| ?Otho Matrix? |
-------------------
|?Some Trans? |
-------------------
| ?Rotation? |
-------------------

so our glVertex(x,x,x) goes "thru" the stack

glVertex * ?Otho? * ?Trans? * ?Rotation? = point on screen

and if we would like to remove ?Trans? & ?Rotations?, I''d call glLoadIdentity

|-----------------|
| ?Otho Matrix? |
-------------------
| ?Idenitity? |
-------------------

If I would have cleared it, it would have destroyed the Ortho Matrix, since 0 * ?Ortho? = 0... but since I have the identity matrix, I can now rebuild our transformations

You might wanna read Chapter 3 in the Red book.....and read up on glPushMatrix() / glPopMatrix()

I tried to be VERY simple in this explination, but its very difficult to explain.. I might have glossed over a few important items...You''re going to have to learn about OpenGL''s System Stacks in order to fully understand what you''re asking about, and that is a slightly larger topic, one not usually covered on websites...

##### Share on other sites
I was going to post this earlier but...hope this helps:
if we had a vertex x,y,z we could do this using matrices

  point  identity matrix |x|   |1 0 0 0|   |x•1 + y•0 + z•0 + 1•0|   |x||y| • |0 1 0 0| = |x•0 + y•1 + z•0 + 1•0| = |y||z|   |0 0 1 0|   |x•0 + y•0 + z•1 + 1•0|   |z||1|   |0 0 0 1|   |x•0 + y•0 + z•0 + 1•1|   |1|

Basically the identity matrix is comparable to the number 1. When you load the identity matrix to the screen what you are telling OGL is "whatever point i draw onto the screen, dont change it", that is multiply it by the number 1. If you say translate it 5 units up, it will multiply your point by a matrix to do so...which all it boils down to is add 5 to y. If you need more clarification just ask.

##### Share on other sites
Ah, I understand now why the identity looks like it does, when i tried multiplying a matrix with it I got the same matrix as I started with.

And also, the identity matrix resets any rotations or translations for some reason, but I can''t understand why multiplying something with "1" (identity matrix) changes it.

And also, why the hell use matrices in the first place? why not a bunch of vectors (seems simpler to me)? and what exactly is it that is stored in all the 16 values in the matrix?

I''ll buy that red OGL book as soon as I can afford it btw

-Lord Maz-

##### Share on other sites
glLoadIdentity() doesn't multiply the current matrix with the identity matrix (it wouldn't change anything), it instead replaces the current matrix with the identity matrix, cancelling out all previous rotations, translations and scalings.

Matrices are a short hand way of using sets of vectors, actually. I came up with my own 3D rendering routine before I learned OpenGL and realized I was performing very close to the same operations with vectors that take place within the matrices of OpenGL.

There are a number of matrices within the OpenGL rendering pipeline: There is the MODELVIEW matrix, which holds rotation, scaling and translation information. There is the PROJECTION matrix, which determines how a 3D point maps to the screen. And there is the TEXTURE matrix, which defines the orientation of a texture on a surface (which I haven't worked much with at all).

Exactly what values are stored in the matrix, I am not sure (the projection matrix is by far the most complicated), but the red OGL book will give you the details.

[edited by - Waverider on November 6, 2002 3:57:33 PM]

##### Share on other sites
is there a way to overload the identity matrix? so i don t have to port the coordinates from worldcraft to ogl coordinates?
that causes quite a few problems

##### Share on other sites
The Red Book is free, and you can find it here on Gamedev.net AAMOF.

/Sandman

##### Share on other sites
quote:
Original post by Saandman
The Red Book is free, and you can find it here on Gamedev.net AAMOF.

Ah cool, I''ll check it out.

Thanks for all your help, I think I understand it a bit better now.

-Lord Maz-

• ### Forum Statistics

• Total Topics
628278
• Total Posts
2981789

• 10
• 11
• 17
• 14
• 9