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.


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.

Looks like a good start.

Jeff

You need to accumulate transformations. At each update, transform the “forward” motion by the current rotation then add the result to the current position.

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

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

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