View Full Version : glUnrotate AnyOne?

jbarton

02-17-2003, 08:02 AM

I'm just geginning to understand Matritics and OpenGl... so bear with me.

How would one go about unrotating an object if you know:

cpt (Local center point)

pt1 (a point on the Local X axis)

pt2 (a point on the Local Y axis)

ptZ (a point on the Local Z axis)

I've looked at Different options and can see something in the Matrix, but through the brain fog it is'nt very clear.

The reason for this is I want to take the object and find the X,Y,Z rotation angles needed to align another object to it.

Thanks,

shinpaughp

02-17-2003, 08:55 AM

You could save the current modelview matrix for the first object using glGetFloatv, and use glLoadMatrix later to render the object that would be aligned with it. Or if they are drawn roughly at the same time, you could just use glPushMatrix and glPopMatrix. Push the matrix onto the stack where alignment should start, do other drawing and translation to finish first object, then pop the matrix off the stack to start drawing the second object.

jbarton

02-17-2003, 10:55 AM

That would work but I need the rotation of the current object at anytime after the model is created. The problem is that the original model is a set of lines and a more complex model is going to be placed in the same location. I'm believe the matrix or normalised vectors of the current models xyz axies can give the XYZ angles needed to glrotate the new model into position.

Thanks,

jbarton

02-17-2003, 05:38 PM

For anyone finding this question I finally found my solution.

angle_y = D = asin( mat[2]); /* Calculate Y-axis angle */

C = cos( angle_y );

angle_y *= RADIANS;

if ( fabs( C ) > 0.005 ) /* Gimball lock? */

{

trx = mat[10] / C; /* No, so get X-axis angle */

try = -mat[6] / C;

angle_x = atan2( try, trx ) * RADIANS;

trx = mat[0] / C; /* Get Z-axis angle */

try = -mat[1] / C;

angle_z = atan2( try, trx ) * RADIANS;

}

else /* Gimball lock has occurred */

{

angle_x = 0; /* Set X-axis angle to zero */

trx = mat[5]; /* And calculate Z-axis angle */

try = mat[4];

angle_z = atan2( try, trx ) * RADIANS;

}

/* 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;

This was found at http://www.j3d.org/matrix_faq/matrfaq_latest.html#Q37

The only problem is I have to subtract the anglez from 360 to get the correct angle but I beleive this is a fault on my end.

Thanks Guys and Gals..

Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.