# Thread: rotating object

1. Originally Posted by pbivens
so how do I adjust the angle variable.
Have keys for "rotate right" and "rotate left". Pressing one causes the angle to increase at a fixed rate, pressing the other causes it to decrease at a fixed rate.

2. here is the code I am using
Code :
```void ship_left_two()
{
angle+=2.5f;
}

void ship_right_two()
{
angle-=2.5f;
}```
here is the drawing code
Code :
```void DrawShip(GLfloat position_X,GLfloat position_Y, GLfloat position_Z, GLfloat rotation,GLfloat color)
{
glPushMatrix();
double magnitude = sqrt(position_X * position_X + position_Y * position_Y);
double angle = atan2(position_Y,position_X);
position_X = magnitude * cos(angle);
position_Y = magnitude * sin(angle);
//	double acceleration = sqrt(position_X * position_X + position_Y * position_Y);
//	double angle = atan2(position_Y,position_X);
//	position_X = acceleration * cos(angle);
//	position_Y = acceleration * sin(angle);
//	position_X = speed_X;
//	position_Y = speed_Y;
//	glRotatef(rotation,0.0f,0.0f,1.0f);
glTranslatef(position_X, position_Y, position_Z);
glColor3f(color,0.0f,0.0f);
glBegin(GL_LINE_LOOP);
glVertex3f(0.0f,-0.25f,0.0f);
glVertex3f(-0.25f,-0.5f,0.0f);
glVertex3f(-0.5f,-0.5f,0.0f);
glVertex3f(0.0f,0.5f,0.0f);
glVertex3f(0.5f,-0.5f,0.0f);
glVertex3f(0.25f,-0.5f,0.0f);
glVertex3f(0.0f,-0.25f,0.0f);
glEnd();
glPopMatrix();
}```
I am still a little confused

3. Originally Posted by pbivens
here is the drawing code
Code :
```	double magnitude = sqrt(position_X * position_X + position_Y * position_Y);
double angle = atan2(position_Y,position_X);
position_X = magnitude * cos(angle);
position_Y = magnitude * sin(angle);```
This doesn't belong here. The drawing code in your first post was fine.

The issue is how you obtain the position which you pass to the drawing function.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•