Rotation about an arbitrary axis
by Stephane Savioz · in Torque Game Engine · 09/08/2005 (7:09 am) · 5 replies
So far, I've been able to rotate my object on the z axis
float deg = 45.0;
float rad = mDegToRad(deg);
float radius = 10.0;
newPosition.x = (mInitialPosition.x + mCos(rad) * radius);
newPosition.y = (mInitialPosition.y + mSin(rad) * radius);
This works...
But now, I would like to make my object rotating about an arbitrary axis, for example V(0, 10, 5);
How to code that ?...
float deg = 45.0;
float rad = mDegToRad(deg);
float radius = 10.0;
newPosition.x = (mInitialPosition.x + mCos(rad) * radius);
newPosition.y = (mInitialPosition.y + mSin(rad) * radius);
This works...
But now, I would like to make my object rotating about an arbitrary axis, for example V(0, 10, 5);
How to code that ?...
#2
Note that mulP will produce the same results as mulV in this case, since the matrix has no positional information. I like mulV here, just to remind me of that. And it saves 3 useless + 0 operations. Note also that your points will be rotated around 0,0,0 but I'm sure you knew that.
09/08/2005 (4:18 pm)
// Establish axis around which to rotate EulerF axis(x, y, z); // Normalize to the length representing the radians you wish to rotate // This can be positive or negative. AFAIK there is no range limit. axis.normalize(radiansToRotate); // Create new Matrix from Euler axis MatrixF rotationMatrix(axis); // Rotate desired points like so: rotationMatrix.mulV(pointToRotate);
Note that mulP will produce the same results as mulV in this case, since the matrix has no positional information. I like mulV here, just to remind me of that. And it saves 3 useless + 0 operations. Note also that your points will be rotated around 0,0,0 but I'm sure you knew that.
#3
09/08/2005 (5:03 pm)
Just keep in mind that not all classes of object types within Torque network rotation about all 3 axes...from memory for example the player is clamped to only rotating about the vertical axis. So even with the algorithms, you will need to make sure the class you are using has all 3 axes of rotation networked as well.
#4
I am not sure I understand the math behind the code but the most important.....it works great.
thanks
09/08/2005 (11:59 pm)
Thanks guys,I am not sure I understand the math behind the code but the most important.....it works great.
thanks
#5
09/09/2005 (3:30 am)
Oh.. My code rotates around an arbitrary axis at an arbitrary point in space.
Torque Owner Chris Labombard
Premium Preferred