Reputation: 4958
so I am drawing a bunch of square plains to my GLView and wondering if there is a cleaner way to reset the glTransatef between each square.. my first square lets say is on -5 of the z axis and then the next square i want to draw at +5 on the axis.
gl.glTranslatef(0.0f, 0.0f, -5.0f); // move 5 units INTO the screen
square.draw(gl);
gl.glTranslatef(0.0f, 0.0f, 10.0f); // move 10 units to compensate for last point
square2.draw(gl);
another question i have is currently my two square classes have different matirx to so that they are viewable from the opposite side as the other. Is there a way to just have one square class and change the way its facing when i draw it instead of having a completely different class?
Upvotes: 0
Views: 179
Reputation: 162164
glPushMatrix glPopMatrix
glPushMatrix();
gl.glTranslatef(0.0f, 0.0f, -5.0f); // move 5 units INTO the screen
square.draw(gl);
glPopMatrix();
glPushMatrix();
gl.glTranslatef(0.0f, 0.0f, +5.0f); // move 10 units to compensate for last point
square2.draw(gl);
glPopMatrix();
EDIT
glPushMatrix creates a copy of the currently active matrix (in the current matrix mode and stack) and pushes it to the top of the matrix stack. All matrix operations happen on the top of the matrix stack. glPopMatrix removes the matrix on the top of the stack, so that all further matrix operations (in the current matrix mode and stack) operate on the matrix that was saved with the corresponsing push.
Note that with OpenGL-ES 2 and OpenGL 3 and later there are no longer matrix manipulation functions, so this is all a bit obsolte these days.
another question i have is currently my two square classes have different matirx to so that they are viewable from the opposite side as the other. Is there a way to just have one square class and change the way its facing when i draw it instead of having a completely different class?
Just make that 2nd matrix a class member and set it as per the class constructor. Actually, I don't really understand your problem. A code example would help.
Upvotes: 4