Public Group

# Degrees in 2D

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

## Recommended Posts

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.

Which API?

##### Share on other sites
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)

##### Share on other sites
I'm using Allegro.
Thanks for the help.

1. 1
Rutin
23
2. 2
3. 3
JoeJ
20
4. 4
5. 5

• 29
• 40
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631739
• Total Posts
3001958
×