Archived

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

Im stuck with glTranslatef()

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

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 on other sites
Use gluLookup before you translate your object. Your camera transform should always be the first thing you do.

____________________________________________________________
www.elf-stone.com

Share on other sites
error C2065: ''gluLookup'' : undeclared identifier

what is the gluLookup?

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

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

see if that works

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

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

see if that works

Share on other sites
damn, now the object dissapeared somewhere in the "space". look this is my code for this:

inline int DrawGLScene(GLvoid){
-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]);
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();
glTranslatef(UP,1,5);
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 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();
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]

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 on other sites
Yeah sorry, you weren''t completely wrong. BTW, the glLoadIdentity call is still needed, it should just be before the gluLookAt().

Share on other sites
What will happen if i call gluLoadIdentity() before every movement of some object like:

glTranslatef(...);
some_object_here();

glTranslatef(...);
some_object_here2();

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

1. 1
2. 2
JoeJ
20
3. 3
frob
18
4. 4
5. 5

• 10
• 11
• 12
• 13
• 9
• Forum Statistics

• Total Topics
632204
• Total Posts
3004754

×