PDA

View Full Version : moving space ship



pbivens
03-02-2018, 03:24 PM
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.


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.

OceanJeff40
03-05-2018, 05:34 PM
Looks like a good start.

Jeff

GClements
03-06-2018, 05:25 AM
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.

pbivens
03-08-2018, 07:07 PM
well I have worked on my code here is what I have so far.


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();
}

pbivens
03-10-2018, 04:44 PM
I have almost solved my problem can I please get some input on my code.

Dark Photon
03-12-2018, 06:21 AM
Please read the Forum Posting Guidelines (https://www.opengl.org/discussion_boards/showthread.php/176139-Forum-Posting-Guidelines?p=1230021&viewfull=1#post1230021). In particular, see #4 under Posting Guidelines and #6 under Before You Post.