Skip to main content
gamedev.net
🔒 Locked

How to draw at exact positions instead of relative

Started by Colby_ 2 replies 950+ views
Original Post
Colby_
Colby_
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
Waterlimon
Waterlimon
I think there is a function for going backwards in the matrix stack, you should call that a few times.
o3o
SiCrane
SiCrane
I think what you want is glPushMatrix() and glPopMatrix().
slicer4ever
slicer4ever
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()

Topic Locked

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

Sign in to reply to this topic.