矩陣變換節點:
由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長度。
相關示例:
運行效果:
對牛的位置做了平移和旋轉。