Reputation: 5193
Right imagine your at 0,1,0 or even a cube is. You then rotate 45% (glRotatef), then you move that object forward (glTranslate 0,0,10) so you move that object 10 forward.
How do you then get that objects position?
Upvotes: 2
Views: 633
Reputation: 72261
Looks like you'd want to use the gluProject
function from GLu library (comes with OpenGL).
Upvotes: 3
Reputation: 20018
You can combine the transformations into one matrix, and then apply this to any point to give you its world position. You can do this by querying the current matrix (after applying all your rotations, translations and scalings) and using this to apply transforms to arbitrary points.
Note that by using glRotatef
and glTranslatef`, you are using immediate mode and the old-style APIs. Modern OpenGL usage would have you create matrices and send them to shaders to apply the transforms from object to world coordinates. In this way, you would already have the matrix for object-to-world transforms.
Upvotes: 3