[osg-users] Improvement of Arcball Camera Handling
Daniel Neos
daniel.rd at hotmail.de
Thu Jul 21 08:42:33 PDT 2016
Hi,
I want to improve my CameraHandling since it acts a little bit odd if I am too far in the center of the scene, which is the lookat-point of the camera.
The camera is rotates around a specific point(mid of the boundingsphere center), always looking at it.
But if I am getting to close to the midpoint, sometimes I lose the focus point or the camera rotates very fast. My code is rather simple, maybe there is a caveat which I am not aware of.
Also the distance changes, if I am rotating around the same axis everytime, I get close or far away.
Code:
void OsgWidgetEventHandler::rotateOrbitCamera(double angle, const osg::Vec3d& axis, osgViewer::View* viewer)
{
const osg::Matrixd rotation = osg::Matrix::rotate(angle, axis);
osg::Matrixd preTrans = osg::Matrix::identity();
osg::Matrixd postTrans = osg::Matrix::identity();
const osg::Vec3 translation = viewer->getCamera()->getViewMatrix().getTrans();
m_rotationPoint = translation - m_boundingSphereCenter;
preTrans.setTrans(-m_rotationPoint);
postTrans.setTrans(m_rotationPoint);
osg::Matrixd viewMatrix = viewer->getCamera()->getViewMatrix();
viewMatrix = viewMatrix * (preTrans * rotation * postTrans);
viewer->getCamera()->setViewMatrix(viewMatrix);
osg::Vec3d eye, center, up;
viewer->getCamera()->getViewMatrixAsLookAt(eye, center, up);
if (m_focusPointFlag)
{
viewer->getCamera()->setViewMatrixAsLookAt(eye, m_boundingSphereCenter, up);
}
}
The m_focusPointFlag is only false when the camera was translated(not zoomed), so that the lookat point can be changed.
How can I achieve a smooth arcball camera behaviour?
Thank you!
Cheers,
Daniel
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=68194#68194
More information about the osg-users
mailing list