Reputation: 6082
I am trying to create some rotation animations in my projects with objects.
Currently to animate the objects, I have written some tween functons which take the params as value from, value to, value time
and tweens the object from from Param
to to Param
and tween the objects movements in the given time. However, I am need to creating some animations which look like the following:
The objects have to be tweened in rotation around a certain side. So, if go by this algorithm, something like:
for(int rotationAmount = 0;rotationAmount<=90;rotationAmount++){
glPushMatrix();
glRotatef(rotationAmount,1,0,0);
Rectangle(500,500,200,100);
glPopMatrix();
}
I still don't get the required effect, since the Rectangle instead of rotating around a certain side looks like rotating around the circumfrence of some big circle and coming back. Would really welcome some suggestions here on how to achieve the above?
Upvotes: 0
Views: 110
Reputation: 1140
glRotatef multiplies current matrix by rotation matrix. Rotation matrix rotates around orign of coordinates. You need to transtate orign to the side of the object, perform rotation, translate back.
point_type point_on_the_side;
for(int rotationAmount = 0;rotationAmount<=90;rotationAmount++){
glPushMatrix();
glTranslatef(-point_on_the_side.x, -point_on_the_side.y, -point_on_the_side.z);
glRotatef(rotationAmount,1,0,0);
glTranslatef(point_on_the_side.x, point_on_the_side.y, point_on_the_side.z);
Rectangle(500,500,200,100);
glPopMatrix();
}
Upvotes: 2