Hey guys, I am wondering is there any possible way for me to reset the translate function so that it does affect the geometry that I am creating below it. I am using multiple display list so when I use gltranslate it moves everything by that translation, when I actually only want one thing to be translate then end the translate. Is there any way to do it? For example I have: (This is not the actually code, but similar layout. I know the syntax isn't correct in the example.)
glTranslatef(x, y, z);
displaylist(item1);
// I would like to end translate here.
//I would like to end the translate before I create the other object
glTranslatef(u,v,w); //New translation that I don't want effected by the previous translate
displaylist(item2);
//I would like to end this new translate and not effect the other display list declared below it
Is this possible? Or do I have to subtract the pervious translation from the new translation to make it go back to the original position
How do I make the gltranslate function not effect other objects below it
SiCrane already mentioned the mechanism that is build into OpenGL explicitly for such kind of thing. It is further an easy way and shows no inaccuracies.. However, I want to mention another way for completeness:
You can undo any right sided transformations by applying their inverse. I.e if the current transformation is
T[sub]1[/sub] * ... * T[sub]n[/sub]
[sub][/sub]then
T[sub]1[/sub] * ... * T[sub]n [/sub]* T[sub]n+1[/sub]
where
T[sub]n+1[/sub] := T[sub]n[/sub][sup]-1[/sup]
would effectively cancel out the last transformation, leaving
T[sub]1[/sub] * ... * T[sub]n [/sub]* T[sub]n[/sub][sup]-1[/sup] = T[sub]1[/sub] * ... * T[sub]n-1[/sub]
on the stack. This principle can be extended to a group of transformation T[sub]m[/sub] * ... * T[sub]n[/sub] , 1 <= m < n, when the rules of matrix inversion are obeyed, of course.
In your case with T[sub]n[/sub] being a translation by (x y z)
glTranslatef( x, y, z )
you apply the inverse by invoking
glTranslatef( -x, -y, -z )
next.
You can undo any right sided transformations by applying their inverse. I.e if the current transformation is
T[sub]1[/sub] * ... * T[sub]n[/sub]
[sub][/sub]then
T[sub]1[/sub] * ... * T[sub]n [/sub]* T[sub]n+1[/sub]
where
T[sub]n+1[/sub] := T[sub]n[/sub][sup]-1[/sup]
would effectively cancel out the last transformation, leaving
T[sub]1[/sub] * ... * T[sub]n [/sub]* T[sub]n[/sub][sup]-1[/sup] = T[sub]1[/sub] * ... * T[sub]n-1[/sub]
on the stack. This principle can be extended to a group of transformation T[sub]m[/sub] * ... * T[sub]n[/sub] , 1 <= m < n, when the rules of matrix inversion are obeyed, of course.
In your case with T[sub]n[/sub] being a translation by (x y z)
glTranslatef( x, y, z )
you apply the inverse by invoking
glTranslatef( -x, -y, -z )
next.
Ok, thanks guys. I understand mathematics well so I get the inverse thing, but I think i am going to try the push and pop matrix thing. I am new to opengl and I want to get a feel for it, so I think I want to use as many commands as possible. Quick question, Should I push the matrix then apply the glTranslate() then pop it after I have called my display list item? Also does pushing and popping the matrix reset scaling?
If the scale was already applied to the matrix before you pushed it, then you're just popping it out and back to that original state, so it should be fine.
Have a look at the documentation for the push/pop commands, they explain the matrix stack in more detail - it's pretty handy.
Have a look at the documentation for the push/pop commands, they explain the matrix stack in more detail - it's pretty handy.
Pushing/poping just means "save the current matrix on the matrix stack", and "restore the last saved matrix from the matrix stack".
glTranslate/glScale/etc modifies the current matrix.
So pop will naturally undo any matrix modifications since the last push.
Makes it easy to build hierarchical dependencies between objects.
glTranslate/glScale/etc modifies the current matrix.
So pop will naturally undo any matrix modifications since the last push.
Makes it easy to build hierarchical dependencies between objects.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement