|
我是在3D Max8中建模,完成一个箱子,然后导成osg文件,现在要打开一个箱门,箱门绕Z轴旋转,在3D Max中手动测量了门的宽度,最后旋转有偏差。代码如下:
osg::Matrixf max;
osg::MatrixTransform* pMat = dynamic_cast<osg::MatrixTransform*>(_node.get());//要旋转的箱门
osg::BoundingSphere bsh = _node.get()->getBound();//取得包围球
//先移回原点 _GeometryAttr._fLength为在3D Max中手动测量的门的宽度
max.identity();
max.makeTranslate(-(bsh._center._v[0]-_GeometryAttr._fLength/2),-(bsh._center._v[1]),0.0f);
pMat->postMult(max);
//进行旋转 绕Z轴旋转
max.identity();
max.makeRotate(osg:egreesToRadians(-90.0f),0.0f,0.0f,1.0f);
pMat->postMult(max);
//再移回原处
max.identity();
max.makeTranslate((bsh._center._v[0]-_GeometryAttr._fLength/2),(bsh._center._v[1]),0.0f);
pMat->postMult(max); |
|