# moving space ship

• 03-02-2018, 02:24 PM
pbivens
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); glLoadIdentity();   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.
• 03-05-2018, 04:34 PM
OceanJeff40
Looks like a good start.

Jeff
• 03-06-2018, 04:25 AM
GClements
Quote:

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.
• 03-08-2018, 06:07 PM
pbivens
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); glLoadIdentity();   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(); }```
• 03-10-2018, 03:44 PM
pbivens
I have almost solved my problem can I please get some input on my code.
• 03-12-2018, 05:21 AM
Dark Photon
Please read the Forum Posting Guidelines. In particular, see #4 under Posting Guidelines and #6 under Before You Post.