VCTravel
#pragma once #include <osgViewer/Viewer> #include <osgViewer/ViewerEventHandlers> #include <osgViewer/CompositeViewer> #include <osgDB/ReadFile> #include <osg/Geode> #include <osg/Node> #include <osgGA/TrackballManipulator> #include <osg/GraphicsContext> #include <osg/ShapeDrawable> #include <osg/Material> #include <osg/Image> #include <osg/Texture2D> #include <osg/TexEnv> #include <osg/TexGen> #include <osg/MatrixTransform> #include <osg/PositionAttitudeTransform> #include <osg/AnimationPath> #include <osg/Matrixd> #include <osgGA/GUIEventHandler> #include <osgGA/CameraManipulator> #include <osgGA/StandardManipulator> #include <osgGA/OrbitManipulator> #include <osgGA/TrackballManipulator> class VCTravel : //public MatrixManipulator public osgGA::CameraManipulator { public: VCTravel(); ~VCTravel(); //设置当前视口 virtual void setByMatrix(const osg::Matrixd& matrix); // virtual void setByInverseMatrix(const osg::Matrixd& matrix); //获取 virtual osg::Matrixd getMatrix() const; //得到矩阵逆 virtual osg::Matrixd getInverseMatrix() const; private: //视点 osg::Vec3 vec_position; //方向 osg::Vec3 vec_rotation; };
#include "VCTravel.h" VCTravel::VCTravel() { vec_position = osg::Vec3(0.0,0.0,0.0); vec_rotation = osg::Vec3(0.0, 0.0, 0.0); } VCTravel::~VCTravel() { } //设置当前视口 void VCTravel::setByMatrix(const osg::Matrixd& matrix) { } // void VCTravel::setByInverseMatrix(const osg::Matrixd& matrix) { } //获取 osg::Matrixd VCTravel::getMatrix() const { osg::Matrixd mat; mat.makeTranslate(vec_position); return mat*osg::Matrixd::rotate(vec_rotation[0], osg::X_AXIS, vec_rotation[1], osg::Y_AXIS, vec_rotation[2], osg::Z_AXIS); } //得到矩阵逆 osg::Matrixd VCTravel::getInverseMatrix() const { osg::Matrixd mat; mat.makeTranslate(vec_position); //return mat*osg::Matrixd::rotate(vec_rotation[0], osg::X_AXIS, vec_rotation[1], osg::Y_AXIS, vec_rotation[2], osg::Z_AXIS); return osg::Matrixd::inverse(mat*osg::Matrixd::rotate(vec_rotation[0], osg::X_AXIS, vec_rotation[1], osg::Y_AXIS, vec_rotation[2], osg::Z_AXIS)); }
QQ 3087438119