Jump to content
  • Advertisement

Archived

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

Ronald Forbes

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 friction
if (--speed<0) speed=0;

// do thrust
if (UpArrow is pressed) {
speed += 2;
if (speed>maxSpeed) speed=maxSpeed;
}

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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 this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!