CryEngine ViewMat

来源:互联网 发布:穷养儿富养女知乎 编辑:程序博客网 时间:2024/05/22 02:06
mathMatrixLookAt 函数生的矩阵和camera.GetViewMatrix 获得的视图矩阵不相同。
mathMatrixLookAt 函数与osg::Matrix::makeLookAt 函数产生的矩阵一致

// 对于Camera获得的ViewMatrix 经过以下方式可以正确计算:
{
osg::Matrix osgViewMatT = Matrix34ToOSG_T(camera.GetViewMatrix());
osg::Vec3d eye_, center_, up_;
osg::Matrix inv = osg::Matrix::inverse(osgViewMatT);
// note: e and c variables must be used inside this method instead of eye and center
// because eye and center are references and they may point to the same variable.
osg::Vec3d e = osg::Vec3d(0.0, 0.0, 0.0)*inv;
up_ = osg::Matrix::transform3x3(osgViewMatT, osg::Vec3d(0.0, 0.0, 1.0));
osg::Vec3d c = osg::Matrix::transform3x3(osgViewMatT, osg::Vec3d(0.0, 1, 0.0));
c.normalize();
c = e + c*1;
// assign the results
eye_ = e;
center_ = c;
}


inline osg::Matrix Matrix34ToOSG_T(const Matrix34& mat)
{
osg::Matrix osgMat;
osgMat.set(
mat.m00, mat.m10, mat.m20, 0,
mat.m01, mat.m11, mat.m21, 0,
mat.m02, mat.m12, mat.m22, 0,
mat.m03, mat.m13, mat.m23, 1
);
return osgMat;
}
原创粉丝点击