void ParticleSystemParticleTrailGenerator::onCreate(const ParticleTrailGenerator *Id) { // assemble default material PointChunkRecPtr pointChunk = PointChunk::create(); pointChunk->setSmooth(true); BlendChunkRecPtr blendChunk = BlendChunk::create(); //Particle System Material MaterialChunkRecPtr materialChunkChunk = MaterialChunk::create(); materialChunkChunk->setAmbient(Color4f(0.5f,0.5f,0.5f,1.0f)); materialChunkChunk->setDiffuse(Color4f(0.7f,0.7f,0.7f,1.0f)); materialChunkChunk->setSpecular(Color4f(0.9f,0.9f,0.9f,1.0f)); materialChunkChunk->setColorMaterial(GL_AMBIENT_AND_DIFFUSE); // Assembling materials ChunkMaterialRecPtr mat = ChunkMaterial::create(); mat->addChunk(materialChunkChunk); mat->addChunk(pointChunk); mat->addChunk(blendChunk); PointParticleSystemDrawerRecPtr theDrawer = PointParticleSystemDrawer::create(); theDrawer->setForcePerParticleSizing(true); ParticleSystemRecPtr newPS = ParticleSystem::create(); newPS->setDynamic(true); setParticleSystem(newPS); ParticleSystemCoreRecPtr newCore = ParticleSystemCore::create(); newCore->setSystem(newPS); newCore->setMaterial(mat); newCore->setDrawer(theDrawer); setCore(newCore); }
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 PointChunkRecPtr PSPointChunk = PointChunk::create(); PSPointChunk->setSize(5.0f); PSPointChunk->setSmooth(true); BlendChunkRecPtr PSBlendChunk = BlendChunk::create(); PSBlendChunk->setSrcFactor(GL_SRC_ALPHA); PSBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA); MaterialChunkRecPtr PSMaterialChunkChunk = MaterialChunk::create(); PSMaterialChunkChunk->setAmbient(Color4f(0.5f,0.5f,0.5f,0.3f)); PSMaterialChunkChunk->setDiffuse(Color4f(0.8f,0.8f,0.8f,0.3f)); PSMaterialChunkChunk->setSpecular(Color4f(1.0f,1.0f,1.0f,0.3f)); PSMaterialChunkChunk->setColorMaterial(GL_AMBIENT_AND_DIFFUSE); ChunkMaterialRecPtr PSMaterial = ChunkMaterial::create(); PSMaterial->addChunk(PSPointChunk); PSMaterial->addChunk(PSMaterialChunkChunk); PSMaterial->addChunk(PSBlendChunk); //Particle System ParticleSystemRecPtr ExampleParticleSystem = ParticleSystem::create(); for(UInt32 i(0) ; i<10 ; ++i) { ExampleParticleSystem->addParticle(Pnt3f(i,i,i), Vec3f(0.0,0.0f,1.0f), Color4f(1.0,0.0,0.0,0.5), Vec3f(1.0,1.0,1.0), -1.0, Vec3f(0.0f,0.0f,0.0f), //Velocity Vec3f(0.0f,0.0f,0.0f) ); } ExampleParticleSystem->attachUpdateProducer(TutorialWindow); //Particle System Drawer //Point PointParticleSystemDrawerRecPtr ExamplePointDrawer = PointParticleSystemDrawer::create(); //ExamplePointParticleSystemDrawer->setForcePerParticleSizing(true); //Line LineParticleSystemDrawerRecPtr ExampleLineDrawer = LineParticleSystemDrawer::create(); ExampleLineDrawer->setLineDirectionSource(LineParticleSystemDrawer::DIRECTION_NORMAL);//DIRECTION_VELOCITY_CHANGE); ExampleLineDrawer->setLineLengthSource(LineParticleSystemDrawer::LENGTH_SIZE_X); //Quad QuadParticleSystemDrawerRecPtr ExampleQuadDrawer = QuadParticleSystemDrawer::create(); //Disc DiscParticleSystemDrawerRecPtr ExampleDiscDrawer = DiscParticleSystemDrawer::create(); ExampleDiscDrawer->setSegments(16); ExampleDiscDrawer->setCenterAlpha(1.0); ExampleDiscDrawer->setEdgeAlpha(0.0); //Particle System Node ParticleSystemCoreRecPtr ParticleNodeCore = ParticleSystemCore::create(); ParticleNodeCore->setSystem(ExampleParticleSystem); ParticleNodeCore->setDrawer(ExampleLineDrawer); ParticleNodeCore->setMaterial(PSMaterial); NodeRecPtr ParticleNode = Node::create(); ParticleNode->setCore(ParticleNodeCore); // Make Main Scene Node NodeRecPtr scene = Node::create(); scene->setCore(Group::create()); scene->addChild(ParticleNode); sceneManager.setRoot(scene); TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1, &sceneManager, ParticleNodeCore.get(), ExamplePointDrawer, ExampleLineDrawer, ExampleQuadDrawer, ExampleDiscDrawer )); //Create the Documentation SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow); // Show the whole Scene sceneManager.showAll(); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "01ParticleSystemDrawers"); commitChanges(); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }