|
方法一:用PositionAttitudeTransform实现 把牛先平移后旋转 与 把牛先旋转后平移 效果一样
/***把牛先平移后旋转***/
osg::Group* root = new osg::Group;
osg::Node* cow = osgDB::readNodeFile("cow.osg");
osg:ositionAttitudeTransform* posCow = new osg::PositionAttitudeTransform;
root->addChild(posCow);
posCow->addChild(cow);
osg:uat quat;
//平移
posCow->setPosition(osg::Vec3(10,0.0,0.0));
//旋转
quat.makeRotate(osg::PI_2,osg::Vec3(0.0,0.0,1.0));
posCow->setAttitude(quat);
/***把牛先旋转后平移***/
osg::Group* root = new osg::Group;
osg::Node* cow = osgDB::readNodeFile("cow.osg");
osg::PositionAttitudeTransform* posCow = new osg::PositionAttitudeTransform;
root->addChild(posCow);
posCow->addChild(cow);
osg::Quat quat;
//旋转
quat.makeRotate(osg::PI_2,osg::Vec3(0.0,0.0,1.0));
//平移
posCow->setPosition(osg::Vec3(10,0.0,0.0));
posCow->setAttitude(quat);
通过实现表明,用PositionAttitudeTransform 把牛先平移后旋转 与 把牛先旋转后平移 效果一样,两只牛重合
效果贴图
方法二:用MatrixTransform 把牛先平移后旋转 与 把牛先旋转后平移 效果却不同
/*************旋转矩阵*平移矩阵 的方式**代码如下********/
osg::Quat quat1;
//创建变换节点
osg::MatrixTransform* matrixCow1 = new osg::MatrixTransform;
root->addChild(matrixCow1);
matrixCow1->addChild(cow);
quat1.makeRotate(osg::PI_2,osg::Vec3(0.0,0.0,1.0));
//旋转矩阵*平移矩阵
matrixCow1->setMatrix(osg::Matrixd::rotate(quat1)*osg::Matrixd::translate(osg::Vec3(10.0,0.0,0.0)));
/*************平移矩阵*旋转矩阵 的方式**********/
osg::Quat quat1;
//创建变换节点
osg::MatrixTransform* matrixCow1 = new osg::MatrixTransform;
root->addChild(matrixCow1);
matrixCow1->addChild(cow);
quat1.makeRotate(osg::PI_2,osg::Vec3(0.0,0.0,1.0));
//平移矩阵* 旋转矩阵
matrixCow1->setMatrix(osg::Matrixd::translate(osg::Vec3(9.0,0.0,0.0))*osg::Matrixd::rotate(quat1));
通过实现表明,用MatrixTransform把牛先平移后旋转 与 把牛先旋转后平移 效果不同,一个牛向前,一个牛向后,没有重合
请高手指点:这是为什么呢
MatrixTransform有什么特别之处吗
非常感谢! |
|