Archived

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

Rotation Matrix

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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();
.
.
.
[/CODE]
^^^^^^^^^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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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)


Share this post


Link to post
Share on other sites