[osg-users] Local Camera angles

Wojtek Kowalski karcios at poczta.onet.pl
Fri May 20 00:07:58 PDT 2016


Hi,

How to get local rotation angles when camera is set by setViewMatrixAsLookAt?

I've got two camera modes:
1) Camera is set by global position and local angles

Code:
osg::Matrix worldMatrix;
ellipsoid->computeLocalToWorldTransformFromLatLongHeight(longitude, latitude, height, worldMatrix);

osg::Vec3 yawAxis( 0.f, 0.f, 1.f );
osg::Vec3 pitchAxis( 1.f, 0.f, 0.f );
osg::Vec3 rollAxis( 0.f, 1.f, 0.f );

//roll,pitch, yaw - local angles
osg::Matrix rotationMat = osg::Matrix::rotate(roll, rollAxis)// Roll
* osg::Matrix::rotate(pitch, pitchAxis)// Pitch
* osg::Matrix::rotate( yaw, yawAxis);// Yaw

camera>setViewMatrix(osg::Matrix::inverse(rotationMat * worldMatrix));




2) Camera is set by global eyepos, globalcenter and up vector

Code:
ECEFpnt (position in global) is calcualted from lot, lan, alt
osg::Vec3f upVec = ellipsoid->computeLocalUpVector(ECEFpnt.x(), ECEFpnt.y(), ECEFpnt.z());

camera->setViewMatrixAsLookAt(ECEFpnt, groundPosECEF, upVec);




How to get camera local angles in this case?!?!?

>From Mat -> angles I will use

Code:
osg::Vec3d getHPRfromQuat(osg::Quat quat)
{
double qx = quat.x();
double qy = quat.y();
double qz = quat.z();
double qw = quat.w();

double sqx = qx * qx;
double sqy = qy * qy;
double sqz = qz * qz;
double sqw = qw * qw;

double term1 = 2*(qx*qy+qw*qz);
double term2 = sqw+sqx-sqy-sqz;
double term3 = -2*(qx*qz-qw*qy);
double term4 = 2*(qw*qx+qy*qz);
double term5 = sqw - sqx - sqy + sqz;

double heading = atan2(term1, term2);
double pitch = atan2(term4, term5);
double roll = asin(term3);

return osg::Vec3d( heading, pitch, roll );
}


but I need local rotationMat! How!?:)

Thank you!

Cheers,
Wojtek[/code]

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=67164#67164








More information about the osg-users mailing list