Advertisement

move ship

Started by October 14, 2019 08:52 PM
4 comments, last by Rutin 4 years, 11 months ago

I got my ship to rotate about arbitrary axis. my next step is to get it to move up and down depending on which way it is facing. I got it to move up and down but not in the way it is facing after it is rotated.


void drawShip()
{
	glPushMatrix();
	glColor3f(1.0f, 0.0f, 0.0f);
	glLoadIdentity();
	glTranslatef(50.0f, 0.0f+thrust, 0.0f);
	glRotatef(shipAngle, 0.0f, 0.0f, 1.0f);
	glBegin(GL_LINE_LOOP);
	glVertex3f(0.0f, 0.0f, 0.0f);
	glVertex3f(-5.0f, -5.0f, 0.0f);
	glVertex3f(0.0f, 10.0f, 0.0f);
	glVertex3f(5.0f, -5.0f, 0.0f);
	glEnd();
	glPopMatrix();
}

 

And the question is ... ?

Advertisement

Similar logic to the problem you claimed to solve last year.

Which you made several threads about (and claimed to solve again).

 

You've been trying to solve this specific problem (rotate something and have it move the direction it's facing) for more than 6 years. Maybe it's time to find something else to invest your time in.

Hello to all my stalkers.

If you're making a spacewar game, then:

Make vector3 variables for position and velocity and initialize them to appropriate starting values any time the ship spawns.

When you detect input that applies thrust, say:  velocity += shipForwardVector * thrustAcceleration * deltaTime;

shipForwardVector can be calculated from a rotation angle by using x = cos(angle), y = sin(angle), z = 0

You may want to clamp velocity to a maximum length.  To do this, check (velocity dot velocity) > (max speed squared) and if true, set velocity = velocity * max speed / velocity.Length;

If you want your velocity to slow down automatically over time, every frame say velocity *= 0.99f;

Every frame, say position += velocity;

Use position for your glTranslatef instead of any of the hardcoded numbers you have in the glTranslatef line right now.

If you don't have vector3 types then look up the long way of writing them and make your own vector multiply, add, length, dot product, etc functions.

8 minutes ago, Lactose said:

Similar logic to the problem you claimed to solve last year.

Which you made several threads about (and claimed to solve again).

 

You've been trying to solve this specific problem (rotate something and have it move the direction it's facing) for more than 6 years. Maybe it's time to find something else to invest your time in.

It seems to be the trend... It's almost like he is living in a scenario like shown in the movie "Groundhog Day" but he doesn't remember what happened prior to the "reset".

Programmer and 3D Artist

This topic is closed to new replies.

Advertisement