|
自定义了一个漫游器,使用KeySwitchMatrixManipulator来进行切换,但是切换到自定义的漫游器时,相机的位置和姿态发生了变化,这是为什么?????求解!!!
已经在自定义的漫游器中重写了setByMatrix,定义如下:
virtual void setByMatrix(const osg::Matrixd& matrix)
{
m_vPosition=matrix.getTrans();
m_vRotation=matrix.getRotate().asVec3();
//m_Matrix=matrix;
}
其中平移、旋转矩阵定义如下:osg::Vec3 m_vPosition;osg::Vec3 m_vRotation;
getMatrix、getInverseMatrix重写如下:
virtual osg::Matrixd getMatrix(void)const
{
//return m_Matrix;
osg::Matrixd mat;
mat.makeRotate(m_vRotation._v[0],osg::Vec3f(1.0,0.0,0.0),m_vRotation._v[1],osg::Vec3f(0.0,1.0,0.0),m_vRotation._v[2],osg::Vec3f(0.0,0.0,1.0));
return mat*osg::Matrixd::translate(m_vPosition);
}
virtual osg::Matrixd getInverseMatrix()const
{
/*return osg::Matrixd::inverse(m_Matrix);*/
osg::Matrixd mat;
mat.makeRotate(m_vRotation._v[0],osg::Vec3f(1.0,0.0,0.0),m_vRotation._v[1],osg::Vec3f(0.0,1.0,0.0),m_vRotation._v[2],osg::Vec3f(0.0,0.0,1.0));
return osg::Matrixd::inverse(mat*osg::Matrixd::translate(m_vPosition));
}
PS:测试了一下,如果直接使用矩阵的话,切换时相机的位置和姿态是一致的~~~~ |
|