|
楼主 |
发表于 2011-7-7 09:51:30
|
显示全部楼层
本帖最后由 zhoujiajun2010 于 2011-7-7 09:54 编辑
回复 4# array
- #include<osg/MatrixTransform>
- #include<osgGA/MatrixManipulator>
- #include <osgAnimation/UpdateCallback>
- #include<osg/Geode>
- #include<osg/ShapeDrawable>
- #include<osgDB/ReadFile>
- #include<osgViewer/Viewer>
- #include<osg/Image>
- #include<osg/Texture2D>
- #include<osg/Material>
- #include<osg/PositionAttitudeTransform>
- #include<osgGA/NodeTrackerManipulator>
- #include<osg/Matrix>
- #include<osgViewer/ViewerEventHandlers>
- #include <osgParticle/ExplosionDebrisEffect>
- #include <osgParticle/ExplosionEffect>
- #include <osgParticle/SmokeEffect>
- #include <osgParticle/FireEffect>
- #include<windows.h>
- #include<osg/BoundingSphere>
- #include <osgUtil/Optimizer>
- #include <osg/BlendFunc>
- #include <osg/Depth>
- #include <osg/Projection>
- #include <osg/Camera>
- #include <osg/io_utils>
- #include <osgText/Text>
- #include <sstream>
- #include<osg/Node>
- #include <osgGA/TrackballManipulator>
- #include <osg/Notify>
- #include <osgDB/Registry>
- #include <osgGA/KeySwitchMatrixManipulator>
- #include <osg/Transform>
- #include <osgText/Font>
- #include "KeyboardHandler.h"
- #include <osgParticle/Particle>
- #include <osgParticle/ParticleSystemUpdater>
- #include <osgParticle/ModularEmitter>
- #include <osgParticle/RandomRateCounter>
- #include <osgParticle/MultiSegmentPlacer>
- #include <osgParticle/PointPlacer>
- #include <osgParticle/SectorPlacer>
- #include <osgParticle/RadialShooter>
- #include <osgParticle/FluidProgram>
- #include <osgParticle/ModularProgram>
- #include <osgParticle/AccelOperator>
- #include <osgParticle/FluidFrictionOperator>
- #include <osgParticle/LinearInterpolator>
- #include <osgParticle/ParticleSystem>
- #include <string>
- #include <iostream>
- #include <osg/Sequence>
- float z=-50.0;
- bool ZhuYuiTuoLi_lable;
- osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer;
- osg::ref_ptr<osg::PositionAttitudeTransform> matrixfashe = new osg::PositionAttitudeTransform;
- osg::ref_ptr<osg::PositionAttitudeTransform>ZhuTuiQi2=new osg::PositionAttitudeTransform(); // 声明并初始化位置变换节点
- osg::ref_ptr<osg::PositionAttitudeTransform>ZhuTuiQi1=new osg::PositionAttitudeTransform(); // 声明并初始化位置变换节点
- osg::ref_ptr<osg::PositionAttitudeTransform>ZhuTuiQi1CALLback=new osg::PositionAttitudeTransform();
- osg::ref_ptr<osg::PositionAttitudeTransform>ZhuTuiQi2CALLback=new osg::PositionAttitudeTransform();
- osg::ref_ptr<osg::Node> dantou=osgDB::readNodeFile("MuBiaoDan/Mdantou1.obj");
- osg::ref_ptr<osg::Node> zhuituiqi1= osgDB::readNodeFile("MuBiaoDan/Mzhutuiqi11.obj");
- osg::ref_ptr<osg::Node> zhuituiqi2= osgDB::readNodeFile("MuBiaoDan/Mzhutuiqi21.obj");
- unsigned int width,height;
- unsigned int count = 0;
- int ex = 0;
- float pos = 0.0;
- int cnt= 0;
- float dis = 0.0;
- int bait = 0;
- float hudu=0.0;
- float zizhu=0.0;
- float y=0.0;
- //float x=0.0;
- int IM1=0;
- int IM2=0;
- int IN1=0;
- int IN2=0;
- //---------------------------------发射烟雾-----------------------------//
- void createDarkSmoke(osg::ref_ptr<osg::MatrixTransform> smokeNode)
- {
- osg::ref_ptr<osg::Geode> geode = new osg::Geode;
- //创建粒子系统模板
- osgParticle::Particle ptemplate;
- //设置粒子形状
- ptemplate.setShape(osgParticle::Particle::QUAD);
- //设置生命周期
- ptemplate.setLifeTime(50.0);//单位:秒
- //设置粒子大小变化范围
- ptemplate.setSizeRange(osgParticle::rangef(10.0, 260.0));//单位:米
- //设置粒子Alpha变化范围
- // ptemplate.setAlphaRange(osgParticle::rangef(0.0f, 1.0f));
- /* //设置粒子颜色变化范围
- ptemplate.setColorRange(osgParticle::rangev4(
- osg::Vec4(1.0f, 0.5f, 0.3f, 1.0f),
- osg::Vec4(0.0f, 0.7f, 1.0f, 0.0f)));*/
- //设置半径
- ptemplate.setRadius(0.2f);
- //设置重量
- ptemplate.setMass(10.0f);//单位:千克
- //设置位置
- ptemplate.setPosition(osg::Vec3(0.0f, 0.0f, 0.0f));
- //初速度
- ptemplate.setVelocity(osg::Vec3(1.0f, 1.0f, 1.0f));
- ptemplate.setSizeInterpolator(new osgParticle::LinearInterpolator);
- ptemplate.setAlphaInterpolator(new osgParticle::LinearInterpolator);
- //创建粒子系统
- osg::ref_ptr<osgParticle::ParticleSystem> ps = new osgParticle::ParticleSystem();
- ps->setDataVariance(osg::Node::STATIC);
- //设置材质,是否放射粒子,是否添加光照
- ps->setDefaultAttributes("11.bmp", true, false);
- //加入模板
- ps->setDefaultParticleTemplate(ptemplate);
- //创建发射器和计数器,调整每一帧增加的粒子的数目
- osg::ref_ptr<osgParticle::RandomRateCounter> counter = new osgParticle::RandomRateCounter();
- //设置每秒添加的粒子的个数
- counter->setRateRange(0, 10);
- //每秒新生成的粒子范围
- counter->setDataVariance(osg::Node::DYNAMIC);
- //设置一个点放置器
- osg::ref_ptr<osgParticle::PointPlacer> placer = new osgParticle::PointPlacer();
- //设置位置
- placer->setCenter(osg::Vec3(0.0f, 0.0f, 0.05f));
- placer->setDataVariance(osg::Node::DYNAMIC);
- //创建弧度发射器
- osg::ref_ptr<osgParticle::RadialShooter> shooter = new osgParticle::RadialShooter();
- //设置发射器速度变化范围
- shooter->setInitialSpeedRange(10, 15);//单位:米/秒
- //设置发射器属性
- shooter->setDataVariance(osg::Node::DYNAMIC);
- shooter->setThetaRange(0.1f,-0.1f);//弧度值,与Z轴夹角0.392699f
- shooter->setPhiRange(0.1f,-0.1f);
- //创建粒子放射器(包括计数器、放置器和发射器)
- osg::ref_ptr<osgParticle::ModularEmitter> emitter = new osgParticle::ModularEmitter();
- emitter->setDataVariance(osg::Node::DYNAMIC);
- emitter->setCullingActive(false);
- //关联粒子系统
- emitter->setParticleSystem(ps.get());
- //关联计数器
- emitter->setCounter(counter.get());
- //关联点放置器
- emitter->setPlacer(placer.get());
- //关联发射器
- emitter->setShooter(shooter.get());
- smokeNode->addChild(emitter.get());
- osg::ref_ptr<osgParticle::ModularProgram> program = new osgParticle::ModularProgram();
- program->setParticleSystem(ps.get());
- osg::ref_ptr<osgParticle::ParticleSystemUpdater> psu = new osgParticle::ParticleSystemUpdater();
- psu->addParticleSystem(ps.get());
- smokeNode->addChild(psu.get());
- smokeNode->addChild(program.get());
- geode->addDrawable(ps);
- smokeNode->addChild(geode);
- }
- //更新回调1
- class ZhuTuiQi1Callback:public osg::NodeCallback
- {
- public:
- ZhuTuiQi1Callback():z1(1000.0),x(0),y(0),_angle(osg::PI),s(0),zs(0),s1(0){}
- virtual void operator()(osg::Node *node, osg::NodeVisitor *nv)
- {
- osg::PositionAttitudeTransform *zhutuiqi = dynamic_cast<osg::PositionAttitudeTransform*>(node);
- if(zhutuiqi)
- {
- if(z>=1000)
- {
- if(z1<=1150)
- {
- x = 150+150*cos(_angle);
- y = 150+150*cos(_angle);
- z1 =1000+150*sin(_angle);
- zhutuiqi->setPosition(osg::Vec3(x, y, z1 ));
- _angle -= osg::PI/500;
- if(_angle<=osg::PI_2)
- _angle=osg::PI_2;
- }
- if(z1>=1150)
- {
- x = 150+s;
- y = 150+s;
- z1 =1150-zs*s1/2;
- zhutuiqi->setPosition(osg::Vec3(x, y, z1 ));
- s+=1;
- s1+=0.5;
- zs+=0.05;
- }
- }
- }
- traverse(node, nv);
- }
- private:
- float x;
- float y;
- float _angle;
- float rot;
- float z1;
- int _time;
- float s;
- float s1;
- float zs;
- };
- //更新回调2
- class ZhuTuiQi2Callback:public osg::NodeCallback
- {
- public:
- ZhuTuiQi2Callback():z1(1200.0),x(200.0),/*y(200.0),*/_angle(osg::PI),s(0),zs(0),s1(0){}
- virtual void operator()(osg::Node *node, osg::NodeVisitor *nv)
- {
- osg::PositionAttitudeTransform *zhutuiqi = dynamic_cast<osg::PositionAttitudeTransform*>(node);
- if(zhutuiqi)
- {
- if(y>=500)
- {
- y+= 1;
- z1 =1200-zs*s1/2;
- zhutuiqi->setPosition(osg::Vec3(y, y, z1 ));
- s+=1;
- s1+=0.5;
- zs+=0.05;
- }
- }
- traverse(node, nv);
- }
- private:
- float x;
- float _angle;
- float rot;
- float z1;
- int _time;
- float s;
- float s1;
- float zs;
- };
- /**主更新回调*/
- class FaSheDanCallback:public osg::NodeCallback
- {
- public:
- FaSheDanCallback():_angle(osg::PI),rot(osg::PI/6),zizhu(-osg::PI_2), /*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::ref_ptr<osg::PositionAttitudeTransform>matrixfashe = dynamic_cast<osg::PositionAttitudeTransform*>(node);
- if(matrixfashe)
- {
- if (z < 1000)
- {
- matrixfashe->setPosition(osg::Vec3(0, 0, z ));
- 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;
- if(_angle<=osg::PI)
- {
- ZhuTuiQi2->removeChild(ZhuTuiQi1.get());
- ZhuYuiTuoLi_lable=true;
- }
- }
- else if(y>=200)
- {
- matrixfashe->setPosition(osg::Vec3(y,y,1200));
- matrixfashe->setAttitude(osg::Quat(-osg::PI_2,osg::Vec3(1,-1,0)));
- y+=1;
- if(y>=500)
- matrixfashe->removeChild(ZhuTuiQi2.get());//删除第一节助推器
- if(y>=1000)
- {
- matrixfashe->setAttitude(osg::Quat(zizhu,osg::Vec3(1,-1,0)));
- zizhu+=osg::PI/800;
- if(zizhu<osg::PI_2)
- zizhu=osg::PI_2;
- }
- if(y>=1200)
- {
- matrixfashe->setAttitude(osg::Quat(zizhu,osg::Vec3(1,-1,0)));
- zizhu+=osg::PI/400;
- if(zizhu>=osg::PI_2*3)
- zizhu=osg::PI_2*3;
- }
- }
- }
- traverse(node, nv);
- }
- private:
- float x;
- float _angle;
- float rot;
- float z1;
- int _time;
- float zizhu;
- };
- class BaitstCallback:public osg::NodeCallback
- {
- public:
- BaitstCallback():_angle(1.78),s(1.0),z1(1200){}
- virtual void operator()(osg::Node *node, osg::NodeVisitor *nv)
- {
- osg::PositionAttitudeTransform *matrixbait1 = dynamic_cast<osg::PositionAttitudeTransform*>(node);
- if(matrixbait1)
- {
- if(y>=500)
- {
- matrixbait1->setAttitude(osg::Quat(-osg::PI_2,osg::Vec3(1,-1,0)));
- matrixbait1->setPosition(osg::Vec3(y, y, z1 ));
- y+=1.568;
- z1-=0.1;
- if(z1<=1180)
- z1=1180;
- matrixbait1->setScale(osg::Vec3(s,s,s));
- s+=0.01;
- if(s>=3)
- s=3;
- }
- }
- traverse(node, nv);
- }
- private:
- float s;
- float _angle;
- float z1;
- };
复制代码
这是头文件里的内容,在头文件的开始定义了bool ZhuYuiTuoLi_lable;然后再主更新回调(class FaSheDanCallback:public osg::NodeCallback
)里进行赋值,在其他函数中无法读取赋值后的ZhuYuiTuoLi_lable值,在主函数中也无法读取赋值后的ZhuYuiTuoLi_lable值,情况就是这样的!不知道这样表达是否清楚! |
|