Reputation: 43
I have just begun working with OpenGL ES and I want to have an object that does not move when I call gltranslatef. I have tried first rendering everything but this object, then calling gltranslatef with the same values as before, but *(-1). This makes the object stay in its place, but seems to "quiver" slightly. Is what I am describing even possible?
Upvotes: 0
Views: 806
Reputation: 54592
Since you're using glTranslatef()
, I figure this must be ES 1.1. The cleaner and more generic approach is to use glPushMatrix()
and glPopMatrix()
to restore the original transformation state, instead of applying the inverse translation yourself. The structure of your would then look like this:
glPushMatrix();
glTranslatef(...);
// draw objects that need to be translated
glPopMatrix();
// draw objects that should not be translated
glPopMatrix()
restores the transformation matrix to the state it was in before the glPushMatrix()
call. So in this code sequence, the translation will not be applied to the objects drawn after the glPopMatrix()
call.
You could of course also draw the stationary object first, but you will still need to restore the original transformation at the end of the frame anyway, to get ready for the next frame. So it doesn't make much of a difference if you draw it first or last.
From what you're describing, I'm not quite sure what's going on with the "quivering". Since we're dealing with limited floating point precision, it's true that applying a transformation, and then later applying the inverse transformation, does not generally give you exactly the original transformation. But after just applying a couple of translations, I wouldn't expect the rounding error to be large enough to cause a noticeable visual effect.
Upvotes: 1