Rotating vectors around an axis

Started by
3 comments, last by CMN 23 years, 9 months ago
Let''s say I have three vectors, vX, vY, vZ and vPosition describing the local coordinate system of an object. What is the formula for rotating two of the alignment vectors around the third. And calling YRotate(DEGREE_RADIAN(1)) each frame should keep the object spinning. /CMN
Advertisement
Here is the code that I use for this (Taken directly from my tMatrix class).

tMatrix33::tMatrix33(const tVector &unitAxis, const double &angle)// unitAxis is the axis of rotation// angle is the amount to rotate around that axis in radians{	// A rotation matrix around an arbitary unit axis	// Find c, s and t	double c = cos(angle);	double s = sin(angle);	double t = 1 - c;	// Calculate the matrix.	_Mx[0][0] = t * unitAxis._x * unitAxis._x + c;	_Mx[1][0] = t * unitAxis._x * unitAxis._y - unitAxis._z * s;	_Mx[2][0] = t * unitAxis._x * unitAxis._z + unitAxis._y * s;	_Mx[0][1] = t * unitAxis._x * unitAxis._y + unitAxis._z * s;	_Mx[1][1] = t * unitAxis._y * unitAxis._y + c;	_Mx[2][1] = t * unitAxis._y * unitAxis._z - unitAxis._x * s;	_Mx[0][2] = t * unitAxis._x * unitAxis._z - unitAxis._y * s;	_Mx[1][2] = t * unitAxis._y * unitAxis._z + unitAxis._x * s;	_Mx[2][2] = t * unitAxis._z * unitAxis._z + c;};  


Of course you will have to translate to the origin first too.

Hope this helps a little.

Edited by - Dr_Evil on July 14, 2000 8:16:43 AM
What about doing this:

    // Load identityLoadIdentity(matrix);// Translate to the position of your vectorTranslate(matrix, vec_x, vec_y, vec_z);// Rotate around this point nowYRotate(matrix, theta);    


Hope that works...
OldManDave

Edited by - OldManDave on July 14, 2000 8:40:11 AM
I think that I am correct in assuming that you are trying to rotate objects relative to their own orientation. In other words making a plane actually rotate in a realistig manner. I stumbled across a technique using frames. I would be happy to give you the code but not here because it''s so long.



Creativity -- Concept -- Code

Your game is nothing if you don't have all three.

Creativity -- Concept -- CodeYour game is nothing if you don't have all three.http://www.wam.umd.edu/~dlg/terc.htm
Yeah, that is about exactly what i''m trying to do... Thanks.

Were could I get the code then?

/CMN

This topic is closed to new replies.

Advertisement