|
楼主 |
发表于 2011-10-24 22:06:32
|
显示全部楼层
回复 2# osg_student
您好,我是派生了两个节点回调做的,一个是实现回转,一个实现变幅。
然后怎么把这两个运动联系起来,先做完一个,再做另外一个。谢谢!- // 申请一个节点回调类,完成转台节点的回转运动
- class DOF1NodeCallback : public osg::NodeCallback
- {
- protected:
- double rotation; // rotation 参数,用于控制回转角度
- public:
- DOF1NodeCallback( ): rotation(0.0){}
- virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
- {
- osg::PositionAttitudeTransform* DOF1 =
- dynamic_cast<osg::PositionAttitudeTransform*>(node);
- if(DOF1)
- {
- if( rotation < 50 )
- rotation += 0.1;
- else
- rotation -= 0.1;
- osg::Quat quat(osg::DegreesToRadians(rotation),osg::Z_AXIS);
- DOF1->setAttitude(quat);
- }
- traverse(node,nv);
- }
- };
- //申请一个节点回调类,完成主臂的变幅运动
- class DOF2NodeCallback : public osg::NodeCallback
- {
- protected:
- double elevation; //elevation参数,控制变幅角度
- bool up; //up 用来控制是否进行回转
- public:
- DOF2NodeCallback() : elevation(0.0){}
- virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
- {
- osg::PositionAttitudeTransform* DOF2 =
- dynamic_cast<osg::PositionAttitudeTransform*>(node);
- if(DOF2)
- {
- if(elevation > 20)
- up = false;
- if(elevation < -15)
- up = true;
- if(up)
- elevation += 0.05;
- else
- elevation -=0.05;
- osg::Quat quat1(osg::DegreesToRadians(elevation),osg::Y_AXIS);
- DOF2->setAttitude(quat1);
- }
- traverse(node,nv);
- }
- };
复制代码 |
|