Sign in to follow this  
schoolkid

GL rotation

Recommended Posts

hi all, I couldn't understand the difference of the following set of commands :: 1 ---- glRotatef (30.0, 0.0, 1.0, 0.0); glRotatef (30.0, 0.0, 0.0, 1.0); 2 --- glRotatef (30.0, 0.0,1.0,1.0); Shouldn't the above 2 be same ? ~ boyd

Share this post


Link to post
Share on other sites
No, the first one is saying to rotate 30 degrees around the Y axis, and then rotate 30 degrees around the Z axis.

The second one is saying to rotate 30 degrees around a line in the Y-Z plane that runs 45 degrees to to both the Y and Z axes.

Share this post


Link to post
Share on other sites
glRotatef takes four paremeters:
- angle, given in degs
- x, y, z that is vector

so glRotatef rotates model around specified vector...

<ang> < vector >
glRotatef(30.0f, 1.0f, 0.0f, 0.0f); - around X axis
glRotatef(30.0f, 0.0f, 1.0f, 0.0f); - around Y axis
glRotatef(30.0f, 0.0f, 0.0f, 1.0f); - around Z axis

so this function is very flexible

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
It takes a second to fully get this into one's head but the order that rotations occur changes the final resting place.

To verify this take a book and place it at the corner of a table. Flip it along one edge and the flip it on one of the edges of the book. Note the final resting place, which side is up and the rotation of the cover.

Now do the same rotations in another order. Different place eh?

This is because rotations are essentially matrix transformation, by that I meant the each rotation can be expressed by a matrix and several rotation can be expressed by multiplying them together.

Unlike plain old variable multiplication, matrix multiplication order alters the result. There is a math word for this. Communative I think....


Share this post


Link to post
Share on other sites
if i not wrong...

glRotationf(angle,vector x,vector y,vector z)

same to:


cVector3d rotate(float angle,float vx,float vy,float vz,cVector3d point)
{
cVector3d temp;

temp.x=(cos(angle)*point.x + sin(angle)*point.z)*vy +
point.x*vx +
(cos(angle)*point.x - sin(angle)*point.y)*vz;

temp.y=point.y*vy +
(point.y * cos(angle) - point.z * sin(angle))*vx +
(point.x * sin(angle) + point.y * cos(angle))*vz;

temp.z=(point.x * -sin(angle) + point.z * cos(angle))*vy +
(point.y * sin(angle) + point.z * cos(angle))*vx +
point.z*vz;

return temp;
}

angle in radian;

1 degree = 3.141592653589793 / 180 rad

am i right ?

-ghckr82--

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this