|
本帖最后由 zhoujiajun2010 于 2011-6-23 21:49 编辑
- virtual void operator()(osg::Node *node, osg::NodeVisitor *nv)//更新回调二
- {
- osg::PositionAttitudeTransform *zhutuiqi = dynamic_cast<osg::PositionAttitudeTransform*>(node);
- if(zhutuiqi)
- {
- zhutuiqi->setPosition(osg::Vec3(0, 0, z ));
- z-=1;
- }
- }
- traverse(node, nv);
- }
- protected:
- float x;
- float y;
- float _angle;
- float rot;
- //float hudu;
- //float z;
- float z1;
- int _time;
- };
- /*更新回调1*/
- class FaSheDanCallback:public osg::NodeCallback
- {
- public:
- FaSheDanCallback():_angle(osg::PI),rot(osg::PI/6), /*hudu(0.0),*/ /*z(-100.0), */_time(0),x(0.0),y(0.0)/*,zizhu(0.0)*/ {}
- virtual void operator()(osg::Node *node, osg::NodeVisitor *nv)
- {
- osg::PositionAttitudeTransform *matrixfashe = dynamic_cast<osg::PositionAttitudeTransform*>(node);
- if(matrixfashe)
- {
- //直线
- if (z < 1000)
- {
- matrixfashe->setPosition(osg::Vec3(0, 0, z ));
- matrixfashe->setAttitude(osg::Quat(zizhu,osg::Z_AXIS));
- z += 1;
- zizhu+=osg::PI/30;
- if(zizhu>=2*osg::PI)
- {
- zizhu=0.0;
- }
- }
- if((y<200)&&(z>=1000))
- {
- x = 200+200*cos(_angle);
- y = 200+200*cos(_angle);
- z =1000+200*sin(_angle);
- matrixfashe->setAttitude(osg::Quat(hudu,osg::Vec3(1,-1,0))); //旋转模型
- matrixfashe->setPosition(osg::Vec3(x,y,z));
- _angle -= osg::PI/200;
- hudu -= osg::PI/200;
- if(hudu<-osg::PI_2)
- hudu=-osg::PI_2;
- ZhuTuiQi2->removeChild(ZhuTuiQi1.get());
- ZhuTuiQi1->addUpdateCallback(new ZhuTuiQi1Callback());//添加更新回调二
- }
- traverse(node, nv);
- }
- protected:
- float x;
- float y;
- float _angle;
- float rot;
- float z1;
- int _time;
- };
复制代码
我把三个模型通过PositionAttitudeTransform 连接成一个模型(这三个模型分别是ZhuTuiQi1,ZhuTuiQi2,Dantou),进行回调使其运动,当运动到一段时间后,让ZhuTuiQi1从这个模型分离出来,使ZhuTuiQi1按照另一种方始运动,ZhuTuiQi1->addUpdateCallback(new ZhuTuiQi1Callback());//添加更新回调二
但是发现分离后的模型不出现,这种情况应该怎样解决啊?谢谢 |
|