Matthias Ferch schrieb:

Andreas Goebel schrieb:

Matthias Ferch schrieb:

in my app, the user can enter 3 angles in degrees (float AngleX, AngleY, AngleZ) in text controls to set the rotation of a PositionAttitudeTransform. the entered values are then processed like this:

float qx = (AngleX*PI)/180.0f;
float qy = (AngleY*PI)/180.0f;
float qz = (AngleX*PI)/180.0f;

MeshTransform->setAttitude( Quat(qx, Vec3(1.0f, 0.0f, 0.0f), qy, Vec3(0.0f, 0.0f, 1.0f), -qz, Vec3(0.0f, 1.0f, 0.0f)) );

the user can alternativly simply rotate the PositionAttitudeTransform with the mouse. so i need to get the updated rotation values to update my text controls. my question is now, how can i extract these values back from the transform (in degrees)? yeah i suck at maths :D
thanks in advance!
_______________________________________________



Hi,

it´s not that easy and no shame to ask.
I have the nice book "Geometric toosl for computer graphics", and there is the following solution: - convert the quat to a matrix. Lets assume your matrix is r00, r01, r02 (first row), r10, r11, r12 (second row) and so on (convert this to your needs)

thetaY = asin(r02);
if (thetaY < PI/2.0) {
if (thetaY > -PI /2.0) {
thetaX = atan2(-r12, r22);
thetaZ = atan2(-r01, r00);
} else{
//solution is not unique!
thetaX = -atan2(r10, r11);
thetaZ = 0;
}
}else{
thetaX = atan2(r10, r11);
thetaZ = 0;
}

atan2 is defined in math.h

Please let me know if it works. You will have to calculate back the values do degrees, of yourse. The solution is not unique, and I don´t know if you have the ordering x, y, z.

Regards,

Andreas

oha ok, thank you! one problem though, i created a matrix from the quat, but how can i access the members of a matrix in osg? the [] operator is not defined..
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/


ok, i got it like this now:

osg::Quat attitude = parent_data->MeshTransform->getAttitude();
                   osg::Matrix matrix = osg::Matrix( attitude );

                   float r02 = matrix(0, 2);
                   float r12 = matrix(1, 2);
                   float r22 = matrix(2, 2);
                   float r01 = matrix(0, 1);
                   float r00 = matrix(0, 0);
                   float r10 = matrix(1, 0);
                   float r11 = matrix(1, 1);

                   float thetaX, thetaY, thetaZ;

                   thetaY = asin( r02 );
                   if( thetaY < PI/2.0 )
                   {
                       if( thetaY > -PI/2.0 )
                       {
                           thetaX = atan2( -r12, r22 );
                           thetaZ = atan2( -r01, r00 );
                       }
                       else
                       {
                           thetaX = -atan2( r10, r11 );
                           thetaZ = 0;
                       }
                   }
                   else
                   {
                       thetaX = atan2( r10, r11 );
                       thetaZ = 0;
                   }

VectorX->SetValue( -(thetaX*180.0f)/PI ); // why do i need a minus here?
                   VectorY->SetValue( -(thetaZ*180.0f)/PI );
                   VectorZ->SetValue( (thetaY*180.0f)/PI );)

does this look reasonable? well, it works correctly, if i enter values for VectorX and VectorY, but keep VectorZ = 0.0f. it also works if I enter a value for VectorZ, but keep VectorX = 0.0 and VectorZ = 0.0. but as soon as enter values for VectorZ and either ValueX or ValueY, the values are not given back correctly. trotzdem vielen dank schonmal :P


_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

Reply via email to