Rotation Matrix

Started by
3 comments, last by DarkRave 21 years, 7 months ago
Hi, how do i create a axis-angle rotation matrix in detail????
Advertisement
glRotatef(angle, 1.0, 0, 0)
the above rotation will multiply the proper rotation matrix automatically by the current matrix. The order in which you perform transformations will drastically vary in the final effect. Think about it. Say your program is only drawing a spere at the grand fixed origin, where the camera rests by default(0,0,0). In your display function, if you wanted to rotate a sphere and then translate it. you''d do this:
void display(void){	glClear(GL_COLOR_BUFFER_BIT);	glColor3f(1.0, 1.0, 1.0);			glPushMatrix();	glTranslatef(-3.0, 0, 0);	glRotatef((GLfloat) ???angle, 0, 1.0, 0);	glutWireSphere(0.05f, 6, 4);	glPopMatrix();        .        .        .

^^^^^^^^^The above will first rotate an abstract local origin about the origin, thin will move it "-3" along the x. Done backwards, this would result in the sphere orbiting around the grand origin rather than rotating about it. The normal vector
for rotation (0,1,0) just says to rotate around the y axis.
if it had been(0,0,0), around what would it rotate?!?!?!
*notice how rotate comes after translate, it''s because the Matrix multiplication order is backwards, somewhat.
i.e. T(R*Sphere)
for t = trans, r = rotation
***very important to grasp!

well, a rotation matrix that rotate around the Z axis

cos( ang ) -sin( ang ) 0
sin( ang ) cos( ang ) 0
0 0 1

around Y axis

cos( ang ) 0 -sin( ang )
0 1 0
sin( ang ) 0 cos( ang )

and around X axis

1 0 0
0 cos( ang ) -sin( ang )
0 sin( ang ) cos( ang )

i hope this was that you are looking for.
http://www.flipcode.com/documents/matrfaq.html
given angle
and a direction (x, y, z) (where ||(x, y, z)|| = 1)

then the matrix is
<pre>
xx * (1 - c) + c xy * (1- c) - zs xz * (1 - c) + ys 0
yx * (1 - c) + zs yy * (1 - c) + c yz * (1 - c) - xs 0
zx * (1 - c) - ys zy * (1 - c) + xs zz * (1 - c) + c 0
0 0 0 1
</pre>

where c = cos(angle)
where s = sin(angle)


This topic is closed to new replies.

Advertisement