Degrees in 2D

Started by
2 comments, last by Meagermanx 18 years, 10 months ago
Hey, I'm wondering about the math behind things rotating in a 2D environment. For example, let's say I'm making an asteroids clone, and I want to rotate my ship a bit. I know how to increase its coordinates to move a ship left, right, up, down, ETC, but I don't understand how you can do turning in a pixilated invironment. Can someone explain how this is done, or point me to some tutorials, or something? Thanks.
---There are 2 kinds of people: those who know hexadecimal, and those who don't.
Advertisement
Which API?
Its pretty much the same as in a none pixelated environment.

Your objects can be represented as a vector with an origin.
The origin is your objects location on the screen, and the other end of the vector is the direction the object is facing.

origin = (ox,oy)
pointing = (px, py)

px = sin(angle) * distance from origin + ox
py = cos(angle) * distance from origin + oy


likewise you can move your objects around

ox = ox + sin(angle) * moving_distance
oy = oy + cos(angle) * moving_distance


Because you work in rads, sin and cos are always less than 1, meaning your object will move the amount specified in moving_distance.

Working wioth these vectors, its very simple to start including gravity and inertial physics, (infact these dont need trig functions)






No bombs, No guns, just an army of game creators...
I'm using Allegro.
Thanks for the help.
---There are 2 kinds of people: those who know hexadecimal, and those who don't.

This topic is closed to new replies.

Advertisement