PDA

View Full Version : Vector rotation



06-11-2003, 03:28 AM
Can somebody give me a routine or a piece of code how to rotate a vector?

thoean
06-11-2003, 08:07 AM
// matrix multiplication
Vector3D mXv(MatrixA d, Vector3D p)
{
Vector3D e;
e.x=d[0][0]*p.x+d[1][0]*p.y+d[2][0]*p.z;
e.y=d[0][1]*p.x+d[1][1]*p.y+d[2][1]*p.z;
e.z=d[0][2]*p.x+d[1][2]*p.y+d[2][2]*p.z;
return e;
}


MatrixA rotMatrix = {
{ cos(angle), 0.0f, -sin(angle)},
{ 0.0f, 1.0f, 0.0f},
{ sin(angle), 0.0f, cos(angle)}};

depending on the axis, the sin and cos are placed on other positions in the matrix.

if you need to rotate in 3d, then 4 dimensions of the matrix and the vector are needed.

thoean

06-11-2003, 08:24 AM
thx man!