Sign in to follow this  
Colby_

How to draw at exact positions instead of relative

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
glPushMatrix/glPopMatrix, per above's answer, essentially:

[code]
glMultMatrix(CameraMatrix);
glPushMatrix();
glTranslater(0.0f, 5.0f, 0.0f);
drawCube();
glPopMatrix()
glPushMatrix()
glTranslate(0.0f, 10.0f, 0.0f);
drawCube();
glPopMatrix()
[/code]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this