Skip to main content
gamedev.net
🔒 Locked

glTranslatef problems

Started by Julio Jun 29, 2000 at 4:54 PM 4 replies 400+ views
Original Post
Julio
Julio
hi everone, here''s some source to show my problem.
    
...
glLoadIdentity(); 
glTranslatef(world_x,world_y,world_z);
drawScene(); //draw the world

glTranslatef(bomb_x, bomb_y,bomb_z); 
drawBomb(); //draw one bomb (everything ok so far)
glTranslatef(enemy_x, enemy_y, enemy_z);
drawEnemy(); won''t translate to right position
    
the problem is I can either draw the bomb or the enemy but not both. How do I do this in opengl? Thanks, Joe JoeMont001@aol.com
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911
Chris F
Chris F
Try loading the identity matrix before your last call to glTranslatef
"I have realised that maths can explain everything. How it can is unimportant, I want to know why." -Me
Void
Void
The glTranslatef multiplies the current world matrix with the translation matrix (meaning it''s accumulative..) You must either reset the matrix to identity first (depending if you want the camera to stay at 0,0,0 ) or use glPush/PopMatrix..

..
Bad Monkey
Bad Monkey
Hi Julio,

As Void said, glTranslatef is cumulative on the modelview matrix (it is affected by any previous transformations), so I would suggest using glPushMatrix() before doing any local transforms, then drawing, and finally calling glPopMatrix()....

    
...
glLoadIdentity();


// apply viewing transforms here if you want them...

// ...but remember, rotate THEN translate for view...


glPushMatrix(); //save matrix state

// Do local tranforms... (translate THEN rotate)
glTranslatef(world_x,world_y,world_z);
drawScene(); //draw the world

glPopMatrix(); //restore matrix state



glPushMatrix(); //save matrix state

glTranslatef(bomb_x, bomb_y,bomb_z);
drawBomb();
glPopMatrix(); //restore matrix state



glPushMatrix(); //save matrix state

glTranslatef(enemy_x, enemy_y, enemy_z);
drawEnemy();
glPopMatrix(); //restore matrix state

...


Hope that helped


-------------
squirrels are a remarkable source of protein...
Julio
Julio
ok. I''ll try that. I tried glPush/PopMatrix but not at all three spots. Thanks for the replies.

JoeMont001@aol.com
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911
Julio
Julio
I got it working right. Here''s the final implementaion.
    
glLoadIdentity();
glTranslatef(world_x,world_y,world_z);
drawScene(); //draw the world


glPushMatrix();
glTranslatef(bomb_x, bomb_y,bomb_z);
drawBomb(); //draw one bomb (everything ok so far)
glPopMatrix();

glPushMatrix();
glTranslatef(enemy_x, enemy_y, enemy_z);
drawEnemy(); won''t translate to right position
glPopMatrix();

thanks again everybody,
Joe

JoeMont001@aol.com
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.