| 43 | { |
| 44 | static const float M_2xPI = 2.0f * M_PI; |
| 45 | float xyToFacing(const Vec2<float> &xy) |
| 46 | { |
| 47 | float a1 = acosf(-xy.y); |
| 48 | float a2 = asinf(xy.x); |
| 49 | return a2 >= 0 ? a1 : M_2xPI - a1; |
| 50 | } |
| 51 | Vec2<float> facingToXY(float facing) { return {sinf(facing), -cosf(facing)}; } |
| 52 | // return the difference f1-f2 in the range [-pi;pi] |
| 53 | // a negative return value means f1 is CCW from f2. |