PDA

View Full Version : Rotate matrix



Platinum
12-14-2001, 08:18 PM
I understand basic matrix transformations (T, S, R around x, y or z axe) but now I need to rotate not just around an axe, but around a vector(x, y, z). Can someone tell me a matrix for this rotation? (4x4)

(I don't want to use the glRotate, I need the matrix separately. And letting OpenGL do the transformation and then getting the matrix out of it looks like a long way around. For example I have the sin/cos calculation already done, so I want to use them.)

thanks in advance

Bob
12-15-2001, 03:46 AM
Code taken directly from my code, which in turn is taken from MESA.

axis is the axis of rotation.
degree is angle in degrees.




matrix mat;

vector3 a = axis.normalized();

float s = fsin(degrees);
float c = fcos(degrees);

float xx;
float yy;
float zz;
float xy;
float yz;
float zx;
float xs;
float ys;
float zs;
float one_c;

xx = a.X * a.X;
yy = a.Y * a.Y;
zz = a.Z * a.Z;
xy = a.X * a.Y;
yz = a.Y * a.Z;
zx = a.Z * a.X;
xs = a.X * s;
ys = a.Y * s;
zs = a.Z * s;

one_c = 1.0f - c;

mat.M[0] = (one_c * xx) + c;
mat.M[1] = (one_c * xy) + zs;
mat.M[2] = (one_c * zx) - ys;
mat.M[4] = (one_c * xy) - zs;
mat.M[5] = (one_c * yy) + c;
mat.M[6] = (one_c * yz) + xs;
mat.M[8] = (one_c * zx) + ys;
mat.M[9] = (one_c * yz) - xs;
mat.M[10] = (one_c * zz) + c;

return mat;

Platinum
12-16-2001, 08:38 PM
thanks http://www.opengl.org/discussion_boards/ubb/biggrin.gif
I'll try it.

greets
Platinum