本文整理汇总了C++中ParticleSystemCoreRefPtr类的典型用法代码示例。如果您正苦于以下问题:C++ ParticleSystemCoreRefPtr类的具体用法?C++ ParticleSystemCoreRefPtr怎么用?C++ ParticleSystemCoreRefPtr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ParticleSystemCoreRefPtr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
// Set up Window
TutorialWindow = createNativeWindow();
TutorialWindow->initWindow();
TutorialWindow->setDisplayCallback(display);
TutorialWindow->setReshapeCallback(reshape);
TutorialKeyListener TheKeyListener;
TutorialWindow->addKeyListener(&TheKeyListener);
TutorialMouseListener TheTutorialMouseListener;
TutorialMouseMotionListener TheTutorialMouseMotionListener;
TutorialWindow->addMouseListener(&TheTutorialMouseListener);
TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener);
// Create the SimpleSceneManager helper
mgr = new SimpleSceneManager;
// Tell the Manager what to manage
mgr->setWindow(TutorialWindow);
// Material point chunk, so particles are drawn as points
PointChunkRefPtr PSPointChunk = PointChunk::create();
PSPointChunk->setSize(5.0f);
PSPointChunk->setSmooth(true);
// Material blend chunk
BlendChunkRefPtr PSBlendChunk = BlendChunk::create();
PSBlendChunk->setSrcFactor(GL_SRC_ALPHA);
PSBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);
LineChunkRefPtr PSLineChunk = LineChunk::create();
//Texture Chunk
TextureObjChunkRefPtr PSTexChunk = OSG::TextureObjChunk::create();
//Particle System Material
MaterialChunkRefPtr PSMaterialChunkChunk = MaterialChunk::create();
PSMaterialChunkChunk->setAmbient(Color4f(1.0f,0.5f,0.3f,1.0f));
PSMaterialChunkChunk->setDiffuse(Color4f(1.0f,0.5f,0.3f,0.6f));
PSMaterialChunkChunk->setSpecular(Color4f(1.0f,0.5f,0.3f,0.6f));
PSMaterialChunkChunk->setColorMaterial(GL_AMBIENT_AND_DIFFUSE);
// Assembling materials
ChunkMaterialRefPtr PSMaterial = ChunkMaterial::create();
PSMaterial->addChunk(PSMaterialChunkChunk);
PSMaterial->addChunk(PSPointChunk);
PSMaterial->addChunk(PSBlendChunk);
PSMaterial->addChunk(PSLineChunk);
PSMaterial->addChunk(PSTexChunk);
PSMaterial->setTransparencyMode(Material::TransparencyForceTransparent);
// Creating a particle generator
RateParticleGeneratorRefPtr ExampleGenerator = OSG::RateParticleGenerator::create();
//Attach the function objects to the Generator
ExampleGenerator->setPositionDistribution(createPositionDistribution());
ExampleGenerator->setGenerationRate(8.0);
ExampleGenerator->setVelocityDistribution(createVelocityDistribution());
ExampleGenerator->setLifespanDistribution(createLifespanDistribution());
ExampleGenerator->setSizeDistribution(createSizeDistribution());
//Creating Particle System
ExampleParticleSystem = OSG::ParticleSystem::create();
// add a couple temp particles so the camera is zoomed out
ExampleParticleSystem->addParticle(OSG::Pnt3f(0,0,-100),OSG::Vec3f(0,1,0),OSG::Color4f(1,1,1,1),OSG::Vec3f(1,1,1),0.1,OSG::Vec3f(0,0,0),OSG::Vec3f(0,0,0));
ExampleParticleSystem->addParticle(OSG::Pnt3f(0,0,100),OSG::Vec3f(0,1,0),OSG::Color4f(1,1,1,1),OSG::Vec3f(1,1,1),0.1,OSG::Vec3f(0,0,0),OSG::Vec3f(0,0,0));
ExampleParticleSystem->setMaxParticles(200);
ExampleParticleSystem->attachUpdateListener(TutorialWindow);
//Creating Particle System Drawer
PointParticleSystemDrawerRefPtr ExampleParticleSystemDrawer = OSG::PointParticleSystemDrawer::create();
ExampleParticleSystemDrawer->setForcePerParticleSizing(true);
// Attaching affector and generator to the particle system
ExampleParticleSystem->pushToGenerators(ExampleGenerator);
//Particle System Core, setting its system, drawer, and material
ParticleSystemCoreRefPtr ParticleNodeCore = OSG::ParticleSystemCore::create();
ParticleNodeCore->setSystem(ExampleParticleSystem);
ParticleNodeCore->setDrawer(ExampleParticleSystemDrawer);
ParticleNodeCore->setMaterial(PSMaterial);
// Create Trail Generator(s)
// simple trail generator
ExampleTrailGenerator = OSG::SimpleParticleTrailGenerator::create();
ExampleTrailGenerator->setTrailResolution(2.5f);
ExampleTrailGenerator->setDrawMethod(SimpleParticleTrailGenerator::POINTS);
ExampleTrailGenerator->setTrailLength(3.12);
ExampleTrailGenerator->setTrailLengthMethod(ParticleTrailGenerator::TIME);
ExampleTrailGenerator->setTrailResolutionMethod(ParticleTrailGenerator::DISTANCE_SPACING);
ExampleTrailGenerator->setTrailMaterial(PSMaterial);
// attach listener for trail generator to the particle system
ExampleParticleSystem->addParticleSystemListener(ExampleTrailGenerator->getParticleSystemListener());
// Set up node with the particle system at its core
//.........这里部分代码省略.........
示例2: main
//.........这里部分代码省略.........
// Creating a particle generator
RateParticleGeneratorRefPtr ExampleGenerator = RateParticleGenerator::create();
//Attach the function objects to the Generator
ExampleGenerator->setPositionDistribution(createPositionDistribution());
ExampleGenerator->setGenerationRate(3.0);
ExampleGenerator->setVelocityDistribution(createVelocityDistribution());
ExampleGenerator->setNormalDistribution(createNormalDistribution());
ExampleGenerator->setLifespanDistribution(createLifespanDistribution());
ExampleGenerator->setSizeDistribution(createSizeDistribution());
//Creating Particle System
ParticleSystemRecPtr ExampleParticleSystem = ParticleSystem::create();
ExampleParticleSystem->addParticle(Pnt3f(0,0,-100),Vec3f(0,1,0),Color4f(1,1,1,1),Vec3f(1,1,1),0.1,Vec3f(0,0,0),Vec3f(0,0,0));
ExampleParticleSystem->addParticle(Pnt3f(0,0,100),Vec3f(0,1,0),Color4f(1,1,1,1),Vec3f(1,1,1),0.1,Vec3f(0,0,0),Vec3f(0,0,0));
ExampleParticleSystem->setMaxParticles(5); // 5 rockets max to avoid collisions. they are bad.
ExampleParticleSystem->pushToAffectors(AgeFadeAffector);
ExampleParticleSystem->attachUpdateProducer(TutorialWindow);
//Creating Particle System Drawer
QuadParticleSystemDrawerRefPtr ExampleParticleSystemDrawer = QuadParticleSystemDrawer::create();
ExampleParticleSystemDrawer->setNormalAndUpSource(QuadParticleSystemDrawer::NORMAL_VIEW_DIRECTION,
QuadParticleSystemDrawer::UP_VELOCITY);
QuadParticleSystemDrawerRefPtr ExampleTrailDrawer = QuadParticleSystemDrawer::create();
ExampleTrailDrawer->setNormalAndUpSource(QuadParticleSystemDrawer::NORMAL_VIEW_DIRECTION,
QuadParticleSystemDrawer::UP_PARTICLE_NORMAL);
// Attaching affector and generator to the particle system
ExampleParticleSystem->pushToGenerators(ExampleGenerator);
//Particle System Core, setting its system, drawer, and material
ParticleSystemCoreRefPtr ParticleNodeCore = ParticleSystemCore::create();
ParticleNodeCore->setSystem(ExampleParticleSystem);
ParticleNodeCore->setDrawer(ExampleParticleSystemDrawer);
ParticleNodeCore->setMaterial(PSMaterial);
// create Particle System Particle Trail generator
ParticleSystemParticleTrailGeneratorRecPtr ExamplePSTrailGenerator = ParticleSystemParticleTrailGenerator::create();
ExamplePSTrailGenerator->setTrailResolution(0.05f);
ExamplePSTrailGenerator->setTrailLength(1.2);
ExamplePSTrailGenerator->setTrailLengthMethod(ParticleTrailGenerator::TIME);
ExamplePSTrailGenerator->setTrailResolutionMethod(ParticleTrailGenerator::TIME_SPACING);
ExamplePSTrailGenerator->setTrailMaterial(TrailMaterial);
ExamplePSTrailGenerator->setTrailDrawer(ExampleTrailDrawer);
ExamplePSTrailGenerator->setSizeDistribution(createTrailSizeDistribution());
ExamplePSTrailGenerator->setColorDistribution(createColorDistribution());
ExamplePSTrailGenerator->setNormalDistribution(createNormalDistribution());
ExamplePSTrailGenerator->setVelocityDistribution(createNormalDistribution());
// create affectors for particle trails
GravityParticleAffectorRefPtr GravAffector = GravityParticleAffector::create();
GravAffector->setBeacon(ExamplePSTrailGenerator);
AgeFadeParticleAffectorRefPtr TrailAgeFadeAffector = AgeFadeParticleAffector::create();
TrailAgeFadeAffector->setFadeInTime(0.2f);
TrailAgeFadeAffector->setStartAlpha(0.0f);
TrailAgeFadeAffector->setEndAlpha(0.0f);
TrailAgeFadeAffector->setFadeOutTime(1.0f);
TrailAgeFadeAffector->setFadeToAlpha(0.6f);
// now we attach the affector to the particle trail generator's particle system
ExamplePSTrailGenerator->getParticleSystem()->pushToAffectors(TrailAgeFadeAffector);
示例3: main
int main(int argc, char **argv)
{
preloadSharedObject("OSGImageFileIO");
// OSG init
osgInit(argc,argv);
{
// Set up Window
WindowEventProducerRecPtr TutorialWindow = createNativeWindow();
TutorialWindow->initWindow();
// Create the SimpleSceneManager helper
SimpleSceneManager sceneManager;
TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager));
TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager));
// Tell the Manager what to manage
sceneManager.setWindow(TutorialWindow);
//Attach to events
TutorialWindow->connectMousePressed(boost::bind(mousePressed, _1, &sceneManager));
TutorialWindow->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager));
TutorialWindow->connectMouseMoved(boost::bind(mouseMoved, _1, &sceneManager));
TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager));
TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager));
// Creating the Particle System Material
// Here, the image is loaded. The entire image sequence is conatined in one image,
// which reduces texture memory overhead and runs faster.
TextureObjChunkRefPtr QuadTextureChunk = TextureObjChunk::create();
ImageRefPtr LoadedImage = ImageFileHandler::the()->read("Data/SpriteExplode.png");
QuadTextureChunk->setImage(LoadedImage);
TextureEnvChunkRefPtr QuadTextureEnvChunk = TextureEnvChunk::create();
QuadTextureEnvChunk->setEnvMode(GL_MODULATE);
BlendChunkRefPtr PSBlendChunk = BlendChunk::create();
PSBlendChunk->setSrcFactor(GL_SRC_ALPHA);
PSBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);
MaterialChunkRefPtr PSMaterialChunk = MaterialChunk::create();
PSMaterialChunk->setAmbient(Color4f(0.3f,0.0f,0.0f,1.0f));
PSMaterialChunk->setDiffuse(Color4f(0.7f,0.0f,0.0f,1.0f));
PSMaterialChunk->setSpecular(Color4f(0.9f,0.0f,0.0f,1.0f));
PSMaterialChunk->setColorMaterial(GL_AMBIENT_AND_DIFFUSE);
ChunkMaterialRefPtr PSMaterial = ChunkMaterial::create();
PSMaterial->addChunk(QuadTextureChunk);
PSMaterial->addChunk(QuadTextureEnvChunk);
PSMaterial->addChunk(PSMaterialChunk);
PSMaterial->addChunk(PSBlendChunk);
//Particle System
ParticleSystemRecPtr ExampleParticleSystem = ParticleSystem::create();
ExampleParticleSystem->attachUpdateProducer(TutorialWindow);
//Age Particle Function. Controls which image is shown when, based on the age of a particle.
AgeParticleFunctionRecPtr AgeFunc = AgeParticleFunction::create();
AgeFunc->setSequenceTime(0.1f); // image changes every 0.1 seconds.
AgeFunc->setSequenceOrder(AgeParticleFunction::CUSTOM); // using the custom sequence below.
/*
Here, a custom sequence for the image ordering is assembled. The image sequence will be shown in
the order specified here. Once the end of the sequence is reached, the sequence repeats.
*/
AgeFunc->editMFCustomSequence()->push_back(0);
AgeFunc->editMFCustomSequence()->push_back(1);
AgeFunc->editMFCustomSequence()->push_back(2);
AgeFunc->editMFCustomSequence()->push_back(3);
AgeFunc->editMFCustomSequence()->push_back(4);
AgeFunc->editMFCustomSequence()->push_back(5);
AgeFunc->editMFCustomSequence()->push_back(4);
AgeFunc->editMFCustomSequence()->push_back(3);
AgeFunc->editMFCustomSequence()->push_back(2);
AgeFunc->editMFCustomSequence()->push_back(1);
//Particle System Drawer -
QuadSequenceParticleSystemDrawerRecPtr ExampleParticleSystemDrawer = QuadSequenceParticleSystemDrawer::create();
// image dimensions (in pixels) are required if there is a border on the images.
ExampleParticleSystemDrawer->setImageDimensions(Vec2us(780,520));
// The "dimensions" of the sequence contained in the image. For this image,
// there are 3 images in the "x" direction, and two in the "y" direction, for a
// total of 6.
ExampleParticleSystemDrawer->setSequenceDimensions(Vec2b(3,2));
// width of the border on each side of the image, in pixels.
ExampleParticleSystemDrawer->setBorderOffsets(Vec2b(0,0));
// this is the age function we just created above.
ExampleParticleSystemDrawer->setSequenceFunction(AgeFunc);
RateParticleGeneratorRecPtr ExampleParticleGenerator = RateParticleGenerator::create();
//Attach the function objects to the Generator
ExampleParticleGenerator->setPositionDistribution(createPositionDistribution());
ExampleParticleGenerator->setLifespanDistribution(createLifespanDistribution());
ExampleParticleGenerator->setVelocityDistribution(createVelocityDistribution());
ExampleParticleGenerator->setAccelerationDistribution(createAccelerationDistribution());
ExampleParticleGenerator->setSizeDistribution(createSizeDistribution());
ExampleParticleGenerator->setGenerationRate(40.0f);
//Particle System Node
ParticleSystemCoreRefPtr ParticleNodeCore = ParticleSystemCore::create();
ParticleNodeCore->setSystem(ExampleParticleSystem);
//.........这里部分代码省略.........
示例4: main
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
// Set up Window
TutorialWindow = createNativeWindow();
TutorialWindow->initWindow();
TutorialWindow->setDisplayCallback(display);
TutorialWindow->setReshapeCallback(reshape);
TutorialKeyListener TheKeyListener;
TutorialWindow->addKeyListener(&TheKeyListener);
TutorialMouseListener TheTutorialMouseListener;
TutorialMouseMotionListener TheTutorialMouseMotionListener;
TutorialWindow->addMouseListener(&TheTutorialMouseListener);
TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener);
// Create the SimpleSceneManager helper
mgr = new SimpleSceneManager;
// Tell the Manager what to manage
mgr->setWindow(TutorialWindow);
//Particle System Material
PointChunkRefPtr PSPointChunk = PointChunk::create();
PSPointChunk->setSize(5.0f);
PSPointChunk->setSmooth(true);
BlendChunkRefPtr PSBlendChunk = BlendChunk::create();
PSBlendChunk->setSrcFactor(GL_SRC_ALPHA);
PSBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);
MaterialChunkRefPtr PSMaterialChunkChunk = MaterialChunk::create();
PSMaterialChunkChunk->setAmbient(Color4f(1.0f,1.0f,1.0f,1.0f));
PSMaterialChunkChunk->setDiffuse(Color4f(0.7f,0.7f,0.7f,1.0f));
PSMaterialChunkChunk->setSpecular(Color4f(0.9f,0.9f,0.9f,1.0f));
PSMaterialChunkChunk->setColorMaterial(GL_NONE);
ChunkMaterialRefPtr PSMaterial = ChunkMaterial::create();
PSMaterial->addChunk(PSPointChunk);
PSMaterial->addChunk(PSMaterialChunkChunk);
PSMaterial->addChunk(PSBlendChunk);
//Particle System
ParticleSystemRefPtr ExampleParticleSystem = OSG::ParticleSystem::create();
ExampleParticleSystem->addParticle(Pnt3f(0,100,0),
Vec3f(0.0,0.0f,1.0f),
Color4f(1.0,1.0,1.0,1.0),
Vec3f(1.0,1.0,1.0),
0.1,
Vec3f(0.0f,0.0f,0.0f), //Velocity
Vec3f(0.0f,0.0f,0.0f)
);
ExampleParticleSystem->addParticle(Pnt3f(0,-100,0),
Vec3f(0.0,0.0f,1.0f),
Color4f(1.0,1.0,1.0,1.0),
Vec3f(1.0,1.0,1.0),
0.1,
Vec3f(0.0f,0.0f,0.0f), //Velocity
Vec3f(0.0f,0.0f,0.0f)
);
ExampleParticleSystem->attachUpdateListener(TutorialWindow);
//Particle System Drawer (Point)
PointParticleSystemDrawerRefPtr ExampleParticleSystemDrawer = OSG::PointParticleSystemDrawer::create();
//Create a Rate Particle Generator
RateParticleGeneratorRefPtr ExampleGenerator = OSG::RateParticleGenerator::create();
//Attach the function objects to the Generator
ExampleGenerator->setPositionDistribution(createPositionDistribution());
ExampleGenerator->setLifespanDistribution(createLifespanDistribution());
ExampleGenerator->setGenerationRate(80.0);
ExampleGenerator->setVelocityDistribution(createVelocityDistribution());
ExampleRadialAffector = OSG::RadialParticleAffector::create();
ExampleRadialAffector->setMagnitude(15.0);
NodeRefPtr RadialBeacon = OSG::Node::create();
ExampleRadialAffector->setBeacon(RadialBeacon); // set to 'emulate' from (0,0,0)
ExampleRadialAffector->setMaxDistance(-1.0); // particles affected regardless of distance
ExampleRadialAffector->setAttenuation(0.0); // strength of uniform field dimishes by dist^attenuation
//Attach the Generator and Affector to the Particle System
ExampleParticleSystem->pushToGenerators(ExampleGenerator);
ExampleParticleSystem->pushToAffectors(ExampleRadialAffector);
ExampleParticleSystem->setMaxParticles(800);
//Particle System Node
ParticleSystemCoreRefPtr ParticleNodeCore = OSG::ParticleSystemCore::create();
ParticleNodeCore->setSystem(ExampleParticleSystem);
ParticleNodeCore->setDrawer(ExampleParticleSystemDrawer);
ParticleNodeCore->setMaterial(PSMaterial);
NodeRefPtr ParticleNode = OSG::Node::create();
//.........这里部分代码省略.........
示例5: main
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
// Set up Window
TutorialWindow = createNativeWindow();
TutorialWindow->initWindow();
TutorialWindow->setDisplayCallback(display);
TutorialWindow->setReshapeCallback(reshape);
TutorialKeyListener TheKeyListener;
TutorialWindow->addKeyListener(&TheKeyListener);
TutorialMouseListener TheTutorialMouseListener;
TutorialMouseMotionListener TheTutorialMouseMotionListener;
TutorialWindow->addMouseListener(&TheTutorialMouseListener);
TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener);
// Create the SimpleSceneManager helper
mgr = new SimpleSceneManager;
// Tell the Manager what to manage
mgr->setWindow(TutorialWindow);
//Particle System Material
TextureObjChunkRefPtr QuadTextureObjChunk = TextureObjChunk::create();
ImageRefPtr LoadedImage = ImageFileHandler::the()->read("Data/Cloud.png");
QuadTextureObjChunk->setImage(LoadedImage);
TextureEnvChunkRefPtr QuadTextureEnvChunk = TextureEnvChunk::create();
QuadTextureEnvChunk->setEnvMode(GL_MODULATE);
BlendChunkRefPtr PSBlendChunk = BlendChunk::create();
PSBlendChunk->setSrcFactor(GL_SRC_ALPHA);
PSBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);
MaterialChunkRefPtr PSMaterialChunk = MaterialChunk::create();
PSMaterialChunk->setAmbient(Color4f(0.3f,0.3f,0.3f,1.0f));
PSMaterialChunk->setDiffuse(Color4f(0.7f,0.7f,0.7f,1.0f));
PSMaterialChunk->setSpecular(Color4f(0.9f,0.9f,0.9f,1.0f));
PSMaterialChunk->setColorMaterial(GL_AMBIENT_AND_DIFFUSE);
ChunkMaterialRefPtr PSMaterial = ChunkMaterial::create();
PSMaterial->addChunk(QuadTextureObjChunk);
PSMaterial->addChunk(QuadTextureEnvChunk);
PSMaterial->addChunk(PSMaterialChunk);
PSMaterial->addChunk(PSBlendChunk);
//Affector
ExampleAgeSizeParticleAffector = OSG::AgeSizeParticleAffector::create();
//ages
ExampleAgeSizeParticleAffector->editMFAges()->push_back(0.0);
ExampleAgeSizeParticleAffector->editMFAges()->push_back(0.05);
ExampleAgeSizeParticleAffector->editMFAges()->push_back(0.2);
ExampleAgeSizeParticleAffector->editMFAges()->push_back(0.36);
ExampleAgeSizeParticleAffector->editMFAges()->push_back(0.7);
ExampleAgeSizeParticleAffector->editMFAges()->push_back(0.8);
ExampleAgeSizeParticleAffector->editMFAges()->push_back(1.0);
//sizes
ExampleAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(1.0,0.5,1.0));
ExampleAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(1.0,0.5,1.0));
ExampleAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(20.0,0.5,30.0));
ExampleAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(3.0,3.0,3.0));
ExampleAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(6.0,60.0,6.0));
ExampleAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(2.0,3.0,1.0));
ExampleAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(10.0,1.0,10.0));
//Particle System
ExampleParticleSystem = OSG::ParticleSystem::create();
ExampleParticleSystem->attachUpdateListener(TutorialWindow);
ExampleParticleSystem->pushToAffectors(ExampleAgeSizeParticleAffector);
//Particle System Drawer
ExampleParticleSystemDrawer = OSG::QuadParticleSystemDrawer::create();
ExampleBurstGenerator = OSG::BurstParticleGenerator::create();
//Attach the function objects to the Generator
ExampleBurstGenerator->setPositionDistribution(createPositionDistribution());
ExampleBurstGenerator->setLifespanDistribution(createLifespanDistribution());
ExampleBurstGenerator->setBurstAmount(10.0);
ExampleBurstGenerator->setVelocityDistribution(createVelocityDistribution());
//ExampleBurstGenerator->setAccelerationDistribution(createAccelerationDistribution());
ExampleBurstGenerator->setSizeDistribution(createSizeDistribution());
//Particle System Node
ParticleSystemCoreRefPtr ParticleNodeCore = OSG::ParticleSystemCore::create();
ParticleNodeCore->setSystem(ExampleParticleSystem);
ParticleNodeCore->setDrawer(ExampleParticleSystemDrawer);
ParticleNodeCore->setMaterial(PSMaterial);
NodeRefPtr ParticleNode = OSG::Node::create();
ParticleNode->setCore(ParticleNodeCore);
//Ground Node
NodeRefPtr GoundNode = makePlane(30.0,30.0,10,10);
//.........这里部分代码省略.........
示例6: main
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
// Set up Window
TutorialWindow = createNativeWindow();
TutorialWindow->initWindow();
TutorialWindow->setDisplayCallback(display);
TutorialWindow->setReshapeCallback(reshape);
TutorialKeyListener TheKeyListener;
TutorialWindow->addKeyListener(&TheKeyListener);
TutorialMouseListener TheTutorialMouseListener;
TutorialMouseMotionListener TheTutorialMouseMotionListener;
TutorialWindow->addMouseListener(&TheTutorialMouseListener);
TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener);
// Create the SimpleSceneManager helper
mgr = new SimpleSceneManager;
// Tell the Manager what to manage
mgr->setWindow(TutorialWindow);
//Particle System
ParticleSystemRefPtr ExampleParticleSystem = OSG::ParticleSystem::create();
ExampleParticleSystem->attachUpdateListener(TutorialWindow);
PointParticleSystemDrawerRefPtr ExamplePointParticleSystemDrawer = OSG::PointParticleSystemDrawer::create();
//NodeRefPtr ParticlePrototypeNode = makeTorus(1.0,4.0,16,16);
//NodeRefPtr CollisionNode = makeBox(5.0,5.0,5.0,1,1,1);//makeSphere(4,10.0f);
NodeRefPtr CollisionNode = makeSphere(2,4.0f);
//Particle System Material
PointChunkRefPtr PSPointChunk = PointChunk::create();
PSPointChunk->setSize(5.0f);
PSPointChunk->setSmooth(true);
BlendChunkRefPtr PSBlendChunk = BlendChunk::create();
PSBlendChunk->setSrcFactor(GL_SRC_ALPHA);
PSBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);
MaterialChunkRefPtr PSMaterialChunkChunk = MaterialChunk::create();
PSMaterialChunkChunk->setAmbient(Color4f(1.0f,0.0f,0.0f,1.0f));
PSMaterialChunkChunk->setDiffuse(Color4f(1.0f,0.0f,0.0f,1.0f));
PSMaterialChunkChunk->setSpecular(Color4f(1.0f,0.0f,0.0f,1.0f));
PSMaterialChunkChunk->setColorMaterial(GL_NONE);
//PSMaterialChunkChunk->setLit(false);
ChunkMaterialRefPtr PSMaterial = ChunkMaterial::create();
PSMaterial->addChunk(PSPointChunk);
PSMaterial->addChunk(PSMaterialChunkChunk);
PSMaterial->addChunk(PSBlendChunk);
ParticleSystemCoreRefPtr ParticleNodeCore = OSG::ParticleSystemCore::create();
ParticleNodeCore->setSystem(ExampleParticleSystem);
ParticleNodeCore->setDrawer(ExamplePointParticleSystemDrawer);
ParticleNodeCore->setMaterial(PSMaterial);
NodeRefPtr ParticleNode = OSG::Node::create();
ParticleNode->setCore(ParticleNodeCore);
//Generator
//Attach the function objects to the Generator
RateParticleGeneratorRefPtr ExampleGenerator= RateParticleGenerator::create();
ExampleGenerator->setPositionDistribution(createPositionDistribution());
ExampleGenerator->setLifespanDistribution(createLifespanDistribution());
ExampleGenerator->setGenerationRate(20.0);
ExampleGenerator->setVelocityDistribution(createVelocityDistribution());
//Geometry Collision Affector
GeometryCollisionParticleSystemAffectorRefPtr ExampleGeometryCollisionParticleSystemAffector = GeometryCollisionParticleSystemAffector::create();
ExampleGeometryCollisionParticleSystemAffector->setCollisionNode(CollisionNode);
TutorialParticleCollisionListener TheCollisionListener;
ExampleGeometryCollisionParticleSystemAffector->addParticleGeometryCollisionListener(&TheCollisionListener);
ExampleParticleSystem->pushToSystemAffectors(ExampleGeometryCollisionParticleSystemAffector);
ExampleParticleSystem->pushToGenerators(ExampleGenerator);
// Make Main Scene Node and add the Torus
NodeRefPtr scene = OSG::Node::create();
scene->setCore(OSG::Group::create());
scene->addChild(ParticleNode);
scene->addChild(CollisionNode);
mgr->setRoot(scene);
// Show the whole Scene
mgr->showAll();
//Open Window
Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
TutorialWindow->openWindow(WinPos,
WinSize,
"13CollisionGeometry");
//.........这里部分代码省略.........
示例7: main
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
{
// Set up Window
WindowEventProducerRecPtr TutorialWindow = createNativeWindow();
TutorialWindow->initWindow();
// Create the SimpleSceneManager helper
SimpleSceneManager sceneManager;
TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager));
TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager));
// Tell the Manager what to manage
sceneManager.setWindow(TutorialWindow);
//Attach to events
TutorialWindow->connectMousePressed(boost::bind(mousePressed, _1, &sceneManager));
TutorialWindow->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager));
TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager));
TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager));
//Particle System Material
TextureObjChunkRefPtr QuadTextureChunk = TextureObjChunk::create();
ImageRefPtr LoadedImage = ImageFileHandler::the()->read("Data/Cloud.png");
QuadTextureChunk->setImage(LoadedImage);
TextureEnvChunkRefPtr QuadTextureEnvChunk = TextureEnvChunk::create();
QuadTextureEnvChunk->setEnvMode(GL_MODULATE);
BlendChunkRefPtr PSBlendChunk = BlendChunk::create();
PSBlendChunk->setSrcFactor(GL_SRC_ALPHA);
PSBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);
MaterialChunkRefPtr PSMaterialChunk = MaterialChunk::create();
PSMaterialChunk->setAmbient(Color4f(0.3f,0.3f,0.3f,1.0f));
PSMaterialChunk->setDiffuse(Color4f(0.7f,0.7f,0.7f,1.0f));
PSMaterialChunk->setSpecular(Color4f(0.9f,0.9f,0.9f,1.0f));
PSMaterialChunk->setColorMaterial(GL_AMBIENT_AND_DIFFUSE);
ChunkMaterialRefPtr PSMaterial = ChunkMaterial::create();
PSMaterial->addChunk(QuadTextureChunk);
PSMaterial->addChunk(QuadTextureEnvChunk);
PSMaterial->addChunk(PSMaterialChunk);
PSMaterial->addChunk(PSBlendChunk);
//Particle System
ParticleSystemRecPtr ExampleParticleSystem = ParticleSystem::create();
ExampleParticleSystem->attachUpdateProducer(TutorialWindow);
//Particle System Drawer
QuadParticleSystemDrawerRefPtr ExampleParticleSystemDrawer = QuadParticleSystemDrawer::create();
BurstParticleGeneratorRecPtr ExampleBurstGenerator = BurstParticleGenerator::create();
//Attach the function objects to the Generator
ExampleBurstGenerator->setPositionDistribution(createPositionDistribution());
ExampleBurstGenerator->setLifespanDistribution(createLifespanDistribution());
ExampleBurstGenerator->setBurstAmount(50.0);
ExampleBurstGenerator->setVelocityDistribution(createVelocityDistribution());
ExampleBurstGenerator->setAccelerationDistribution(createAccelerationDistribution());
ExampleBurstGenerator->setSizeDistribution(createSizeDistribution());
//Particle System Node
ParticleSystemCoreRefPtr ParticleNodeCore = ParticleSystemCore::create();
ParticleNodeCore->setSystem(ExampleParticleSystem);
ParticleNodeCore->setDrawer(ExampleParticleSystemDrawer);
ParticleNodeCore->setMaterial(PSMaterial);
NodeRefPtr ParticleNode = Node::create();
ParticleNode->setCore(ParticleNodeCore);
//Ground Node
NodeRefPtr GoundNode = makePlane(30.0,30.0,10,10);
Matrix GroundTransformation;
GroundTransformation.setRotate(Quaternion(Vec3f(1.0f,0.0,0.0), -3.14195f));
TransformRefPtr GroundTransformCore = Transform::create();
GroundTransformCore->setMatrix(GroundTransformation);
NodeRefPtr GroundTransformNode = Node::create();
GroundTransformNode->setCore(GroundTransformCore);
GroundTransformNode->addChild(GoundNode);
// Make Main Scene Node and add the Torus
NodeRefPtr scene = Node::create();
scene->setCore(Group::create());
scene->addChild(ParticleNode);
scene->addChild(GroundTransformNode);
TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1,
&sceneManager,
//.........这里部分代码省略.........
示例8: main
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
// Set up Window
TutorialWindow = createNativeWindow();
TutorialWindow->initWindow();
TutorialWindow->setDisplayCallback(display);
TutorialWindow->setReshapeCallback(reshape);
TutorialKeyListener TheKeyListener;
TutorialWindow->addKeyListener(&TheKeyListener);
TutorialMouseListener TheTutorialMouseListener;
TutorialMouseMotionListener TheTutorialMouseMotionListener;
TutorialWindow->addMouseListener(&TheTutorialMouseListener);
TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener);
// Create the SimpleSceneManager helper
mgr = new SimpleSceneManager;
// Tell the Manager what to manage
mgr->setWindow(TutorialWindow);
//Particle System Material
LineChunkRefPtr PSLineChunk = LineChunk::create();
PSLineChunk->setWidth(2.0f);
PSLineChunk->setSmooth(true);
BlendChunkRefPtr PSBlendChunk = BlendChunk::create();
PSBlendChunk->setSrcFactor(GL_SRC_ALPHA);
PSBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);
MaterialChunkRefPtr PSMaterialChunkChunk = MaterialChunk::create();
PSMaterialChunkChunk->setAmbient(Color4f(0.3f,0.3f,0.3f,0.5f));
PSMaterialChunkChunk->setDiffuse(Color4f(0.7f,0.7f,0.7f,0.5f));
PSMaterialChunkChunk->setSpecular(Color4f(0.9f,0.9f,0.9f,1.0f));
PSMaterialChunkChunk->setColorMaterial(GL_AMBIENT_AND_DIFFUSE);
ChunkMaterialRefPtr PSMaterial = ChunkMaterial::create();
PSMaterial->addChunk(PSLineChunk);
PSMaterial->addChunk(PSMaterialChunkChunk);
PSMaterial->addChunk(PSBlendChunk);
//Particle System
ParticleSystemRefPtr ExampleParticleSystem = OSG::ParticleSystem::create();
ExampleParticleSystem->addParticle(Pnt3f(-400,-400,0),
Vec3f(0.0,0.0f,1.0f),
Color4f(1.0,1.0,1.0,1.0),
Vec3f(1.0,1.0,1.0),
0.25,
Vec3f(0.0f,0.0f,0.0f), //Velocity
Vec3f(0.0f,0.0f,0.0f)
);
ExampleParticleSystem->addParticle(Pnt3f(400,400,0),
Vec3f(0.0,0.0f,1.0f),
Color4f(1.0,1.0,1.0,1.0),
Vec3f(1.0,1.0,1.0),
0.25,
Vec3f(0.0f,0.0f,0.0f), //Velocity
Vec3f(0.0f,0.0f,0.0f)
);
ExampleParticleSystem->attachUpdateListener(TutorialWindow);
//Particle System Drawer (Line)
LineParticleSystemDrawerRefPtr ExampleParticleSystemDrawer = OSG::LineParticleSystemDrawer::create();
ExampleParticleSystemDrawer->setLineDirectionSource(LineParticleSystemDrawer::DIRECTION_VELOCITY);
ExampleParticleSystemDrawer->setLineLengthSource(LineParticleSystemDrawer::LENGTH_SPEED);
ExampleParticleSystemDrawer->setLineLengthScaling(0.001);
ExampleParticleSystemDrawer->setEndPointFading(Vec2f(0.0f,1.0f));
//Create a Rate Particle Generator
RateParticleGeneratorRefPtr ExampleGenerator = OSG::RateParticleGenerator::create();
//Attach the function objects to the Generator
ExampleGenerator->setPositionDistribution(createPositionDistribution());
ExampleGenerator->setLifespanDistribution(createLifespanDistribution());
ExampleGenerator->setGenerationRate(300.0);
ExampleGenerator->setVelocityDistribution(createVelocityDistribution());
//Attach the Generator to the Particle System
ExampleParticleSystem->pushToGenerators(ExampleGenerator);
//Particle System Node
ParticleSystemCoreRefPtr ParticleNodeCore = OSG::ParticleSystemCore::create();
ParticleNodeCore->setSystem(ExampleParticleSystem);
ParticleNodeCore->setDrawer(ExampleParticleSystemDrawer);
ParticleNodeCore->setMaterial(PSMaterial);
NodeRefPtr ParticleNode = OSG::Node::create();
ParticleNode->setCore(ParticleNodeCore);
// Make Main Scene Node and add the Torus
NodeRefPtr scene = OSG::Node::create();
scene->setCore(OSG::Group::create());
scene->addChild(ParticleNode);
//.........这里部分代码省略.........
示例9: main
int main(int argc, char **argv)
{
preloadSharedObject("OSGImageFileIO");
// OSG init
osgInit(argc,argv);
{
// Set up Window
WindowEventProducerRecPtr TutorialWindow = createNativeWindow();
TutorialWindow->initWindow();
// Create the SimpleSceneManager helper
SimpleSceneManager sceneManager;
TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager));
TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager));
// Tell the Manager what to manage
sceneManager.setWindow(TutorialWindow);
//Attach to events
TutorialWindow->connectMousePressed(boost::bind(mousePressed, _1, &sceneManager));
TutorialWindow->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager));
TutorialWindow->connectMouseMoved(boost::bind(mouseMoved, _1, &sceneManager));
TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager));
TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager));
// Creating the Particle System Material
// Here, the image is loaded. The entire image sequence is conatined in one image,
// which reduces texture memory overhead and runs faster.
TextureObjChunkRefPtr QuadTextureChunk = TextureObjChunk::create();
ImageRefPtr LoadedImage = ImageFileHandler::the()->read("Data/Explosion.png");
QuadTextureChunk->setImage(LoadedImage);
TextureEnvChunkRefPtr QuadTextureEnvChunk = TextureEnvChunk::create();
QuadTextureEnvChunk->setEnvMode(GL_MODULATE);
BlendChunkRefPtr PSBlendChunk = BlendChunk::create();
PSBlendChunk->setSrcFactor(GL_SRC_ALPHA);
PSBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);
MaterialChunkRefPtr PSMaterialChunk = MaterialChunk::create();
PSMaterialChunk->setLit(false);
ChunkMaterialRefPtr PSMaterial = ChunkMaterial::create();
PSMaterial->addChunk(QuadTextureChunk);
PSMaterial->addChunk(QuadTextureEnvChunk);
PSMaterial->addChunk(PSMaterialChunk);
PSMaterial->addChunk(PSBlendChunk);
//Particle System
ParticleSystemRecPtr ExplosionParticleSystem = ParticleSystem::create();
ExplosionParticleSystem->attachUpdateProducer(TutorialWindow);
//Age Particle Function. Controls which image is shown when, based on the age of a particle.
AgeParticleFunctionRecPtr AgeFunc = AgeParticleFunction::create();
AgeFunc->setSequenceTime(0.07f); // image changes every 0.1 seconds.
AgeFunc->setSequenceOrder(AgeParticleFunction::CUSTOM); // using the custom sequence below.
/*
Here, a custom sequence for the image ordering is assembled. The image sequence will be shown in
the order specified here. Once the end of the sequence is reached, the sequence repeats.
*/
UInt32 NumImages(25);
for(UInt32 i(0) ; i<NumImages ; ++i)
{
AgeFunc->editMFCustomSequence()->push_back(i);
}
//Particle System Drawer -
QuadSequenceParticleSystemDrawerRecPtr ExplosionParticleSystemDrawer = QuadSequenceParticleSystemDrawer::create();
// image dimensions (in pixels) are required if there is a border on the images.
ExplosionParticleSystemDrawer->setImageDimensions(Vec2us(320,320));
// The "dimensions" of the sequence contained in the image. For this image,
// there are 3 images in the "x" direction, and two in the "y" direction, for a
// total of 6.
ExplosionParticleSystemDrawer->setSequenceDimensions(Vec2b(5,5));
// width of the border on each side of the image, in pixels.
ExplosionParticleSystemDrawer->setBorderOffsets(Vec2b(0,0));
// this is the age function we just created above.
ExplosionParticleSystemDrawer->setSequenceFunction(AgeFunc);
RateParticleGeneratorRecPtr ExplosionParticleGenerator = RateParticleGenerator::create();
//Attach the function objects to the Generator
ExplosionParticleGenerator->setPositionDistribution(createPositionDistribution());
ExplosionParticleGenerator->setLifespanDistribution(createLifespanDistribution());
ExplosionParticleGenerator->setVelocityDistribution(createVelocityDistribution());
ExplosionParticleGenerator->setAccelerationDistribution(createAccelerationDistribution());
ExplosionParticleGenerator->setSizeDistribution(createSizeDistribution());
ExplosionParticleGenerator->setGenerationRate(100.0f);
//Particle System Node
ParticleSystemCoreRefPtr ExplosionParticleCore = ParticleSystemCore::create();
ExplosionParticleCore->setSystem(ExplosionParticleSystem);
ExplosionParticleCore->setDrawer(ExplosionParticleSystemDrawer);
ExplosionParticleCore->setMaterial(PSMaterial);
ExplosionParticleCore->setSortingMode(ParticleSystemCore::BACK_TO_FRONT);
NodeRefPtr ExplosionParticleNode = Node::create();
ExplosionParticleNode->setCore(ExplosionParticleCore);
ExplosionParticleSystem->addParticle(Pnt3f(10.0,0.0,0.0),
//.........这里部分代码省略.........
示例10: main
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
// Set up Window
TutorialWindow = createNativeWindow();
TutorialWindow->initWindow();
TutorialWindow->setDisplayCallback(display);
TutorialWindow->setReshapeCallback(reshape);
TutorialKeyListener TheKeyListener;
TutorialWindow->addKeyListener(&TheKeyListener);
TutorialMouseListener TheTutorialMouseListener;
TutorialMouseMotionListener TheTutorialMouseMotionListener;
TutorialWindow->addMouseListener(&TheTutorialMouseListener);
TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener);
// Create the SimpleSceneManager helper
mgr = new SimpleSceneManager;
// Tell the Manager what to manage
mgr->setWindow(TutorialWindow);
//Particle System Material
PointChunkRefPtr PSPointChunk = PointChunk::create();
PSPointChunk->setSize(12.0f);
PSPointChunk->setSmooth(true);
BlendChunkRefPtr PSBlendChunk = BlendChunk::create();
PSBlendChunk->setSrcFactor(GL_SRC_ALPHA);
PSBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);
MaterialChunkRefPtr PSMaterialChunkChunk = MaterialChunk::create();
PSMaterialChunkChunk->setAmbient(Color4f(0.3f,0.3f,0.3f,1.0f));
PSMaterialChunkChunk->setDiffuse(Color4f(0.7f,0.7f,0.7f,1.0f));
PSMaterialChunkChunk->setSpecular(Color4f(0.9f,0.9f,0.9f,1.0f));
PSMaterialChunkChunk->setColorMaterial(GL_AMBIENT_AND_DIFFUSE);
ChunkMaterialRefPtr PSMaterial = ChunkMaterial::create();
PSMaterial->addChunk(PSPointChunk);
PSMaterial->addChunk(PSMaterialChunkChunk);
PSMaterial->addChunk(PSBlendChunk);
//Particle System
ExampleParticleSystem = OSG::ParticleSystem::create();
ExampleParticleSystem->attachUpdateListener(TutorialWindow);
//Particle System Drawer
PointParticleSystemDrawerRefPtr ExampleParticleSystemDrawer = OSG::PointParticleSystemDrawer::create();
ExampleBurstGenerator = OSG::BurstParticleGenerator::create();
//Attach the function objects to the Generator
ExampleBurstGenerator->setPositionDistribution(createPositionDistribution());
ExampleBurstGenerator->setLifespanDistribution(createLifespanDistribution());
ExampleBurstGenerator->setBurstAmount(50.0);
ExampleBurstGenerator->setVelocityDistribution(createVelocityDistribution());
ExampleBurstGenerator->setAccelerationDistribution(createAccelerationDistribution());
//Particle System Node
ParticleSystemCoreRefPtr ParticleNodeCore = OSG::ParticleSystemCore::create();
ParticleNodeCore->setSystem(ExampleParticleSystem);
ParticleNodeCore->setDrawer(ExampleParticleSystemDrawer);
ParticleNodeCore->setMaterial(PSMaterial);
NodeRefPtr ParticleNode = OSG::Node::create();
ParticleNode->setCore(ParticleNodeCore);
// Make Main Scene Node and add the Torus
NodeRefPtr scene = OSG::Node::create();
scene->setCore(OSG::Group::create());
scene->addChild(ParticleNode);
mgr->setRoot(scene);
// Show the whole Scene
mgr->showAll();
//Open Window
Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
TutorialWindow->openWindow(WinPos,
WinSize,
"04BurstParticleGenerator");
//Enter main Loop
TutorialWindow->mainLoop();
osgExit();
return 0;
}
示例11: main
//.........这里部分代码省略.........
UInt32 NumParticlesToGenerate(2500);
Distribution3DRefPtr PositionDistribution = createPositionDistribution();
Distribution3DRefPtr NormalDistribution = createNormalDistribution();
Distribution3DRefPtr ColorDistribution = createColorDistribution();
Distribution3DRefPtr SizeDistribution = createSizeDistribution();
Distribution1DRefPtr LifespanDistribution = createLifespanDistribution();
Distribution3DRefPtr VelocityDistribution = createVelocityDistribution();
Distribution3DRefPtr AccelerationDistribution = createAccelerationDistribution();
Pnt3f PositionReturnValue;
Vec3f NormalReturnValue = Vec3f(0.0,0.0f,1.0f);
Color4f ColorReturnValue = Color4f(1.0,1.0f,1.0f, 1.0f);
Vec3f SizeReturnValue;
Time LifespanReturnValue = -1;
Vec3f VelocityReturnValue;
Vec3f AccelerationReturnValue;
for(UInt32 i(0) ; i< NumParticlesToGenerate ; ++i)
{
if(PositionDistribution != NULL)
{
PositionReturnValue.setValue(PositionDistribution->generate().getValues());
}
if(ColorDistribution != NULL)
{
Vec3f ColorRGB = ColorDistribution->generate();
ColorReturnValue.setValuesRGBA(ColorRGB[0],ColorRGB[1],ColorRGB[2],1.0f);
}
if(SizeDistribution != NULL)
{
SizeReturnValue = SizeDistribution->generate();
}
if(LifespanDistribution != NULL)
{
LifespanReturnValue = LifespanDistribution->generate();
}
if(VelocityDistribution != NULL)
{
VelocityReturnValue = VelocityDistribution->generate();
}
ExampleParticleSystem->addParticle(PositionReturnValue,
NormalReturnValue,
ColorReturnValue,
SizeReturnValue,
LifespanReturnValue,
VelocityReturnValue,
AccelerationReturnValue
);
}
//Particle System Drawer
LineParticleSystemDrawerRefPtr ExampleParticleSystemDrawer = LineParticleSystemDrawer::create();
ExampleParticleSystemDrawer->setLineDirectionSource(LineParticleSystemDrawer::DIRECTION_VELOCITY);
ExampleParticleSystemDrawer->setLineLengthSource(LineParticleSystemDrawer::LENGTH_SIZE_X);
ExampleParticleSystemDrawer->setEndPointFading(Vec2f(0.0f,1.0f));
//Particle System Node
ParticleSystemCoreRefPtr ParticleNodeCore = ParticleSystemCore::create();
ParticleNodeCore->setSystem(ExampleParticleSystem);
ParticleNodeCore->setDrawer(ExampleParticleSystemDrawer);
ParticleNodeCore->setMaterial(PSMaterial);
NodeRefPtr ParticleNode = Node::create();
ParticleNode->setCore(ParticleNodeCore);
// Make Main Scene Node and add the Torus
NodeRefPtr scene = Node::create();
scene->setCore(Group::create());
scene->addChild(ParticleNode);
mgr->setRoot(scene);
// Show the whole Scene
mgr->showAll();
//Open Window
Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
TutorialWindow->openWindow(WinPos,
WinSize,
"02DynamicDistribution");
//Enter main Loop
TutorialWindow->mainLoop();
osgExit();
return 0;
}
示例12: main
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
{
// Set up Window
WindowEventProducerRecPtr TutorialWindow = createNativeWindow();
TutorialWindow->initWindow();
// Create the SimpleSceneManager helper
SimpleSceneManager sceneManager;
TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager));
TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager));
// Tell the Manager what to manage
sceneManager.setWindow(TutorialWindow);
//Attach to events
TutorialWindow->connectMousePressed(boost::bind(mousePressed, _1, &sceneManager));
TutorialWindow->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager));
TutorialWindow->connectMouseMoved(boost::bind(mouseMoved, _1, &sceneManager));
TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager));
TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager));
//Particle System Material
MaterialChunkRefPtr PSMaterialChunkChunk = MaterialChunk::create();
PSMaterialChunkChunk->setAmbient(Color4f(0.3f,0.3f,0.3f,1.0f));
PSMaterialChunkChunk->setDiffuse(Color4f(0.7f,0.7f,0.7f,1.0f));
PSMaterialChunkChunk->setSpecular(Color4f(0.9f,0.9f,0.9f,1.0f));
PSMaterialChunkChunk->setColorMaterial(GL_AMBIENT_AND_DIFFUSE);
ChunkMaterialRefPtr PSMaterial = ChunkMaterial::create();
PSMaterial->addChunk(PSMaterialChunkChunk);
Distribution3DRefPtr PositionDistribution = createPositionDistribution();
Pnt3f PositionReturnValue;
//Particle System
ParticleSystemRecPtr ExampleParticleSystem = ParticleSystem::create();
for(UInt32 i(0) ; i<500 ; ++i)//controls how many particles are created
{
if(PositionDistribution != NULL)
{
PositionReturnValue = Pnt3f(PositionDistribution->generate());
}
ExampleParticleSystem->addParticle(
PositionReturnValue,
PositionReturnValue,
Vec3f(0.0f,0.0f,1.0f),
Color4f(1.0,0.0,0.0,1.0),
Vec3f(1.0,1.0,1.0),
-1, 0,
Vec3f(0.0,0.0,0.0), Vec3f(0.0f,0.0f,0.0f), //Velocity
Vec3f(0.0f,0.0f,0.0f), //acceleration
StringToUInt32Map() );
}
ExampleParticleSystem->attachUpdateProducer(TutorialWindow);
RandomMovementParticleAffectorRecPtr ExampleRMA = RandomMovementParticleAffector::create();
ExampleRMA->setAmplitude(100.0f);
AttributeAttractRepelParticleAffectorRecPtr ExampleAttributeAttractRepelParticleAffector = AttributeAttractRepelParticleAffector::create();
ExampleAttributeAttractRepelParticleAffector->setAttributeAffected(RandomMovementParticleAffector::POSITION_ATTRIBUTE);
ExampleAttributeAttractRepelParticleAffector->setMinDistance(0.0);
ExampleAttributeAttractRepelParticleAffector->setMaxDistance(10000000000000.0);
ExampleAttributeAttractRepelParticleAffector->setQuadratic(0.01);
ExampleAttributeAttractRepelParticleAffector->setLinear(0.01);
ExampleAttributeAttractRepelParticleAffector->setConstant(0.0);
ExampleParticleSystem->pushToAffectors(ExampleRMA);
ExampleParticleSystem->pushToAffectors(ExampleAttributeAttractRepelParticleAffector);
ExampleParticleSystem->setUpdateSecAttribs(false);
//Particle System Drawer
QuadParticleSystemDrawerRefPtr ExampleParticleSystemDrawer = QuadParticleSystemDrawer::create();
//Particle System Node
ParticleSystemCoreRefPtr ParticleNodeCore = ParticleSystemCore::create();
ParticleNodeCore->setSystem(ExampleParticleSystem);
ParticleNodeCore->setDrawer(ExampleParticleSystemDrawer);
ParticleNodeCore->setMaterial(PSMaterial);
NodeRefPtr ParticleNode = Node::create();
ParticleNode->setCore(ParticleNodeCore);
// Make Main Scene Node
NodeRefPtr scene = Node::create();
scene->setCore(Group::create());
scene->addChild(ParticleNode);
TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1,
&sceneManager,
ExampleParticleSystem.get(),
//.........这里部分代码省略.........
示例13: keyPressed
virtual void keyPressed(const KeyEventUnrecPtr e)
{
if(e->getKey()== KeyEvent::KEY_1) // Use the Point Drawer
{
ParticleNodeCore->setDrawer(ExamplePointParticleSystemDrawer);
}
if(e->getKey()== KeyEvent::KEY_2)//Use the Line Drawer for 2
{
ParticleNodeCore->setDrawer(ExampleLineParticleSystemDrawer);
}
if(e->getKey()== KeyEvent::KEY_3)// increase velocity conservation
{
ExampleConserveVelocityAffector->setConserve(osgMax(0.0f,ExampleConserveVelocityAffector->getConserve() - 0.03f));
}
if(e->getKey()== KeyEvent::KEY_4) // decrease velocity conservation
{
ExampleConserveVelocityAffector->setConserve(osgMin(1.0f,ExampleConserveVelocityAffector->getConserve() + 0.03f));
}
if(e->getKey() == KeyEvent::KEY_Q && e->getModifiers() & KeyEvent::KEY_MODIFIER_CONTROL)
{
TutorialWindow->closeWindow();
}
}
示例14: keyPressed
virtual void keyPressed(const KeyEventUnrecPtr e)
{
if(e->getKey()== KeyEvent::KEY_1) // Use the Point Drawer
{
ParticleNodeCore->setDrawer(ExamplePointParticleSystemDrawer);
}
if(e->getKey()== KeyEvent::KEY_2)//Use the Line Drawer for 2
{
ParticleNodeCore->setDrawer(ExampleLineParticleSystemDrawer);
}
if(e->getKey()== KeyEvent::KEY_R)
{ // reverse the magnitude of the field
ExampleUniformAffector->setMagnitude(-(ExampleUniformAffector->getMagnitude()));
}
// change direction of the field
if(e->getKey()== KeyEvent::KEY_A)
{
ExampleUniformAffector->setDirection(Vec3f(-1.0,0.0,0.0));
}
if(e->getKey()== KeyEvent::KEY_W)
{
ExampleUniformAffector->setDirection(Vec3f(0.0,1.0,0.0));
}
if(e->getKey()== KeyEvent::KEY_S)
{
ExampleUniformAffector->setDirection(Vec3f(0.0,-1.0,0.0));
}
if(e->getKey()== KeyEvent::KEY_D)
{
ExampleUniformAffector->setDirection(Vec3f(1.0,0.0,0.0));
}
if(e->getKey() == KeyEvent::KEY_Q && e->getModifiers() & KeyEvent::KEY_MODIFIER_COMMAND)
{
TutorialWindow->closeWindow();
}
}
示例15: keyTyped
virtual void keyTyped(const KeyEventUnrecPtr e)
{
if(e->getKey()== KeyEvent::KEY_1) // Use the Point Drawer
{
ParticleNodeCore->setDrawer(ExamplePointParticleSystemDrawer);
}
if(e->getKey()== KeyEvent::KEY_2)//Use the Line Drawer for 2
{
ParticleNodeCore->setDrawer(ExampleLineParticleSystemDrawer);
}
if(e->getKey()== KeyEvent::KEY_3)//Use the Quad Drawer for 3
{
ParticleNodeCore->setDrawer(ExampleQuadParticleSystemDrawer);
}
if(e->getKey() == KeyEvent::KEY_F) //particles will be sorted from closest to the view point to the furthest
{
ParticleNodeCore->setSortingMode(ParticleSystemCore::FRONT_TO_BACK);
}
if(e->getKey() == KeyEvent::KEY_R) //particles will be sorted from furthest to the view point to the closest.
{
ParticleNodeCore->setSortingMode(ParticleSystemCore::BACK_TO_FRONT);
}
if(e->getKey() == KeyEvent::KEY_N) //particles will not be sorted
{
ParticleNodeCore->setSortingMode(ParticleSystemCore::NONE);
}
}