Physical math problem

For a small Game I NEED HELP !
How can I programm the movement like in the Game Disasteroid ?
The actor musst accelerate in one of 360.0f Degrees. The Programm currently reads out the Z Axis (from 0.0f to 360.0f) from the actor . How can I calculate the X and the y coordinates and the acceleration ? When the actor rotates (around his Z Axis) during the acceleration…the Programm has to calculate the amount of reverse Accelaration and the new Direction of the actor.
I hope i discribed my Problem good enough.

Can anyone help me ?

Thanks to everyone who can help me a little bit to solve my problem.

Hi there,
If you don’t want to use drift try this:


Would like to help more, but I have to catch my train now…

Hi Geniuz ! …

Thanx for your fast answer … but
I tried it…and it does not work…or I am to stupid. I think the last one :slight_smile:
I decided to explain my Problem a little bit more…

I want to build a small Game where the Player is seen from above, like a 2D Game …
The actor/player is a textured quad . The Player starts at a defined startpoint on the screen. When you(the textured quad) burst in one of the possible 360.0f directions The “0 Angle” starts at 12 o´clock … when you rotate the Actor/player to the left side ,… the “angle” on the Z Axis of the Actor grows up to 360 … and at 360 back to 0 … because it was one full rotation…and the player is back to 12´clock.

ok,…ok,…back to main :slight_smile:

The player moves in one of the directions … when i want to stop the player/textquad/actor … I must turn and burst in the reverse direction to stop or to slow the quad/actor/player down. The Rotation of the actor had to take no effect during the movement until you burst in one of the other directions.
Like an havy ship in space :slight_smile: … hm … i think its the best an shortest explantation for the movement

I am very new in C++ and OpenGL and have Problems to simulate this Physical Movement
in my little (not working) programm

I hope this Try is better to understand
what I mean…

If you have any idea …please let me know.


This is luckily not an OpenGL problem, which means that I’ll be able to help you

Here’s a suggestion:

class Vect{
float xcord;
float ycord;

Vekt position;
Vekt movement;

//do each turn:
position.xcord += movement.xcord;
position.ycord += movement.ycord;

Now, each turn, check for input. Say your user pushes “thrust” while the ship is pointing upwards. The acceleration “vector” that comes from this is xcord = 0, ycord= CURRENT_SPEED. (well, pseudo-code)
Add this thrust vector to the vector movement, and you’ve got it. To increase the “inertia” of your ship, decrease the change made to movement when user pushes button.

Good Luck!

Maybe you can have the player as an object. The object has a motion class associated with it. all my C++ syntax is rusty but here goes.

class motion
double Xposition;
double Yposition;

double Xdirection;
double Ydirection;

double Xvelocity;
double Yvelocity;

double Mass;
double ThrustForce;

The X,Y position has an obvious purpose. Having X and Y velocity as its own entitiy means, you can rotate (e.i. cange X and Y direction) with out changing the way you move. Having a thrust force and mass seperate means, that your object can have things on it, or lose parts of itself, and move slower or faster when you press the after burner (i don’t know if you want that, but for completeness there it is) force/mass will be your acceleration.

So when you want to accelerate find the acceleration and use your X and Y direction variable to tell you what direction the actor is facing.then cahnge teh velocity based on the acceleration, and update the postion base on the velocity.

[This message has been edited by grady (edited 04-21-2001).]

I think …
I have to programm a Text Adventure … that makes the movement easysier
for a beginner

OK,…just joking…

I use the glTranslatef Function to position my Textquad (2 Variables for x and the y
coordinates) and Z for the Rotation wich where caculated between 0.0f and 360.0f
(When the Player pressed Right or Left ZSpeed it increased or decreased with 0.001f)
But when the Player turns his ship over 360 Degrees the Variable Z grows for example
over 360.0f or under 0.0f . To get an defined Rotation between 0-360 I wrote this Lines:
to keep tracking of the Rotation:

-Than the Actor/Player/Textquad
-calculate the XMOVE and YMOVE ???


if (ZRotation >= 360.0f) Looks if the float gets over 360
ZRotation = 0.0f; resets the float ZRotation on same Position

if (ZRotation <= 0.01f ) Looks if the float runs under 0
ZRotation = 360.0f; resets the float ZRotation on same Position

if (keys[VK_RIGHT])
ZSpeed += 0.001f; increase / turn left

if (Keys[VK_LEFT])
ZSpeed -= 0.001f; decrease / turn right

When the actor looks to the left side ZRotation is 90.0f
When the actor looks up ZRotation is 0.0f/360.0f !!
When the actor looks down ZRotation is 180.0f
but possible are all 360.0f degrees…
and so on…

for example :

When my actor has the xmove-coordinate 0.0f, ymove-coordinate 0.0f and the ZRotation
is 75.8f.

And I press my key to thrust the ship/actor/quad which inreases a Variable ACCELERATION with f.e. 0.01f
to increase the speed of the movement…so I can decrease it slowly to simulate a havy ship and
Tons of steel
for example:

if (Thrust_not_pressed)
Acceleration -= 0.001f;

How can I tell the Programm mathemathecly to move my textured quad with the glTranslatef Function in this
Direction ? Are Vectors the only way ? and…finaly

When the Actor/player/quad/Tons_of_steel_ship moves in this direction and the Player changes the Rotation
of the ship and Thrusts in any other direction…How can I calculate the new direction and the amount of
REST Acceleration (because it is a havy ship with tons of steel ) of the Player/actor/ship ?

I think it must be something with the angles (ZRotation) of the player to get the Information of the relative Acceleration
Directions , Thrust and the amount of changing the Variables for the X ans Y Axis …

Or…Is this maybe the totaly wrong way to do this ?

I don´t know…

reign_bow and grady is that what you both mean ?

Thank you both for your answers I will try these versions to solve my “little” problem…

I will be back in few hours


I’m a bit confused by what you want, Am I right in assuming that you have QUAD lets say and when keys are pressed you want it to accererate in that direction. You also want it to accelerate differently depending on woeight and you want it to slow gradually if nothings pressed (Technically if its a space simulation this wouldn’t happen, but hay this is just a game isn’t it)

Heres the theory I’ll leave you to implement it, I can’t as the chances you program in the same language as me are quite slim.

I’m also assuming 2d

You first need X and Y coordintates for the ship. Thats just two variables

Second you need two vectors I and J, again just two variables

Third you need a weight variables

Then every time lets say the right button is pressed you add 1/Weight to the I variable. Or subtract it if the right is pressed. Similirly the up and down buttons affect the J variables

Then for every game loop add the I to X and J to Y. Note if it moves too fast either increase the weight or change to 1 to a 0.1 or smaller.

A glTranslate with the X, Y variable should place the QUAD at the propper coordinates

The simplist way to slow the ship gradually is to apply air resistance to it. I.e. divide the I and J vectors by a constant, maybe 10 at the end of every game loop.

Finally if you want the left and right button to rotate the ship and the up and down to accelerate it then you need a third variable for the angle. Use the left and right to modify this, when the up and down are pressed use Cos(Angle)/weight to modify the I and SIN for J

Good Luck