• Create Account

Need scary sound effects or creepy audio loops for your next horror-themed game? Check out Highscore Vol.3 - The Horror Edition in our marketplace. 50 sounds and 10 loops for only \$9.99!

### #Actualalvaro

Posted 16 April 2012 - 01:52 PM

You can easily wean yourself off angles by storing a unit-length vector in any situation where you are currently using an angle. The coordinates of this vector are (cos(a), sin(a)).

For the code you just described, the sine and cosine are already computed, so you don't need to do anything.

Angle addition has a funny formula when you represent both angles as unit vectors:
Vector compose_rotation(Vector v, Vector w) {
Vector result;
result.x = v.x*w.x - v.y*w.y;
result.y = v.x*w.y + v.y*w.x;
return result;
}

Incidentally, that is the formula for multiplying the complex numbers (v.x+i*v.y) and (w.x+i*w.y), which is why thinking of rotations as unit-length complex numbers is very handy. It also prepares you for computing composition of 3D rotations as multiplication of unit-length quaternions.

If you need help implementing anything else using vectors, feel free to ask.

### #1alvaro

Posted 16 April 2012 - 01:51 PM

You can easily wean yourself off angles by storing a unit-length vector in any situation where you are currently using an angle. The coordinates of this vector are (cos(a), sin(a)).

For the code you just described, the sine and cosine are already computed, so you don't need to do anything.

Angle addition has a funny formula when you represent both angles as unit vectors:
Vector compose_rotation(Vector v, Vector w) {
Vector result;
result.x = v.x*w.x - v.y*w.y;
result.y = v.x*w.y + v.y*w.x;
return result;
}

Incidentally, that is the formula for multiplying the complex numbers (v.x+i*v.y) and (w.x+i*w.y), which is why thinking of rotations as unit-length complex numbers is very handy. It also prepares you for computing composition of 3D rotations as multiplication of quaternions.

If you need help implementing anything else using vectors, feel free to ask.

PARTNERS