• Advertisement

Archived

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

Im stuck with glTranslatef()

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

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...?

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
there is no glLookup, it''s glLookAt()

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

see if that works

Share this post


Link to post
Share on other sites
there is no glLookup, it''s glLookAt()

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

see if that works

Share this post


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

Share this post


Link to post
Share on other sites
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 matrix
glLookAt(whatever); //do the camera transform
glPushMatrix(); //store the camera transform
glTranslatef(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]

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

  • Advertisement