Im stuck with glTranslatef()

Started by
13 comments, last by nemezjah 21 years, 8 months ago
Im using glTranslatef function to move some object (md2) somewhere into the space, for example 0,0,0. Next im setting up a camera look gluLookAt() on those coordinates. After this i have implemented the keys moving camera, and here is the problem. When i move my camera for example forward, the object moves also ! why?? please help... how to set something in his place, maybe there is other function than translatef...?
Advertisement
Use gluLookup before you translate your object. Your camera transform should always be the first thing you do.

____________________________________________________________
www.elf-stone.com

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

error C2065: ''gluLookup'' : undeclared identifier

what is the gluLookup?

there is no glLookup, it''s glLookAt()

try this:
glLookAt(whatever);
glPushMatrix();
glLoadIdentity();
glTranslatef(whatever the object coord);
DrawObject();
glPopMatrix();

see if that works
there is no glLookup, it''s glLookAt()

try this:
glLookAt(whatever);
glPushMatrix();
glLoadIdentity();
glTranslatef(whatever the object coord);
DrawObject();
glPopMatrix();

see if that works
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>
damn, now the object dissapeared somewhere in the "space". look this is my code for this:

inline int DrawGLScene(GLvoid){
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); glLoadIdentity(); gluLookAt(-20,40,-60,
-20,0,20,
-20,0,20);

// below, we''v got a map

glDisable(GL_BLEND);
glDisable(GL_LIGHTING);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[1]);
glBegin(GL_QUADS);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -2.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f( 40.0f, -2.0f, 0.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f( 40.0f, -2.0f, 40.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -2.0f, 40.0f);
glEnd();


//and here we''v got a model

glPushMatrix();
glLoadIdentity();
glTranslatef(UP,1,5);
glShadeModel(GL_SMOOTH);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, Md2_Texture_Modele.ID);

Md2_Modele.Animate(Md2_Modele.stateStart, Md2_Modele.stateEnd, .2f,20);

glPopMatrix();



and what''s goin'' wrong?
quote:
there is no glLookup, it's glLookAt()

That's what I meant. For some reason I wrote gluLookup instead. Must be something about posting while half asleep.

DJ_GL's suggestion is completely wrong BTW.

quote:
glLookAt(whatever);
glPushMatrix();
glLoadIdentity();
glTranslatef(whatever the object coord);
DrawObject();
glPopMatrix();


The glLoadIdentity call would clear the camera transform before you draw the object.

The correct order is:
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  


____________________________________________________________
www.elf-stone.com

[edited by - benjamin bunny on August 11, 2002 2:23:30 PM]

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

yea, sorry about that, take out the glLoadIdentity(). hehe, it's from a habit of writing. BTW, i wasn't completely wrong obviously if some of it was right. NEways, hehe, after work I stayed up til 9am and so I was really tired when writing that. I just got my 3D selection program selecting correctly using gluProject and gluUnProect.

(not that i need to show this any). it's all win32 coding so it's not any fancy MFC code (as I hate MFC code) and I'm so glad I get the correct 2D to 3D coordinates.



really beautiful now tho...

[edited by - DJ_GL on August 11, 2002 6:06:53 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>
Yeah sorry, you weren''t completely wrong. BTW, the glLoadIdentity call is still needed, it should just be before the gluLookAt().

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

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 ?

This topic is closed to new replies.

Advertisement