#### Archived

This topic is now archived and is closed to further replies.

# Asteroids ship rotation

This topic is 6924 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I''m making an Asteroids game in C++ class. (you know how it is for us smart C++ guys who finish our required stuff quickly so we can make games) We''re working with Turbo C++. That means using the pitiful Turbo C++ graphics commands. Now, I''ve decided the ship will just be a triangle until I decide on somehting else. What I need is some way to have this traingle rotate when the player pushes the left and right keys. Thanx for the help

##### Share on other sites
Try using Cosine and Sine.

##### Share on other sites
I just made an asteroids clone in DX, i did. Its tight! I might just e-mail it to ya.

##### Share on other sites
to rotate any point around the origin the equation is (if you have taken trig it''s a sinch).

newx = x*cos(angle) - y*sin(angle)
newy = y*cos(angle) + x*sin(angle)

if you want to rotate around any point you must first translate the point, rotate, and then translate back.

also remember to use sine and cosine lookup tables so that you don''t waste precious time calculating things more than once.

I have always been lost!

##### Share on other sites
Of course, if you wanted to go the full physics route, you could cause a turn-button press to add a rotational force to the ship. Then divide the force with the mass to find the acceleration. And so on... until you have your delta theta.

If I wasn''t so lazy I''d do the above. The ''standard'' asteroids way of doing it is to have a left/right button press increment the angle (that corresponds to the current facing). I think. At least that''s what I''m currently doing.

Dark Lord Pi

##### Share on other sites
Thanx alot. Even though I don''t understand the equation above for rotation (I''ve only used sines and cosines to calculate angles and measures of a right triangle), I think I can make some sort of use for it. Thanx again.

##### Share on other sites
On the subject of asteroid clones:

movement is easy and all, it seems
while up arrow is pressed:
x-velocity += cos(direction)*speed;
y-velocity += sin(direction)*speed;

but how the hell do you implement a max-speed? I don''t think friction in space will be very realistic, but I tried tons of stuff. I have something that works somewhat, but it''s not mathmatically correct or anything. Just put it together with trial and error

DarkAgito

##### Share on other sites
The max speed is c. Don''t worry about exceeding it in your program, because you can''t.

If you really want to worry about it, do this:

// do frictionif (--speed<0) speed=0;// do thrustif (UpArrow is pressed) {   speed += 2;   if (speed>maxSpeed) speed=maxSpeed;}

##### Share on other sites
I''ve got an almost complete vector graphics engine written in QuickBASIC (I know I know). Anyway, it does have all the formulas you''d need for rotation, velocity and even particle effects. It is slow (runs at 20 fps on my 550MHz) but that''s not the point. It has the formulas, so if you want it just let me know and I''ll email it to you.

##### Share on other sites
Sure, I''d love to take a look at it... I''m interested in particle effects too!

• 10
• 34
• 29
• 9
• 15