Jump to content
  • Advertisement
Sign in to follow this  
Colby_

How to draw at exact positions instead of relative

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

Imagine I have a list of things I want to draw, and their exact positions in relation to the origin. For drawing the first object, I can simply translate to the coordinates of the object and draw it. However, for any object after that one, the points i enter are relative to the last translation. How can I reset similarly to glLoadIdentity(); but without discarding my camera rotations? Surely I dont have to subtract the coordinates of all models or re translate the camera for each position?

For example, say I have two cubes at (0, 5, 0) and (0, 10, 0). I currently must draw them as so:


translatecam
translate(0, 5, 0);
drawcube
translate(0, 5, 0);
drawcube
updatescreen

and I need to be able to do it like so:

translatecam
setresetpoint

translate(0, 5, 0);
drawcube
reset
translate(0, 10, 0);
drawcube
updatescreen

Share this post


Link to post
Share on other sites
Advertisement
glPushMatrix/glPopMatrix, per above's answer, essentially:


glMultMatrix(CameraMatrix);
glPushMatrix();
glTranslater(0.0f, 5.0f, 0.0f);
drawCube();
glPopMatrix()
glPushMatrix()
glTranslate(0.0f, 10.0f, 0.0f);
drawCube();
glPopMatrix()

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!