If you just want the relative angle between the two bodies you have two options: cyclic subtraction of the angles (annoying and confusing), or using rotation vectors (much easier).
Basically the cpBody.rot vector stores a rotation as a complex number. You don't really need to know what that means other than there are a number of neat properties of complex numbers that can be used to efficiently rotate 2D vectors. (Quaternions used for rotations in 3D are an extension of complex numbers) Basically though, you can think of a rotation vector as being a vector that points in the direction of the angle, and has a length of 1.0 (a unit vector).
Anyway! There are two functions for working with rotation vectors: cpvrotate() and cpvunrotate(). One adds two rotations, and the other subtracts them. So if you do this:
Code: Select all
// (shuriken rotation - pineapple rotation) as a rotation vector
cpVect rotDelta = cpvunrotate(shirikenBody->rot, pineappleBody->rot);
// Get the angle of the rotation vector:
cpFloat angleDelta = cpvtoangle(rotDelta);
You could also calculate the absolute difference between the two rotations using a dot product and acos(), then use the cross product to figure out if it's a negative or positive rotation. So there are a number of ways you could approach this. I'd use the solution above though, it's the simplest.
Probably off topic:
In my own graphics engines I use the cpBody.rot vector directly instead of an angle in degrees or radians for rotating things. You can easily use the rotation vector to make a transformation matrix, and you don't have to fiddle around with trigonometry.
http://chipmunk-physics.net/release/Chi ... #Transform That's not really an option though if you are using an existing sprite engines if they don't let you use transformation matrices. (Which is most of them, *sigh*.)
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/