|
1,我想做一个程序:
在空间中放置一个物体。用osg来模拟相机,把相机放在不同的位置,以不同的姿态(旋转),来拍摄这个物体。
2.我想到的方法是用漫游器来做,这样可能会方便一些,具体是不是,我也不清楚。
漫游器代码- #pragma once
- //RTManipulator.h头文件
- #include <osgGA/CameraManipulator>
- class CRTManipulator : public osgGA::CameraManipulator
- {
- public:
- CRTManipulator(void);
- ~CRTManipulator(void);
- public:
- /** set the position of the matrix manipulator using a 4x4 Matrix.*/
- virtual void setByMatrix(const osg::Matrixd& matrix);
- /** set the position of the matrix manipulator using a 4x4 Matrix.*/
- virtual void setByInverseMatrix(const osg::Matrixd& matrix) { setByMatrix(osg::Matrixd::inverse(matrix)); }
- /** get the position of the manipulator as 4x4 Matrix.*/
- virtual osg::Matrixd getMatrix() const;
- /** get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model view matrix.*/
- virtual osg::Matrixd getInverseMatrix() const;
- private:
- osg::Vec3 _center;
- osg::Quat _rotation;
- };
复制代码- #include "RTManipulator.h"
- CRTManipulator::CRTManipulator(void)
- {
- _center = osg::Vec3(0.0,100.0,0.0);
- _rotation = osg::Quat(0,osg::Vec3(0.0,0.0,1.0));
- }
- CRTManipulator::~CRTManipulator(void)
- {
- }
- void CRTManipulator::setByMatrix(const osg::Matrixd& matrix)
- {
- _center = matrix.getTrans();
- _rotation = matrix.getRotate();
- }
- osg::Matrixd CRTManipulator::getMatrix() const
- {
- return osg::Matrixd::rotate(_rotation)*osg::Matrixd::translate(_center);
- }
- osg::Matrixd CRTManipulator::getInverseMatrix() const
- {
- return osg::Matrixd::translate(-_center)*osg::Matrixd::rotate(_rotation.inverse());
- }
复制代码 在主函数里面- viewer->setCameraManipulator(new CRTManipulator());
复制代码 我现在就做了这么多,有两个问题:
1.这么做对不对
2.怎么来改变摄相机的位置和姿态。(假如说我已知了摄相机的旋转和平移矩阵) |
|