[osg-users] TrackballManipulator rotate camera about a point different from lookat point

shilpa varri shil.reddy9 at gmail.com
Thu Jun 18 19:53:05 PDT 2015


I'm using trackball manipulator to rotate my camera.
I have following inputs:
eye position, lookAtCenter position, up vector and spin center.
So basically I need to setup my trackballmanipulator such that it is located at 'eye' position looking at 'lookAtCenter' position with 'up' vector. But when I  move my mouse I need the manipulator to rotate about 'spin center' and not 'lookAtCenter'.
So the camera is looking at one point but rotating around a different point.

Now if I use the 'trackballmanipulator->setTransformation(eye, lookAtCenter , up)' when I move the mouse it automatically moves along the sphere of 'lookAtCenter'. 
I'm not sure how to overwrite this behavior so that it's looking at 'lookAtCenter' position but rotating about sphere of 'spin center'.

I've calculated the rotation matrix to rotate about 'spin center'. But how do I feed this to the trackballmanipulator to achieve the result?
Can anyone please help me?

Here's the code:
  osg::Vec3d eye = osg::Vec3d(cameraPos.at(0), cameraPos.at(1), cameraPos.at(2));
  osg::Vec3d viewVector = osg::Vec3d(cameraViewDirection.at(0), cameraViewDirection.at(1), cameraViewDirection.at(2));
  osg::Vec3d lookAtCenter(eye + viewVector);
  osg::Vec3d up = osg::Vec3d(cameraUpDirection.at(0), cameraUpDirection.at(1), cameraUpDirection.at(2));

  osg::Vec3d spinCenterVec = osg::Vec3d(spinCenter.at(0), spinCenter.at(1), spinCenter.at(2));

    osg::Matrixd transSpinToOrigin, transToSpinCenter, rotationAboutOrigin;

    transSpinToOrigin.makeTranslate(-spinCenterVec );
    transToSpinCenter.makeTranslate( spinCenterVec );
    rotationAboutOrigin.makeRotate( osg::DegreesToRadians(0.5), osg::Vec3d(1,0,0),
                        osg::DegreesToRadians(0.5), osg::Vec3d(0,1,0),
                        osg::DegreesToRadians(0.5), osg::Vec3d(0,0,1) );

    m_customRotationMat = new osg::Matrixd(transToSpinCenter * rotationMat * transSpinToOrigin);

    trackBallManipulator->setTransformation(eye, referencePtVector, up);

//After this, how do I use 'm_customRotationMat'? I've started overriding the manipulator class so I can use this somewhere. But I still don't know how?

Any help is much appreciated!
Thank you!


Read this topic online here:

More information about the osg-users mailing list