#### Archived

This topic is now archived and is closed to further replies.

# Rotating vectors around an axis

This topic is 6366 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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

##### Share on other sites
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

##### Share on other sites

  // 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

##### Share on other sites
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.