[osg-users] Local Camera angles

Sebastian Messerschmidt sebastian.messerschmidt at gmx.de
Mon May 23 00:52:57 PDT 2016


Hi Wojtek,

Use the the coordinateSystemNode:

osg::CoordinateSystemNode* csn = new osg::CoordinateSystemNode();
csn->setEllipsoidModel(new osg::EllipsoidModel());
osg::Matrixd local_frame = csn->computeLocalCoordinateFrame(position); 
//where position is your global position

The resulting matrix describes the position and orientation in the 
world-frame-
Hence the inverse will contain the local rotation. So in theory:

Quat q = your_world_rotation;//from the model_view
Mat local_frame_inv = inverse(local_frame);
Quat q_local = local_frame_inv * q;

The q_local will then represent the local rotation which you then can 
decompose into the HPR.

HTH
Sebastian


> 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
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org





More information about the osg-users mailing list