This topic is 4943 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I've been working through NeHe, making some simple projects of my own, and reading the red book. The glLoadIdentity() function seems to be quite common, but I don't understand exactly what it is for. Clearing the model view matrix doesn't mean much to me: I know that this is sort of how the camera is positioned, but I don't understand the effects of glLoadIdentity() on it other than it "clears it". What does that mean? Does it reset the camera's coordinates to (0.0f, 0.0f, 0.0f)? Does it reset the rotation? Help is appreciated - I tried! Thanks.

##### Share on other sites
glLoadIdentity() makes the current matrix in the current matrix mode an identity matrix -that is a matrix whose diagonal components, from top left to bottom right, are all 1's. Example of a 3x3 identity matrix:
| 1 0 0 |
| 0 1 0 |
| 0 0 1 |

Multiplying anything by an identity matrix will yield the original value.

So if you are in model-view mode (glMatrixMode(GL_MODELVIEW)), and you call glLoadIdentity(), the matrix that is to transform geometry into world space will be an identity matrix -that is, when you multiply this matrix by any vector (or matrix), you will obtain the original vector (or matrix). In such a case, the final calculated position of the point (1,2,3) would simply be (1,2,3). In this sense, calling glLoadIdentity(), resets the scene's transformations.

Consequently, if you were to call glTranslatef(1.0f, 0.0f, 0.0f) once every frame, without calling glLoadIdentity(), your geometry would be translated 1 unit along the x axis every frame (thus moving your geometry beyond where it should be).

##### Share on other sites
Read the Red Book chapter where it explains the mathematical basis of geometry transformations. glLoadIdentity, unlike most other functions that affect the active matrix, sets the matrix directly rather than postmultiplying it.

##### Share on other sites
Quote:
 Original post by SneftelRead the Red Book chapter where it explains the mathematical basis of geometry transformations. glLoadIdentity, unlike most other functions that affect the active matrix, sets the matrix directly rather than postmultiplying it.

I did, and right after came to ask this question :)

odiousangel: Thanks. Does that mean that if I started the camera at (0, 0, 0) and called glTranslatef(1, 0, 0) once per frame without calling glLoadIdentity(), I would start the second frame at (1, 0, 0) and then get translated to (2, 0, 0)?
Also, just to make sure, how often (frequently/infrequently) would you say glLoadIdentity() is called? Thanks.

##### Share on other sites
Yes, as long as you don't call glLoadIdentity() OpenGL will continue multiplying your transformations.
You should call it before you render a new frame, or are switching to a new cameraposition.

##### Share on other sites
An identity transformation is one that maintains the identity of the coordinate system. In other words, it doesn't change anything.

So, OpenGL says that when your model view matrix is identity, it's basically got the camera looking down the -z axis, with its up as +y and its right as +x. LoadIdentity resets everything to this point.

##### Share on other sites
Quote:
 Consequently, if you were to call glTranslatef(1.0f, 0.0f, 0.0f) once every frame, without calling glLoadIdentity(), your geometry would be translated 1 unit along the x axis every frame (thus moving your geometry beyond where it should be).

Yep, had that myself. I couldn't figure out why my mesh was "falling"...a proper glLoadIdentity() cleared it up for me.

1. 1
2. 2
Rutin
19
3. 3
khawk
18
4. 4
5. 5
A4L
11

• 9
• 12
• 16
• 26
• 10
• ### Forum Statistics

• Total Topics
633769
• Total Posts
3013754
×