int main(int argc, char **argv) { // OSG init osgInit(argc,argv); // Set up Window TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); TutorialWindow->setDisplayCallback(display); TutorialWindow->setReshapeCallback(reshape); //Add Key Listener TutorialKeyListener TheKeyListener; TutorialWindow->addKeyListener(&TheKeyListener); //Add Mouse Listeners 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(6.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.2f,0.6f,0.5f,0.3f)); PSMaterialChunkChunk->setDiffuse(Color4f(0.2f,0.9f,0.1f,0.3f)); PSMaterialChunkChunk->setSpecular(Color4f(0.5f,0.4f,0.2f,0.6f)); PSMaterialChunkChunk->setEmission(Color4f(0.2f,0.6f,0.5f,0.3f)); PSMaterialChunkChunk->setColorMaterial(GL_NONE); //enable depth test DepthChunkRefPtr PSDepthChunk = DepthChunk::create(); ChunkMaterialRefPtr PSMaterial = ChunkMaterial::create(); PSMaterial->addChunk(PSPointChunk); PSMaterial->addChunk(PSMaterialChunkChunk); PSMaterial->addChunk(PSBlendChunk); PSMaterial->addChunk(PSDepthChunk); //Particle System ParticleSystemRefPtr ExampleParticleSystem = OSG::ParticleSystem::create(); ExampleParticleSystem->attachUpdateListener(TutorialWindow); //Particle System Drawer //Point ExamplePointParticleSystemDrawer = OSG::PointParticleSystemDrawer::create(); //ExamplePointParticleSystemDrawer->setForcePerParticleSizing(true); //Line ExampleLineParticleSystemDrawer = OSG::LineParticleSystemDrawer::create(); ExampleLineParticleSystemDrawer->setLineDirectionSource(LineParticleSystemDrawer::DIRECTION_NORMAL);//DIRECTION_VELOCITY_CHANGE); ExampleLineParticleSystemDrawer->setLineLengthSource(LineParticleSystemDrawer::LENGTH_SIZE_X); ExampleLineParticleSystemDrawer->setEndPointFading(Vec2f(1.0,0.0)); //Quad ExampleQuadParticleSystemDrawer = OSG::QuadParticleSystemDrawer::create(); ExampleQuadParticleSystemDrawer->setQuadSizeScaling(Vec2f(0.1,0.1)); ExampleQuadParticleSystemDrawer->setNormalAndUpSource(QuadParticleSystemDrawer::NORMAL_PARTICLE_NORMAL,QuadParticleSystemDrawer::UP_STATIC); RateParticleGeneratorRefPtr ExampleGeneratorTheSequel = OSG::RateParticleGenerator::create(); //Attach the function objects to the Generator ExampleGeneratorTheSequel->setPositionDistribution(createPositionDistribution()); ExampleGeneratorTheSequel->setLifespanDistribution(createLifespanDistribution()); ExampleGeneratorTheSequel->setGenerationRate(300.0); ExampleGeneratorTheSequel->setVelocityDistribution(createVelocityDistribution()); //Attach the Generator to the Particle System //ExampleParticleSystem->pushToGenerators(ExampleGenerator); ExampleParticleSystem->setMaxParticles(500); ExampleParticleSystem->pushToGenerators(ExampleGeneratorTheSequel); //Particle System Node ParticleNodeCore = OSG::ParticleSystemCore::create(); ParticleNodeCore->setSystem(ExampleParticleSystem); ParticleNodeCore->setDrawer(ExamplePointParticleSystemDrawer); 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(); mgr->getCamera()->setFar(500.0); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "14ParticleSorting"); //Enter main Loop TutorialWindow->mainLoop(); osgExit(); return 0; }
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_AMBIENT_AND_DIFFUSE); ChunkMaterialRefPtr PSMaterial = ChunkMaterial::create(); PSMaterial->addChunk(PSPointChunk); PSMaterial->addChunk(PSMaterialChunkChunk); PSMaterial->addChunk(PSBlendChunk); //Particle System ParticleSystemRefPtr ExampleParticleSystem = OSG::ParticleSystem::create(); ExampleParticleSystem->addParticle(Pnt3f(0,0,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(50,0,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) ExamplePointParticleSystemDrawer = OSG::PointParticleSystemDrawer::create(); //Particle System Drawer (line) ExampleLineParticleSystemDrawer = OSG::LineParticleSystemDrawer::create(); ExampleLineParticleSystemDrawer->setLineDirectionSource(LineParticleSystemDrawer::DIRECTION_VELOCITY); ExampleLineParticleSystemDrawer->setLineLengthSource(LineParticleSystemDrawer::LENGTH_SIZE_X); ExampleLineParticleSystemDrawer->setLineLength(0.5f); ExampleLineParticleSystemDrawer->setEndPointFading(Vec2f(1.0f,0.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->setVelocityDistribution(createVelocityDistribution()); ExampleGenerator->setGenerationRate(2.0); ExampleConserveVelocityAffector = OSG::ConserveVelocityParticleAffector::create(); ExampleConserveVelocityAffector->setConserve(0.0); // all velocity conserved initially. Use keys 3 and 4 to change this value while running. //Attach the Generator and Affector to the Particle System ExampleParticleSystem->pushToGenerators(ExampleGenerator); ExampleParticleSystem->pushToAffectors(ExampleConserveVelocityAffector); ExampleParticleSystem->setMaxParticles(500); //Particle System Node ParticleNodeCore = OSG::ParticleSystemCore::create(); ParticleNodeCore->setSystem(ExampleParticleSystem); ParticleNodeCore->setDrawer(ExamplePointParticleSystemDrawer); 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(); mgr->getCamera()->setFar(1000.0); std::cout << "Conserve Velocity Particle Affector Tutorial Controls:\n" << "1: Use point drawer\n" << "2: Use line drawer\n" << "3: Decrease velocity conserved.\n" << "4: Increase velocity conserved.\n" << "Ctrl + Q: Exit Tutorial"; //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "28ConserveVelocityParticleAffector"); //Enter main Loop TutorialWindow->mainLoop(); osgExit(); return 0; }
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 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 = ParticleSystem::create(); ExampleParticleSystem->addParticle(Pnt3f(0,25,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,-25,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->attachUpdateProducer(TutorialWindow); //Particle System Drawer (Point) PointParticleSystemDrawerRecPtr ExamplePointParticleSystemDrawer = PointParticleSystemDrawer::create(); //Particle System Drawer (line) LineParticleSystemDrawerRecPtr ExampleLineParticleSystemDrawer = LineParticleSystemDrawer::create(); ExampleLineParticleSystemDrawer->setLineDirectionSource(LineParticleSystemDrawer::DIRECTION_VELOCITY); ExampleLineParticleSystemDrawer->setLineLengthSource(LineParticleSystemDrawer::LENGTH_SIZE_X); ExampleLineParticleSystemDrawer->setLineLength(2.0f); ExampleLineParticleSystemDrawer->setEndPointFading(Vec2f(0.0f,1.0f)); //Create a Rate Particle Generator RateParticleGeneratorRefPtr ExampleGenerator = RateParticleGenerator::create(); //Attach the function objects to the Generator ExampleGenerator->setPositionDistribution(createPositionDistribution()); ExampleGenerator->setLifespanDistribution(createLifespanDistribution()); ExampleGenerator->setGenerationRate(200); UniformParticleAffectorRecPtr ExampleUniformAffector = UniformParticleAffector::create(); ExampleUniformAffector->setMagnitude(20.0); // force which the field exerts on particles (negative = towards the air field's beacon location) NodeRefPtr UniformBeacon = Node::create(); ExampleUniformAffector->setBeacon(UniformBeacon); // set to 'emulate' from (0,0,0) ExampleUniformAffector->setDirection(Vec3f(1.0,0.0,0.0)); // direction which field is exerted ExampleUniformAffector->setMaxDistance(-1.0); // particles affected regardless of distance from ExampleUniformAffector->setAttenuation(0.0); // strength of uniform field dimishes by dist^attenuation, in this case it is constant regardless of distance ExampleUniformAffector->setParticleMass(10.0); //Attach the Generator and Affector to the Particle System ExampleParticleSystem->pushToGenerators(ExampleGenerator); ExampleParticleSystem->pushToAffectors(ExampleUniformAffector); ExampleParticleSystem->setMaxParticles(500); //Particle System Node ParticleSystemCoreRecPtr ParticleNodeCore = ParticleSystemCore::create(); ParticleNodeCore->setSystem(ExampleParticleSystem); ParticleNodeCore->setDrawer(ExamplePointParticleSystemDrawer); 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); TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1, &sceneManager, ParticleNodeCore.get(), ExamplePointParticleSystemDrawer.get(), ExampleLineParticleSystemDrawer.get(), ExampleUniformAffector.get())); sceneManager.setRoot(scene); // Show the whole Scene sceneManager.showAll(); sceneManager.getCamera()->setFar(1000.0); std::cout << "Uniform Particle Affector Tutorial Controls:\n" << "1: Use point drawer\n" << "2: Use line drawer\n" << "W,A,S,D: Change direction of field\n" << "Ctrl + Q: Exit Tutorial"; //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "19UniformFieldParticleAffector"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
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 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_AMBIENT_AND_DIFFUSE); ChunkMaterialRefPtr PSMaterial = ChunkMaterial::create(); PSMaterial->addChunk(PSPointChunk); PSMaterial->addChunk(PSMaterialChunkChunk); PSMaterial->addChunk(PSBlendChunk); //Particle System ParticleSystemRefPtr ExampleParticleSystem = 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->attachUpdateProducer(TutorialWindow); //Particle System Drawer (Point) PointParticleSystemDrawerRecPtr ExamplePointParticleSystemDrawer = PointParticleSystemDrawer::create(); //Particle System Drawer (line) LineParticleSystemDrawerRecPtr ExampleLineParticleSystemDrawer = LineParticleSystemDrawer::create(); ExampleLineParticleSystemDrawer->setLineDirectionSource(LineParticleSystemDrawer::DIRECTION_VELOCITY); ExampleLineParticleSystemDrawer->setLineLengthSource(LineParticleSystemDrawer::LENGTH_SIZE_X); ExampleLineParticleSystemDrawer->setLineLength(2.0f); ExampleLineParticleSystemDrawer->setEndPointFading(Vec2f(0.0f,1.0f)); //Create a Rate Particle Generator RateParticleGeneratorRefPtr ExampleGenerator = RateParticleGenerator::create(); //Attach the function objects to the Generator ExampleGenerator->setPositionDistribution(createPositionDistribution()); ExampleGenerator->setLifespanDistribution(createLifespanDistribution()); ExampleGenerator->setGenerationRate(60.0); ExampleGenerator->setVelocityDistribution(createVelocityDistribution()); VortexParticleAffectorRecPtr ExampleVortexAffector = VortexParticleAffector::create(); ExampleVortexAffector->setMagnitude(20.0); ExampleVortexAffector->setVortexAxis(Vec3f(0.0,0.0,1.0)); // field rotates around z axis NodeRefPtr VortexBeacon = Node::create(); ExampleVortexAffector->setBeacon(VortexBeacon); // set to 'emulate' from (0,0,0) ExampleVortexAffector->setMaxDistance(-1.0); // particles affected regardless of distance ExampleVortexAffector->setAttenuation(0.25); // strength of uniform field dimishes by dist^attenuation //Attach the Generator and Affector to the Particle System ExampleParticleSystem->pushToGenerators(ExampleGenerator); ExampleParticleSystem->pushToAffectors(ExampleVortexAffector); ExampleParticleSystem->setMaxParticles(800); //Particle System Node ParticleSystemCoreRecPtr ParticleNodeCore = ParticleSystemCore::create(); ParticleNodeCore->setSystem(ExampleParticleSystem); ParticleNodeCore->setDrawer(ExamplePointParticleSystemDrawer); 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); TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1, &sceneManager, ParticleNodeCore.get(), ExamplePointParticleSystemDrawer.get(), ExampleLineParticleSystemDrawer.get(), ExampleVortexAffector.get())); sceneManager.setRoot(scene); //Create the Documentation SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow); // Show the whole Scene sceneManager.showAll(); sceneManager.getCamera()->setFar(1000.0); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "22VortexParticleAffector"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
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(); 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(); mgr->getCamera()->setFar(1000.0); std::cout << "Radial Particle Affector Tutorial Controls:\n" << "R: Reverse direction of field\n" << "Ctrl + Q: Exit Tutorial"; //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "23RadialFieldParticleAffector"); //Enter main Loop TutorialWindow->mainLoop(); osgExit(); return 0; }
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 NodeRefPtr ParticleNode = OSG::Node::create(); ParticleNode->setCore(ParticleNodeCore); // add the trail generator to the scene ParticleNode->addChild(ExampleTrailGenerator); // Make Main Scene Node NodeRefPtr scene = OSG::Node::create(); scene->setCore(OSG::Group::create()); scene->addChild(ParticleNode); mgr->setRoot(scene); // Show the whole Scene mgr->showAll(); mgr->getCamera()->setFar(10000.0f); mgr->getCamera()->setNear(0.1f); mgr->setStatistics(true); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "01ParticleTrail"); std::cout << "Controls: " << std::endl << "P: Increase Trail Resolution" << std::endl << "L: Decrease Trail Resolution" << std::endl << "O: Increase Trail Length" << std::endl << "K: Decrease Trail Length" << std::endl << "I: Toggle drawing trails as points/lines" << std::endl << "J: Toggle calculating trail length by num points/time" << std::endl << "Y: Toggle calculating trail point spacing by time/distance" << std::endl << "B: Particle burst" << std::endl; //Enter main Loop TutorialWindow->mainLoop(); osgExit(); return 0; }
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 PointChunkRefPtr PSPointChunk = PointChunk::create(); PSPointChunk->setSize(10.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.2f,0.6f,0.5f,0.3f)); PSMaterialChunkChunk->setDiffuse(Color4f(0.2f,0.9f,0.1f,0.3f)); PSMaterialChunkChunk->setSpecular(Color4f(0.5f,0.4f,0.2f,0.6f)); PSMaterialChunkChunk->setEmission(Color4f(0.2f,0.6f,0.5f,0.3f)); PSMaterialChunkChunk->setColorMaterial(GL_NONE); //enable depth test DepthChunkRefPtr PSDepthChunk = DepthChunk::create(); ChunkMaterialRefPtr PSMaterial = ChunkMaterial::create(); PSMaterial->addChunk(PSPointChunk); PSMaterial->addChunk(PSMaterialChunkChunk); PSMaterial->addChunk(PSBlendChunk); PSMaterial->addChunk(PSDepthChunk); //Particle System ParticleSystemRefPtr ExampleParticleSystem = ParticleSystem::create(); ExampleParticleSystem->attachUpdateProducer(TutorialWindow); //Particle System Drawer //Point PointParticleSystemDrawerRecPtr ExamplePointParticleSystemDrawer = PointParticleSystemDrawer::create(); //ExamplePointParticleSystemDrawer->setForcePerParticleSizing(true); //Line LineParticleSystemDrawerRecPtr ExampleLineParticleSystemDrawer = LineParticleSystemDrawer::create(); ExampleLineParticleSystemDrawer->setLineDirectionSource(LineParticleSystemDrawer::DIRECTION_NORMAL);//DIRECTION_VELOCITY_CHANGE); ExampleLineParticleSystemDrawer->setLineLengthSource(LineParticleSystemDrawer::LENGTH_SIZE_X); ExampleLineParticleSystemDrawer->setEndPointFading(Vec2f(1.0,0.0)); //Quad QuadParticleSystemDrawerRecPtr ExampleQuadParticleSystemDrawer = QuadParticleSystemDrawer::create(); ExampleQuadParticleSystemDrawer->setQuadSizeScaling(Vec2f(0.1,0.1)); ExampleQuadParticleSystemDrawer->setNormalAndUpSource(QuadParticleSystemDrawer::NORMAL_PARTICLE_NORMAL,QuadParticleSystemDrawer::UP_STATIC); RateParticleGeneratorRefPtr ExampleGeneratorTheSequel = RateParticleGenerator::create(); //Attach the function objects to the Generator ExampleGeneratorTheSequel->setPositionDistribution(createPositionDistribution()); ExampleGeneratorTheSequel->setLifespanDistribution(createLifespanDistribution()); ExampleGeneratorTheSequel->setGenerationRate(300.0); ExampleGeneratorTheSequel->setVelocityDistribution(createVelocityDistribution()); //Attach the Generator to the Particle System //ExampleParticleSystem->pushToGenerators(ExampleGenerator); ExampleParticleSystem->setMaxParticles(500); ExampleParticleSystem->pushToGenerators(ExampleGeneratorTheSequel); //Particle System Node ParticleSystemCoreRecPtr ParticleNodeCore = ParticleSystemCore::create(); ParticleNodeCore->setSystem(ExampleParticleSystem); ParticleNodeCore->setDrawer(ExampleQuadParticleSystemDrawer); ParticleNodeCore->setMaterial(PSMaterial); ParticleNodeCore->setSortingMode(ParticleSystemCore::BACK_TO_FRONT); 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); TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1, &sceneManager, ParticleNodeCore.get(), ExamplePointParticleSystemDrawer.get(), ExampleLineParticleSystemDrawer.get(), ExampleQuadParticleSystemDrawer.get())); sceneManager.setRoot(scene); //Create the Documentation SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow); // Show the whole Scene sceneManager.showAll(); sceneManager.getCamera()->setFar(500.0); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "14ParticleSorting"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }