Object movement
Ok, im having aproblem moving objects. I load them all from disk, and they are all relative to {0,0,0} so obviously i need to move them. Currently i use this method
glMatrixMode(GL_MODELVIEW_MATRIX);
glPushMatrix();
glTranslatef(mx, my, mz);
// Draw object here
glPopMatrix();
but if i draw 2 objects one after the other like this
Obj1->Draw(0,0,0)
Obj2->Draw(10,10,10)
the first one is drawn fine, but the 2nd one follows the camera. I thought it might be that i need to reset the modelview matrix before drawing(glLoadIdentity) but if i do that my camera doesnt move at all. and objects are drawn in weird places. Any ideas? thanks
~ Chris
Here''s the way you should do it:
Actaully, in your case, it seems that you specify where an object is to be drawn when you call Draw, so just replace the calls to glTranslate and DrawObject with you Draw(x,y,z) call.
Hope that solves your probs
PS: if stuff still acts weird, remember that OpenGL uses a right-handed coord system, so -Z goes into the screen
------------------------------------------------------
"You need a weapon. Look around you... can you construct some sort of rudimentary lathe?"
- Guy Fleegman, Security Officer, NSEA Protector
void Render(){ // Clear color/depth/whatever buffers glClear(...); // make sure modelview matrix is current // call glMatrixMode(GL_MODELVIEW); if its not // I generally assume it is... glLoadIdentity(); // apply your camera transform // remember... rotate THEN translate glTranslatef(mx, my, mz); // Now draw your objects... for( each object ) { glPushMatrix(); //save view transform // apply transforms to object - ie position/orient it // translate THEN rotate glTranslatef(objx, objy, objz); ... DrawObject(); glPopMatrix(); // restore view transform readty for next object } glFlush()/SwapBuffers()/whatever}
Actaully, in your case, it seems that you specify where an object is to be drawn when you call Draw, so just replace the calls to glTranslate and DrawObject with you Draw(x,y,z) call.
Hope that solves your probs
PS: if stuff still acts weird, remember that OpenGL uses a right-handed coord system, so -Z goes into the screen
------------------------------------------------------
"You need a weapon. Look around you... can you construct some sort of rudimentary lathe?"
- Guy Fleegman, Security Officer, NSEA Protector
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement