Jump to content
  • Advertisement
Sign in to follow this  
silverphyre673

understanding glLoadIdentity()

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

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


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by Sneftel
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.


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


Link to post
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!