View Full Version : Rotate around an axis?
05-01-2002, 01:21 PM
What is the algo for rotating around an axis.
You start with a point ( 0,1 ) on a circle centered at (0,0). Then you rotate theta degrees. What is the new x,y coordinates of the point.
Or what is the aglo for it?
05-01-2002, 01:38 PM
for a point locate (0,1) and a ratation axis centered in (0,0) a theta rotation gives new point location : (cos(theta),sin(theta))
when theta is in radian
05-01-2002, 07:58 PM
OK. I have function called rotate that rotates and object and a vector the same amount.
float ry = 0; //holds how much to rotate the character.
cPosition; //(x,y,x) holds where character is located initialized as 0,0,0
cDirection; //(x,y,z) holds where the character is looking, initialized 0,0,1
If you called the funtion rotate() with 90
it would change ry to 90 and change x = 1, y = 0, z = 0;
The distance between where the character and his view is 1 unit.
i have something like:
void rotate( float x, float y, float z )
if( Y > 0 )
ry -= Y;
if( Y < 0 )
ry += Y;
//rotate the cDirection around cPosition Y degrees keeping in mind its 1 unit away from it.
What should I replace the comment with to get what I want?
05-02-2002, 04:57 PM
First, I suggest you use the terms yaw, pitch, and roll instead of x, y, and z.
Next, the easiest way to do this is to rotate around each of the guy's own axes and the order of rotation is important -- this order is the easiest to use: yaw (turn), pitch(up/down), roll(tilt).
Next, this code will keep track of the rotation:
float yaw=0, pitch=0, roll=0;
void rotate( float dy, float dp, float dr )
yaw += dy;
pitch += dp;
roll += dr;
This code will rotate your guy according to the current rotation values (remember the rotation is around the guy's own axes and the order is yaw, then pitch, then roll).
glRotate( yaw, 0,1,0 );
glRotate( pitch, 1,0,0 );
glRotate( roll, 0, 0, -1 );
Note: as long as pitch and roll are between -90 and 90, there is no gimble lock problem.
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.