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長度。

相關示例:

  

  

  運行效果:

  

    對牛的位置做了平移和旋轉。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM