# The Industry's Foundation for High Performance Graphics

1. ## moving space ship

well I am going back to an asteroids like game. I am trying to get a space ship figure to rotate around a point and move up like in asteroids.
Code :
```void Draw_Ship()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);

glPushMatrix();

glTranslatef(5.0f, 0.0f, 0.0f);

glRotatef(angle, 0.0f, 0.0f, 1.0f);

glTranslatef(0.0f, up, 0.0f);

draw_ship();

glPopMatrix();

glPushMatrix();

glTranslatef(-5.0f, 0.0f, 0.0f);

glRotatef(angle_two, 0.0f, 0.0f, 1.0f);

draw_ship_two();

glPopMatrix();

glutSwapBuffers();
}```
here is the main code I am working on. let me know if you need more code.

2. Looks like a good start.

Jeff

3. Originally Posted by pbivens
well I am going back to an asteroids like game. I am trying to get a space ship figure to rotate around a point and move up like in asteroids.
You need to accumulate transformations. At each update, transform the "forward" motion by the current rotation then add the result to the current position.

4. well I have worked on my code here is what I have so far.
Code :
```void Draw_Ship()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);

glPushMatrix();

x = cos(angle)*up;
y = sin(angle)*up;

glTranslatef(-x, -y, 0.0f);

glRotatef(angle, 0.0f, 0.0f, 1.0f);

glTranslatef(x, y, 0.0f);

glTranslatef(x, y, 0.0f);

draw_ship();

glPopMatrix();

glPushMatrix();

glTranslatef(-5.0f, 0.0f, 0.0f);

glRotatef(angle_two, 0.0f, 0.0f, 1.0f);

draw_ship_two();

glPopMatrix();

glutSwapBuffers();
}```

5. I have almost solved my problem can I please get some input on my code.

6. Please read the Forum Posting Guidelines. In particular, see #4 under Posting Guidelines and #6 under Before You Post.

#### Posting Permissions

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