Hi there,
i have this rectangle and i want to be able to rotate this shape around another when i press a key.
i have been able to make it rotate where it is.
There are two problems i am having difficulties with:
- I can get the shape to rotate by placing glRotatef(angle,x,y,z);
within the creation of the rectangle.
This will rotate this object forever.
When trying to make it rotate on keypress i do the follows:
void keyboard_s (int key, int x, int y)
{
switch (key)
{
case GLUT_KEY_LEFT:
glRotatef(angle,rectangleX,rectangleY,rectangleZ);
break;
}
}
But i couldnt figure out how to tell it that i wanted it to do it to the rectangle. Since i have no point of reference.
Also i want to rotate this rectangle around a circle.
Do i use posX,posy,posz of the circle in some way to calculate how to do this.
I read that it's best to :
Make sure the shape is "facing" the fixed point(other shape?), so that translating forward with respect to the shape puts you closer to the center of its orbit
glTranslatef the shape forward to the point around which you want it to rotate
glRotatef the direction you want the spape to orbit
glTranslatef backwards just as far as you went forward
But i couldnt understand it.
Any advice and suggestions anyone could give would be much appreciated.
Thanks in advance Matt.