PDA

View Full Version : rotation,translation in local



12-19-2001, 09:01 PM
The problem goes like that:
Rotation - Pressing and dragging the right mouse button, all objects in the scene will rotate around their center . This means that if initially the object was not centered at (0, 0), you will have to calculate its center (by averaging the x and y coordinates) and make the appropriate transformation before rotating the object.

All directions are in the local object coordinate system. This means that initially, before any rotations are applied, moving the mouse to the right will make the objects move to the right as well. Once the objects are rotated, their coordinate system is rotated as well. This means that making a translation in the X coordinate, for example, will not cause the object to move to the right. Instead it will move in the direction of its own X direction.

For one object in the scene it is easy:
each time I call display() I do

glTranslatef(midpoint_x,midpoint_y,0.0);
glRotatef(...)
glTranslate(...)
glTranslatef(-midpoint_x,-midpoint_y,0.0);
draw_object();

But the problem is that I have many objects
in my scene and thay have different mid_points.

Problem2:
the same but all the transforms with respect
of the global (worlds) coord' system

How can I solve it without using matrix staff
and just glRotate,glTranslate funcs ???

Thank you

Rob The Bloke
12-20-2001, 02:37 AM
When you get round to reading the replies to your other posts, you'll see that it has already been answered. Just to make sure :

glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();

for( each object in scene )
{
glPushMatrix();
glTranslate( The position of the object );
glTranslatef( midpoint_x, midpoint_y,0.0f );
glRotatef( The Rotation Amount );
glTranslatef(-midpoint_x,-midpoint_y,0.0f );
draw_object();
glPopMatrix();
}