SphericalManipulator是一个 OpenSceneGraph (OSG) 的输入设备处理器,它可以实现通过鼠标控制经纬度和距离来控制场景中的相机。
#include <osgGA/SphericalManipulator>
osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer;
osg::ref_ptr<osg::Group> root = new osg::Group;
osg::ref_ptr<osg::Node> scene = osgDB::readNodeFile("cow.osg");
root->addChild(scene);
osg::ref_ptr<osgGA::SphericalManipulator> manipulator = new osgGA::SphericalManipulator;
viewer->setCameraManipulator(manipulator);
viewer->setSceneData(root);
viewer->run();
SphericalManipulator(double scale = 1.0, int flags = DEFAULT_SETTINGS);
SphericalManipulator(const SphericalManipulator& rhs, const osg::CopyOp& copyOp = osg::CopyOp::SHALLOW_COPY);
scale
:控制相机移动的速度,数值越大速度越快,默认为1.0。flags
:设置 manipulator 的选项,默认为DEFAULT_SETTINGS
。void setHomePosition(const osg::Vec3d& eye,const osg::Vec3d& center,const osg::Vec3d& up,bool autoComputeHomePosition = false);
eye
:相机位置。center
:相机看向的点。up
:相机的上向量。autoComputeHomePosition
:是否自动计算 Home Position,默认为false
。osg::Vec3d getPosition() const;
float getDistance() const;
float getLatitude() const;
float getLongitude() const;
getPosition()
:获取相机位置。getDistance()
:获取相机距离。getLatitude()
:获取相机纬度。getLongitude()
:获取相机经度。