Hey, how about doing some quaternions / vector maths? =) I did this using a small βpatchβ in my Vector class:
double NumBounds(double value) { if (fabs(value) < (1 / 1000000.0f)) return 0; else return value; } class Vector { private: double x, y, z; public: Vector(const Vector &v) { x = NumBounds(vx); y = NumBounds(vy); z = NumBounds(vz); } Vector(double _x, double _y, double _z) { x = NumBounds(_x); y = NumBounds(_y); z = NumBounds(_z); } Vector Normalize() { if (Length() != 0) return Vector(x / Length(), y / Length(), z / Length()); else return *this; } double operator[](unsigned int index) const { if (index == 0) return NumBounds(x); else if (index == 1) return NumBounds(y); else if (index == 2) return NumBounds(z); else return 0; } void operator=(const Vector &v) { x = NumBounds(vx); y = NumBounds(vy); z = NumBounds(vz); } Vector operator+(const Vector &v) { return Vector(x + vx, y + vy, z + vz); } Vector operator-(const Vector &v) { return Vector(x - vx, y - vy, z - vz); } double operator*(const Vector &v) { return NumBounds((x * vx) + (y * vy) + (z * vz)); } Vector operator*(double s) { return Vector(x * s, y * s, z * s); } Vector DotProduct(const Vector &v) { double k1 = (y * vz) - (z * vy); double k2 = (z * vx) - (x * vz); double k3 = (x * vy) - (y * vx); return Vector(NumBounds(k1), NumBounds(k2), NumBounds(k3)); } Vector Rotate(Vector &axis, double Angle) { Vector v = *this; return ((v - axis * (axis * v)) * cos(angle)) + (axis.DotProduct(v) * sin(angle)) + (axis * (axis * v)); } };
Using this class, you can easily rotate any vector around any other:
Vector a(1.0f, 0.0f, 0.0f), b(0.0f, 1.0f, 0.0f), c(0.0f, 0.0f, 0.0f); c = a.Rotate(b, M_PI / 2.0f);
source share