osg模型操作之矩阵变换(直接对矩阵操作,从而达到效果)

矩阵变换节点:

  由osg::MatrixTransform : osg::Transform : osg::Group : osg::Node : osg::Object : osg::Referenced的继承。

  主要作用是负责场景的矩阵变换、矩阵的运算及坐标系的变换。实现对场景的模型进行旋转、平移等操作。

常用主要成员函数:

  void setMatrix(const Matrix &mat)//设置矩阵。

  const Matrix & getMatrix() const //得到矩阵。

  void preMult(const Matrix &mat)//递乘,比较类似于++a。

  void postMult(const Matrix &mat)//递乘,比较类似于a++。

  const Matrix & getInverseMatrix() const //得到逆矩阵。

例如:

  osg::ref_ptr<osg::MatrixTransform> mt = new osg::MatrixTransform;

  mt->setMatrix( osg::Matrix::scale(scaleX,0.0,0.0) * osg::Matrix::rotate(rotateZ,osg::Z_AXIS) * osg::Matrix::translate(posX,0.0,0.0)  );

  上面这两行的代码执行的效果是:对模型x轴缩放scaleX,沿z轴旋转rotateZ度,沿x轴移动posX长度。

相关示例:

  

  

  运行效果:

  

    对牛的位置做了平移和旋转。

posted @ 2018-09-10 15:58  一梦、  阅读(2618)  评论(0编辑  收藏  举报