PDA

View Full Version : gluLookAt :: Rotation Angle



bobGL
09-29-2006, 10:23 PM
Im using gluLookAt for my camera, so far so good... I have control over every direction. However I would like to know how I can get the camera xyz rotation angles (0 ~ 360) oriented to the camera start position:

cam_pos->x = 0.0f;
cam_pos->y = 0.0f;
cam_pos->z = 1.0f;

cam_t_pos->x = 0.0f;
cam_t_pos->y = 1.0f;
cam_t_pos->z = 1.0f;

cam_up->x = 0.0f;
cam_up->y = 0.0f;
cam_up->z = 1.0f;


How can I do it!?

Tks in advance,

CrazyButcher
09-30-2006, 01:59 AM
search the web for "Matrix FAQ" it features examples on euler extraction and lots of other related information

bobGL
10-15-2006, 04:15 PM
I used the euler extraction method but the readings seems strange... Am I missing something or? there's my code:


GLdouble mat[16];
glGetDoublev(GL_MODELVIEW_MATRIX, mat);

float D;
float angle_y = D = asin( mat[2]); // Calculate Y-axis angle
float C = cos( angle_y );
float angle_x;
float angle_z;
float tr_x;
float tr_y;

angle_y *= RADIANT_TO_DEGREE;
if ( fabs( C ) > 0.005 ) // Gimball lock?
{
tr_x = mat[10] / C; // No, so get X-axis angle
tr_y = -mat[6] / C;
angle_x = atan2( tr_y, tr_x ) * RADIANT_TO_DEGREE;
tr_x = mat[0] / C; // Get Z-axis angle
tr_y = -mat[1] / C;
angle_z = atan2( tr_y, tr_x ) * RADIANT_TO_DEGREE;
}
else // Gimball lock has occurred
{
angle_x = 0; // Set X-axis angle to zero
tr_x = mat[5]; // And calculate Z-axis angle
tr_y = mat[4];
angle_z = atan2( tr_y, tr_x ) * RADIANT_TO_DEGREE;
}

// return only positive angles in [0,360]
if (angle_x < 0) angle_x += 360;
if (angle_y < 0) angle_y += 360;
if (angle_z < 0) angle_z += 360;


printf("%f %f %f\n", angle_x, angle_y, angle_z);