I'm having a tough time with this. I must have looked at over a hundred pages so far, and I have yet to reach a solution.
All I want to do is rotate a point around a given axis (specified as a vector, so it's always going to pass through the origin), ie rotate P around (1, -1, -1). My knowledge of trigonometry is extremely minimal and exclusively self-taught, so that's not helping any

Here's what I currently have. It only seems to work correctly for certain angles - seemingly mostly ones that lie on the axes, or at 45 degree angles to them. If you can spot something that screams out as being wrong with this, please mention it. Alternately, feel free to ignore the code entirely and just point me in the right direction to solve this problem, that'd be great too
// Rotate around an arbitrary axis.
void Rotate(float theta, triple axis)
{
float a, b;
if(theta == 0.0f)
return;
Normalize(&axis);
// Rotate around the X axis so that the given axis lies in the XZ plane.
a = RadianAngle(triple(0.0f, axis.y, axis.z), triple(0.0f, 0.0f, 1.0f)); // Angle between the vector's projection
// on the YZ plane and the Z axis.
RotateX(a);
RotateX(&axis, a);
// Rotate around the Y axis to align the given rotated axis with the Z axis.
b = RadianAngle(axis, triple(0.0f, 0.0f, 1.0f));
RotateY(b);
// Perform the theta rotation around the Z axis.
RotateZ(theta);
// Undo the previous two rotations.
RotateY(-b);
RotateX(-a);
}
triple is a structure, triple(a,b,c) is a constructor that creates a floating point triple with those values, RotateX/Y/Z is an overloaded function that will multiply the global transformation matrix by whichever axis rotation matrix if given a floating-point number (angle), or will rotate just a vector around whichever axis if given a pointer to a triple and a floating-point number (angle.) Again, feel free to ignore the above entirely and just suggest where I can find out how to do it the
right way

I sincerely appreciate any help you guys can give me with this problem
[edited by - Zorodius on November 12, 2002 2:50:31 PM]