Im stuck with glTranslatef()

Started by
13 comments, last by nemezjah 21 years, 8 months ago
I don''t think I''ve ever heard of gluLoadIdentity, but your object would stay in the same spot on screen regardless of the camera''s orientation and position. This kind of thing is good for text or....hmmmm...a cheap ghost effect?

_____________________________

And the Phoenix shall rise from the ashes...

--Thunder_Hawk -- ¦þ
______________________________
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Formats______________________________________________________________________________________
Advertisement
I think he meant glLoadIdentity() Your object would stay in the same spot but the matrix OpenGL is using would be different, so your object wouldn't appear since the matrix reset itself using glLoadIdentity(). I could be wrong, this is only from my understanding.

[edited by - DJ_GL on August 11, 2002 7:50:40 PM]
Languages: C/C++ C# JavaAPIs: Win32 OpenGL DirectXWeb: &#106avascript Perl JSP PHP-MySQL Oracle Database Programming</span><a href='http://www.ethereal-studios.com'>http://www.ethereal-studios.com</a></a>
quote:Original post by nemezjah
What will happen if i call gluLoadIdentity() before every movement of some object like:

gluLoadIdentity();
glTranslatef(...);
some_object_here();

gluLoadIdentity();
glTranslatef(...);
some_object_here2();

? Will it work, or the gluLoadIdentity(); should be called once ?


By calling glLoadIdentity, you're clearing camera transform before you draw the object, which means the camera's position and orientation will make no difference to where the object is drawn on the screen (if it's drawn on the screen at all). Your gluLookAt call is effectively useless.

As already stated, your draw scene method should look something like this:
glLoadIdentity();  //clear the modelview matrixglLookAt(whatever); //do the camera transformglPushMatrix(); //store the camera transformglTranslatef(whatever the object coord); //transform the object (multiply the camera transform by the object's transform)DrawObject(); glPopMatrix(); //pop the matrix stack back to the camera transform  


I'll elaborate. At the start of your frame, you want the modelview matrix to be an identity matrix. That is

1,0,0,0
0,1,0,0
0,0,1,0
0,0,0,1

This matrix specifies a camera at position 0,0,0, pointing down the Z axis.

Then, you call gluLookAt, which multiplies the modelview matrix by a camera transform you specify. This changes the matrix to specify the camera transform you want.

Now, to draw an object at 10,10,10 in your world, you call

glPushMatrix();glTranslatef(10,10,10);drawObject();glPopMatrix();  


*500 error*

____________________________________________________________
www.elf-stone.com

[edited by - benjamin bunny on August 11, 2002 10:31:02 PM]

____________________________________________________________www.elf-stone.com | Automated GL Extension Loading: GLee 5.00 for Win32 and Linux

All right;-) I''v got it
big thanks.
All right;-) I''v got it
big thanks.

This topic is closed to new replies.

Advertisement