How to draw at exact positions instead of relative

Started by
2 comments, last by slicer4ever 12 years, 1 month ago
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
Advertisement
I think there is a function for going backwards in the matrix stack, you should call that a few times.

o3o

I think what you want is glPushMatrix() and glPopMatrix().
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()
Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.

This topic is closed to new replies.

Advertisement