ChunkMaterialRefPtr createGreenMaterial(void){ ChunkMaterialRefPtr GreenBackgroundMaterial = ChunkMaterial::create(); MaterialChunkRefPtr GreenBackgroundMaterialChunk = MaterialChunk::create(); GreenBackgroundMaterialChunk->setAmbient(Color4f(0.0,1.0,0.0,1.0)); GreenBackgroundMaterialChunk->setDiffuse(Color4f(0.0,1.0,0.0,1.0)); GreenBackgroundMaterialChunk->setSpecular(Color4f(0.0,1.0,0.0,1.0)); GreenBackgroundMaterial->addChunk(GreenBackgroundMaterialChunk); return GreenBackgroundMaterial; }
ChunkMaterialRefPtr createBlueMaterial(void){ ChunkMaterialRefPtr BlueBackgroundMaterial = ChunkMaterial::create(); MaterialChunkRefPtr BlueBackgroundMaterialChunk = MaterialChunk::create(); BlueBackgroundMaterialChunk->setAmbient(Color4f(0.0,0.0,0.8,1.0)); BlueBackgroundMaterialChunk->setDiffuse(Color4f(0.0,0.0,0.8,1.0)); BlueBackgroundMaterialChunk->setSpecular(Color4f(0.0,0.0,0.8,1.0)); BlueBackgroundMaterial->addChunk(BlueBackgroundMaterialChunk); return BlueBackgroundMaterial; }
ChunkMaterialRefPtr createRedMaterial(void){ ChunkMaterialRefPtr RedBackgroundMaterial = ChunkMaterial::create(); MaterialChunkRefPtr RedBackgroundMaterialChunk = MaterialChunk::create(); RedBackgroundMaterialChunk->setAmbient(Color4f(1.0,0.0,0.0,1.0)); RedBackgroundMaterialChunk->setDiffuse(Color4f(1.0,0.0,0.0,1.0)); RedBackgroundMaterialChunk->setSpecular(Color4f(1.0,0.0,0.0,1.0)); RedBackgroundMaterial->addChunk(RedBackgroundMaterialChunk); return RedBackgroundMaterial; }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); { // Set up Window WindowEventProducerRecPtr TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); // Create the SimpleSceneManager helper SimpleSceneManagerRefPtr sceneManager = SimpleSceneManager::create(); TutorialWindow->setDisplayCallback(boost::bind(display, sceneManager)); TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, sceneManager)); // Tell the Manager what to manage sceneManager->setWindow(TutorialWindow); TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1)); // Make Torus Node (creates Torus in background of scene) NodeRefPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16); // Make Main Scene Node and add the Torus NodeRefPtr scene = OSG::Node::create(); scene->setCore(OSG::Group::create()); scene->addChild(TorusGeometryNode); // Create the Graphics GraphicsRefPtr TutorialGraphics = OSG::Graphics2D::create(); // Initialize the LookAndFeelManager to enable default settings LookAndFeelManager::the()->getLookAndFeel()->init(); /****************************************************** Create the Layers. ******************************************************/ ColorLayerRefPtr ExampleColorLayer = OSG::ColorLayer::create(); CompoundLayerRefPtr ExampleCompoundLayer = OSG::CompoundLayer::create(); EmptyLayerRefPtr ExampleEmptyLayer = OSG::EmptyLayer::create(); GradientLayerRefPtr ExampleGradientLayer = OSG::GradientLayer::create(); MaterialLayerRefPtr ExampleMaterialLayer = OSG::MaterialLayer::create(); TextureLayerRefPtr ExampleTextureLayer = OSG::TextureLayer::create(); PatternLayerRefPtr ExamplePatternLayer = OSG::PatternLayer::create(); GlassLayerRefPtr ExampleGlassLayer = OSG::GlassLayer::create(); CompoundLayerRefPtr ExampleGlassCompoundLayer = OSG::CompoundLayer::create(); /****************************************************** The ColorLayer is a simple Layer having just a Color to it. -setColor(Color4f): Determine the Color of the Layer. ******************************************************/ ExampleColorLayer->setColor(Color4f(1.0,0.0,0.0,1.0)); /****************************************************** The CompoundLayer allows you to combine multiple Backgrounds into one. The Backgrounds are added sequentially; so in this example the ExampleTextureLayer would be added first, and the ExampleGradientLayer rendered on top of it. -getBackgrounds().push_back(BackgroundName): Adds a Background to the CompoundBackground. ******************************************************/ ExampleCompoundLayer->pushToBackgrounds(ExampleTextureLayer); ExampleCompoundLayer->pushToBackgrounds(ExampleGradientLayer); /****************************************************** The EmptyLayer is a Background with no attributes. ******************************************************/ // Nothing! /****************************************************** The GradientLayer is a Background which displays a gradient of Color. -getColors().push_back(Color4f): Determines the starting Color for the gradient. -getColors().push_back(Color4f): Determines the ending Color for the gradient. -setOrientation(ENUM): Determines the gradient alignment. Takes HORIZONTAL_ORIENTATION or VERTICAL_ORIENTATION arguments. ******************************************************/ ExampleGradientLayer->editMFColors()->push_back(Color4f(1.0, 0.0, 0.0, 1.0)); ExampleGradientLayer->editMFStops()->push_back(0.0); ExampleGradientLayer->editMFColors()->push_back(Color4f(0.0, 1.0, 0.0, 0.75)); ExampleGradientLayer->editMFStops()->push_back(0.5); ExampleGradientLayer->editMFColors()->push_back(Color4f(0.0, 0.0, 1.0, 0.5)); ExampleGradientLayer->editMFStops()->push_back(1.0); ExampleGradientLayer->setStartPosition(Vec2f(0.2f,0.2f)); ExampleGradientLayer->setEndPosition(Vec2f(.6f,0.6f)); ExampleGradientLayer->setSpreadMethod(GradientLayer::SPREAD_REFLECT); /****************************************************** The MaterialLayer is a Background which is created using a Material (also created here). -setMaterial(MaterialName): Determine which Material will be used to create the Background. ******************************************************/ // Creates Material ChunkMaterialRefPtr LayerMaterial = ChunkMaterial::create(); MaterialChunkRefPtr LayerMaterialChunk = MaterialChunk::create(); LayerMaterialChunk->setAmbient(Color4f(1.0,0.0,0.0,1.0)); LayerMaterialChunk->setDiffuse(Color4f(0.0,1.0,0.0,1.0)); LayerMaterialChunk->setSpecular(Color4f(0.0,0.0,1.0,1.0)); LayerMaterial->addChunk(LayerMaterialChunk); // Edit MaterialLayer ExampleMaterialLayer->setMaterial(LayerMaterial); /****************************************************** The TextureLayer is a Background which is created using a Texture (also created here). -setTexture(TextureName): Determine which Texture will be used to create the Background. ******************************************************/ // Creates Texture from Image TextureObjChunkRefPtr LayerTextureObjChunk = TextureObjChunk::create(); ImageRefPtr LoadedImage = ImageFileHandler::the()->read("Data/Checker.jpg"); LayerTextureObjChunk->setImage(LoadedImage); // Edit TextureLayer ExampleTextureLayer->setTexture(LayerTextureObjChunk); /****************************************************** The PatternLayer is a Background which is created using a Texture (also created here). -setTexture(TextureName): Determine which Texture will be used to create the Background. -setPatternSize(Vec2f): -setVerticalAlignment(): -setHorizontalAlignment(): -setHorizontalRepeat(): -setVerticalRepeat(): -setHorizontalRepeatValue(): -setVerticalRepeatValue(): ******************************************************/ TextureObjChunkRefPtr LayerPatternChunk = TextureObjChunk::create(); //ImageRefPtr LoadedImage = ImageFileHandler::the()->read("Data/Checker.jpg"); LayerPatternChunk->setImage(LoadedImage); LayerPatternChunk->setWrapS(GL_REPEAT); LayerPatternChunk->setWrapT(GL_CLAMP_TO_EDGE); ExamplePatternLayer->setTexture(LayerPatternChunk); ExamplePatternLayer->setPatternSize(Vec2f(50.0f,50.0f)); ExamplePatternLayer->setVerticalAlignment(0.5); ExamplePatternLayer->setHorizontalAlignment(0.0); ExamplePatternLayer->setHorizontalRepeat(PatternLayer::PATTERN_REPEAT_BY_POINT); ExamplePatternLayer->setVerticalRepeat(PatternLayer::PATTERN_REPEAT_ABSOLUTE); ExamplePatternLayer->setHorizontalRepeatValue(1.0); ExamplePatternLayer->setVerticalRepeatValue(2.0); /****************************************************** ******************************************************/ ExampleGlassLayer->setCenterColor(Color4f(1.0f,1.0f,1.0f,0.0f)); ExampleGlassLayer->setEdgeColor(Color4f(1.0f,1.0f,1.0f,0.7f)); /****************************************************** ******************************************************/ ExampleGlassCompoundLayer->pushToBackgrounds(ExampleColorLayer); ExampleGlassCompoundLayer->pushToBackgrounds(ExampleGlassLayer); /****************************************************** Create and edit Button Components to display the Layers. ******************************************************/ ButtonRefPtr ExampleColorLayerButton = OSG::Button::create(); ButtonRefPtr ExampleCompoundLayerButton = OSG::Button::create(); ButtonRefPtr ExampleEmptyLayerButton = OSG::Button::create(); ButtonRefPtr ExampleGradientLayerButton = OSG::Button::create(); ButtonRefPtr ExampleMaterialLayerButton = OSG::Button::create(); ButtonRefPtr ExampleTextureLayerButton = OSG::Button::create(); ButtonRefPtr ExamplePatternLayerButton = OSG::Button::create(); ButtonRefPtr ExampleGlassLayerButton = OSG::Button::create(); ButtonRefPtr ExampleGlassCompoundLayerButton = OSG::Button::create(); ExampleColorLayerButton->setText("Color Layer"); ExampleColorLayerButton->setBackground(ExampleColorLayer); ExampleColorLayerButton->setActiveBackground(ExampleColorLayer); ExampleColorLayerButton->setRolloverBackground(ExampleColorLayer); ExampleColorLayerButton->setPreferredSize(Vec2f(150,50)); ExampleCompoundLayerButton->setText("Compound Layer"); ExampleCompoundLayerButton->setBackground(ExampleCompoundLayer); ExampleCompoundLayerButton->setActiveBackground(ExampleCompoundLayer); ExampleCompoundLayerButton->setRolloverBackground(ExampleCompoundLayer); ExampleCompoundLayerButton->setPreferredSize(Vec2f(150,50)); ExampleEmptyLayerButton->setText("Empty Layer"); ExampleEmptyLayerButton->setBackground(ExampleEmptyLayer); ExampleEmptyLayerButton->setActiveBackground(ExampleEmptyLayer); ExampleEmptyLayerButton->setRolloverBackground(ExampleEmptyLayer); ExampleEmptyLayerButton->setPreferredSize(Vec2f(150,50)); ExampleGradientLayerButton->setText("Gradient Layer"); ExampleGradientLayerButton->setBackground(ExampleGradientLayer); ExampleGradientLayerButton->setActiveBackground(ExampleGradientLayer); ExampleGradientLayerButton->setRolloverBackground(ExampleGradientLayer); ExampleGradientLayerButton->setPreferredSize(Vec2f(150,50)); ExampleMaterialLayerButton->setText("Material Layer"); ExampleMaterialLayerButton->setBackground(ExampleMaterialLayer); ExampleMaterialLayerButton->setActiveBackground(ExampleMaterialLayer); ExampleMaterialLayerButton->setRolloverBackground(ExampleMaterialLayer); ExampleMaterialLayerButton->setPreferredSize(Vec2f(150,50)); ExampleMaterialLayerButton->setTextColor(Color4f(1.0,1.0,1.0,1.0)); ExampleMaterialLayerButton->setRolloverTextColor(Color4f(1.0,1.0,1.0,1.0)); ExampleMaterialLayerButton->setActiveTextColor(Color4f(1.0,1.0,1.0,1.0)); ExampleTextureLayerButton->setText("Texture Layer"); ExampleTextureLayerButton->setBackground(ExampleTextureLayer); ExampleTextureLayerButton->setActiveBackground(ExampleTextureLayer); ExampleTextureLayerButton->setRolloverBackground(ExampleTextureLayer); ExampleTextureLayerButton->setPreferredSize(Vec2f(150,50)); ExampleTextureLayerButton->setTextColor(Color4f(0.0,1.0,0.0,1.0)); ExampleTextureLayerButton->setRolloverTextColor(Color4f(0.0,1.0,0.0,1.0)); ExampleTextureLayerButton->setActiveTextColor(Color4f(0.0,1.0,0.0,1.0)); ExamplePatternLayerButton->setText("Pattern Layer"); ExamplePatternLayerButton->setBackground(ExamplePatternLayer); ExamplePatternLayerButton->setActiveBackground(ExamplePatternLayer); ExamplePatternLayerButton->setRolloverBackground(ExamplePatternLayer); ExamplePatternLayerButton->setPreferredSize(Vec2f(150,50)); ExamplePatternLayerButton->setTextColor(Color4f(0.0,1.0,0.0,1.0)); ExamplePatternLayerButton->setRolloverTextColor(Color4f(0.0,1.0,0.0,1.0)); ExamplePatternLayerButton->setActiveTextColor(Color4f(0.0,1.0,0.0,1.0)); ExampleGlassLayerButton->setText("Glass Layer"); ExampleGlassLayerButton->setBackground(ExampleGlassLayer); ExampleGlassLayerButton->setActiveBackground(ExampleGlassLayer); ExampleGlassLayerButton->setRolloverBackground(ExampleGlassLayer); ExampleGlassLayerButton->setPreferredSize(Vec2f(150,50)); ExampleGlassLayerButton->setTextColor(Color4f(0.0,0.0,0.0,1.0)); ExampleGlassLayerButton->setRolloverTextColor(Color4f(0.0,0.0,0.0,1.0)); ExampleGlassLayerButton->setActiveTextColor(Color4f(0.0,0.0,0.0,1.0)); ExampleGlassCompoundLayerButton->setText("GlassCompound Layer"); ExampleGlassCompoundLayerButton->setBackground(ExampleGlassCompoundLayer); ExampleGlassCompoundLayerButton->setActiveBackground(ExampleGlassCompoundLayer); ExampleGlassCompoundLayerButton->setRolloverBackground(ExampleGlassCompoundLayer); ExampleGlassCompoundLayerButton->setPreferredSize(Vec2f(150,50)); ExampleGlassCompoundLayerButton->setTextColor(Color4f(0.0,0.0,0.0,1.0)); ExampleGlassCompoundLayerButton->setRolloverTextColor(Color4f(0.0,0.0,0.0,1.0)); ExampleGlassCompoundLayerButton->setActiveTextColor(Color4f(0.0,0.0,0.0,1.0)); /****************************************************** Create a MainFrameBackground. For almost all Tutorials, this is simply a ColorLayer with a semi-transparent white Background. ******************************************************/ // Create The Main InternalWindow // Create Background to be used with the Main InternalWindow ColorLayerRefPtr MainInternalWindowBackground = OSG::ColorLayer::create(); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); //InternalWindow Layout LayoutRefPtr MainInternalWindowLayout = OSG::FlowLayout::create(); InternalWindowRefPtr MainInternalWindow = OSG::InternalWindow::create(); MainInternalWindow->pushToChildren(ExampleColorLayerButton); MainInternalWindow->pushToChildren(ExampleCompoundLayerButton); MainInternalWindow->pushToChildren(ExampleEmptyLayerButton); MainInternalWindow->pushToChildren(ExampleGradientLayerButton); MainInternalWindow->pushToChildren(ExampleMaterialLayerButton); MainInternalWindow->pushToChildren(ExampleTextureLayerButton); MainInternalWindow->pushToChildren(ExamplePatternLayerButton); MainInternalWindow->pushToChildren(ExampleGlassLayerButton); MainInternalWindow->pushToChildren(ExampleGlassCompoundLayerButton); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setDrawTitlebar(false); MainInternalWindow->setResizable(false); // Create the Drawing Surface UIDrawingSurfaceRefPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundRefPtr TutorialUIForeground = OSG::UIForeground::create(); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); // Create the SimpleSceneManager helper sceneManager->setRoot(scene); // Add the UI Foreground Object to the Scene ViewportRefPtr TutorialViewport = sceneManager->getWindow()->getPort(0); TutorialViewport->addForeground(TutorialUIForeground); //Create the Documentation Foreground and add it to the viewport 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, "04Background"); //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(20.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); Distribution3DRefPtr PositionDistribution = createPositionDistribution(); Distribution1DRefPtr LifespanDistribution = createLifespanDistribution(); Pnt3f PositionReturnValue; Time LifespanReturnValue = -1; //Particle System ParticleSystemRefPtr ExampleParticleSystem = OSG::ParticleSystem::create(); for(UInt32 i(0) ; i<200 ; ++i)//controls how many particles are created { if(PositionDistribution != NULL) { PositionReturnValue = Pnt3f(PositionDistribution->generate()); } if(LifespanDistribution != NULL) { LifespanReturnValue = LifespanDistribution->generate(); } ExampleParticleSystem->addParticle( PositionReturnValue, Vec3f(0.0f,0.0f,1.0f), Color4f(1.0,0.0,0.0,1.0), Vec3f(1.0,1.0,1.0), LifespanReturnValue, Vec3f(0.0f,0.0f,0.0f), //Velocity Vec3f(0.0f,0.0f,0.0f) //acceleration ); } ExampleParticleSystem->attachUpdateListener(TutorialWindow); //Particle System Drawer PointParticleSystemDrawerRefPtr ExampleParticleSystemDrawer = OSG::PointParticleSystemDrawer::create(); //Create an CollectiveGravityParticleSystemAffector CollectiveGravityParticleSystemAffectorRefPtr ExampleCollectiveGravityParticleSystemAffector = OSG::CollectiveGravityParticleSystemAffector::create(); ExampleCollectiveGravityParticleSystemAffector->setParticleMass(10000000000.0f); ExampleParticleSystem->pushToSystemAffectors(ExampleCollectiveGravityParticleSystemAffector); //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, "10GravityParticleSystemAffector"); //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 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); 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 = OSG::Node::create(); scene->setCore(OSG::Group::create()); scene->addChild(ParticleNode); scene->addChild(GroundTransformNode); 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, "07AgeSizeParticleAffector"); //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) { 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); ParticleNodeCore->setDrawer(ExampleParticleSystemDrawer); ParticleNodeCore->setMaterial(PSMaterial); ParticleNodeCore->setSortingMode(ParticleSystemCore::BACK_TO_FRONT); NodeRefPtr ParticleNode = Node::create(); ParticleNode->setCore(ParticleNodeCore); ExampleParticleSystem->addParticle(Pnt3f(10.0,0.0,0.0), Vec3f(0.0,1.0,0.0), Color4f(1.0,1.0,1.0,1.0), Vec3f(1.0,1.0,1.0), 0.01, Vec3f(0.0,0.0,0.0), Vec3f(0.0,0.0,0.0)); ExampleParticleSystem->addParticle(Pnt3f(-10.0,0.0,0.0), Vec3f(0.0,1.0,0.0), Color4f(1.0,1.0,1.0,1.0), Vec3f(1.0,1.0,1.0), 0.01, Vec3f(0.0,0.0,0.0), Vec3f(0.0,0.0,0.0)); ExampleParticleSystem->pushToGenerators(ExampleParticleGenerator); // Make Main Scene Node and add the Torus NodeRefPtr scene = makeCoredNode<Group>(); scene->addChild(ParticleNode); TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1, &sceneManager, AgeFunc.get())); sceneManager.setRoot(scene); // 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, "05a - QuadSequenceParticleDrawer"); //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)); // Material blend chunk BlendChunkRefPtr PSBlendChunk = BlendChunk::create(); PSBlendChunk->setSrcFactor(GL_SRC_ALPHA); PSBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA); //load up images for PS drawer ImageRefPtr rocket = ImageFileHandler::the()->read("Data/rocket.png"); ImageRefPtr smoke = ImageFileHandler::the()->read("Data/Smokey.png"); //Texture Chunk TextureObjChunkRefPtr PSRocketTexChunk = TextureObjChunk::create(); PSRocketTexChunk->setImage(rocket); TextureEnvChunkRefPtr PSRocketTexEnvChunk = TextureEnvChunk::create(); PSRocketTexEnvChunk->setEnvMode(GL_MODULATE); TextureObjChunkRefPtr SmokeTexChunk = TextureObjChunk::create(); SmokeTexChunk->setImage(smoke); TextureEnvChunkRefPtr SmokeTexEnvChunk = TextureEnvChunk::create(); SmokeTexEnvChunk->setEnvMode(GL_MODULATE); //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(PSBlendChunk); PSMaterial->addChunk(PSRocketTexChunk); ChunkMaterialRefPtr TrailMaterial = ChunkMaterial::create(); TrailMaterial->addChunk(PSMaterialChunkChunk); TrailMaterial->addChunk(PSBlendChunk); TrailMaterial->addChunk(SmokeTexChunk); AgeFadeParticleAffectorRefPtr AgeFadeAffector = AgeFadeParticleAffector::create(); AgeFadeAffector->setFadeInTime(0.0f); AgeFadeAffector->setStartAlpha(1.0f); AgeFadeAffector->setEndAlpha(0.0f); AgeFadeAffector->setFadeOutTime(0.35f); AgeFadeAffector->setFadeToAlpha(1.0f); // 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); // attach listener for trail generator to the particle system ExamplePSTrailGenerator->setSystemToTrail(ExampleParticleSystem); //Attach the the update producer to the particle system particle trail generator. ExamplePSTrailGenerator->attachUpdateProducer(TutorialWindow); // Set up node with the particle system at its core NodeRefPtr ParticleNode = Node::create(); ParticleNode->setCore(ParticleNodeCore); ParticleNode->addChild(ExamplePSTrailGenerator); // Make Main Scene Node NodeRefPtr scene = Node::create(); scene->setCore(Group::create()); scene->addChild(ParticleNode); sceneManager.setRoot(scene); // Show the whole Scene sceneManager.showAll(); sceneManager.getCamera()->setFar(10000.0f); sceneManager.getCamera()->setNear(0.1f); sceneManager.setStatistics(false); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "02ParticleSystemParticleTrail"); 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 << "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 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); BlendChunkRefPtr PSBlendChunk = BlendChunk::create(); PSBlendChunk->setSrcFactor(GL_SRC_ALPHA); PSBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA); //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); PSMaterial->addChunk(PSBlendChunk); Distribution3DRefPtr PositionDistribution = createPositionDistribution(); Pnt3f PositionReturnValue; //Particle System ParticleSystemRefPtr ExampleParticleSystem = OSG::ParticleSystem::create(); for(UInt32 i(0) ; i<800 ; ++i)//controls how many particles are created { if(PositionDistribution != NULL) { PositionReturnValue = Pnt3f(PositionDistribution->generate()); } ExampleParticleSystem->addParticle( PositionReturnValue, Vec3f(0.0f,0.0f,1.0f), Color4f(1.0,0.0,0.0,1.0), Vec3f(10.0,10.0,10.0), -1, Vec3f(0.0f,0.0f,0.0f), //Velocity Vec3f(0.0f,0.0f,0.0f) //acceleration ); } ExampleParticleSystem->attachUpdateListener(TutorialWindow); //Particle System Drawer DiscParticleSystemDrawerRefPtr ExampleParticleSystemDrawer = OSG::DiscParticleSystemDrawer::create(); ExampleParticleSystemDrawer->setSegments(16); ExampleParticleSystemDrawer->setCenterAlpha(1.0); ExampleParticleSystemDrawer->setEdgeAlpha(0.0); //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); //AttractionNode TransformRefPtr AttractionCore = OSG::Transform::create(); Matrix AttractTransform; AttractTransform.setTranslate(0.0f, 0.0,0.0); AttractionCore->setMatrix(AttractTransform); NodeRefPtr AttractionNode = OSG::Node::create(); AttractionNode->setCore(AttractionCore); // Make Main Scene Node and add the Torus NodeRefPtr scene = OSG::Node::create(); scene->setCore(OSG::Group::create()); scene->addChild(ParticleNode); scene->addChild(AttractionNode); mgr->setRoot(scene); // Show the whole Scene //mgr->showAll(); mgr->getNavigator()->set(Pnt3f(0.0,0.0,500.0), Pnt3f(0.0,0.0,0.0), Vec3f(0.0,1.0,0.0)); mgr->getNavigator()->setMotionFactor(1.0f); mgr->getCamera()->setNear(0.1f); mgr->getCamera()->setFar(1000.0f); DistanceAttractRepelParticleAffectorRefPtr ExampleDistanceAttractRepelParticleAffector = OSG::DistanceAttractRepelParticleAffector::create(); ExampleDistanceAttractRepelParticleAffector->setMinDistance(0.0); ExampleDistanceAttractRepelParticleAffector->setMaxDistance(1000.0); ExampleDistanceAttractRepelParticleAffector->setQuadratic(0.0); ExampleDistanceAttractRepelParticleAffector->setLinear(100.0); ExampleDistanceAttractRepelParticleAffector->setConstant(0.0); ExampleDistanceAttractRepelParticleAffector->setParticleSystemNode(ParticleNode); ExampleDistanceAttractRepelParticleAffector->setDistanceFromSource(DistanceAttractRepelParticleAffector::DISTANCE_FROM_NODE); ExampleDistanceAttractRepelParticleAffector->setDistanceFromNode(AttractionNode); ExampleParticleSystem->pushToAffectors(ExampleDistanceAttractRepelParticleAffector); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "11DistanceAttractRepelParticleAffector"); //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 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(1.0f); 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); PSMaterialChunk->setLit(false); ChunkMaterialRefPtr PSMaterial = ChunkMaterial::create(); PSMaterial->addChunk(PSLineChunk); PSMaterial->addChunk(PSMaterialChunk); PSMaterial->addChunk(PSBlendChunk); //Particle System ParticleSystemRefPtr ExampleParticleSystem = ParticleSystem::create(); ExampleParticleSystem->attachUpdateListener(TutorialWindow); //Create the particles 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; }
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, ExampleParticleSystem.get(), ExampleBurstGenerator.get(), ExampleParticleSystemDrawer.get())); sceneManager.setRoot(scene); //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, "05QuadParticleDrawer"); //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 //point 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(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 PSPointMaterial = ChunkMaterial::create(); PSPointMaterial->addChunk(PSPointChunk); PSPointMaterial->addChunk(PSMaterialChunkChunk); PSPointMaterial->addChunk(PSBlendChunk); //smoke material TextureObjChunkRefPtr QuadTextureObjChunk = TextureObjChunk::create(); ImageRefPtr LoadedImage = ImageFileHandler::the()->read("Data/Checker.jpg"); QuadTextureObjChunk->setImage(LoadedImage); TextureEnvChunkRefPtr QuadTextureEnvChunk = TextureEnvChunk::create(); QuadTextureEnvChunk->setEnvMode(GL_MODULATE); 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 PSSmokeMaterial = ChunkMaterial::create(); PSSmokeMaterial->addChunk(QuadTextureObjChunk); PSSmokeMaterial->addChunk(PSMaterialChunk); PSSmokeMaterial->addChunk(PSMaterialChunk); PSSmokeMaterial->addChunk(QuadTextureEnvChunk); //Particle System //Rocket RocketParticleSystem = OSG::ParticleSystem::create(); RocketParticleSystem->attachUpdateListener(TutorialWindow); TutorialRocketParticleSystemListener TheRocketListener; RocketParticleSystem->addParticleSystemListener(&TheRocketListener); //smoke SmokeParticleSystem = OSG::ParticleSystem::create(); SmokeParticleSystem->attachUpdateListener(TutorialWindow); //Shrapnel ShrapnelParticleSystem = OSG::ParticleSystem::create(); ShrapnelParticleSystem->attachUpdateListener(TutorialWindow); //Fireball FireballParticleSystem = OSG::ParticleSystem::create(); FireballParticleSystem->attachUpdateListener(TutorialWindow); //Particle System Drawer //Rocket does not have a drawer because it is being attached to a special node core //Smoke SmokeParticleSystemDrawer = OSG::QuadParticleSystemDrawer::create(); //SmokeParticleSystemDrawer->setQuadSizeScaling(Vec2f(0.5f,0.5f)); //Shrapnel ExampleShrapnelParticleSystemDrawer = OSG::PointParticleSystemDrawer::create(); ExampleShrapnelParticleSystemDrawer->setForcePerParticleSizing(true); //Fireball ExampleFireballParticleSystemDrawer = OSG::PointParticleSystemDrawer::create(); ExampleFireballParticleSystemDrawer->setForcePerParticleSizing(true); //Particle System Node //collision node //NodeRefPtr EnvironmentNode = makeSphere(2,4.0f); Matrix EnvironmentTransformation; EnvironmentTransformation.setScale(0.1f); TransformRefPtr EnvironmentTransformCore = Transform::create(); EnvironmentTransformCore->setMatrix(EnvironmentTransformation); NodeRefPtr EnvironmentNode = Node::create(); EnvironmentNode->setCore(EnvironmentTransformCore); //EnvironmentNode->addChild(SceneFileHandler::the()->read("Data/Chloroplast.osb")); EnvironmentNode->addChild(SceneFileHandler::the()->read("Data/house.obj")); //NodeRefPtr ParticlePrototypeNode = makeTorus(1.0,4.0,16,16); NodeRefPtr RocketParticlePrototypeNode = SceneFileHandler::the()->read("Data/rocket.obj"); if(RocketParticlePrototypeNode == NULL) { RocketParticlePrototypeNode = makeTorus(.5, 2, 16, 16); } NodeParticleSystemCoreRefPtr RocketParticleNodeCore = OSG::NodeParticleSystemCore::create(); RocketParticleNodeCore->setSystem(RocketParticleSystem); RocketParticleNodeCore->setPrototypeNode(RocketParticlePrototypeNode); RocketParticleNodeCore->setNormalSource(NodeParticleSystemCore::NORMAL_VELOCITY); RocketParticleNodeCore->setUpSource(NodeParticleSystemCore::UP_PARTICLE_NORMAL); RocketParticleNodeCore->setUp(Vec3f(0.0f,1.0f,0.0f)); //Geometry Collision Affector GeometryCollisionParticleSystemAffectorRefPtr ExampleGeometryCollisionParticleSystemAffector = GeometryCollisionParticleSystemAffector::create(); ExampleGeometryCollisionParticleSystemAffector->setCollisionNode(EnvironmentNode); TutorialParticleCollisionListener TheCollisionListener; ExampleGeometryCollisionParticleSystemAffector->addParticleGeometryCollisionListener(&TheCollisionListener); NodeRefPtr RocketParticleNode = OSG::Node::create(); RocketParticleNode->setCore(RocketParticleNodeCore); //Attach the Affector to the Rocket Particle System //RocketParticleSystem->pushToAffectors(); RocketParticleSystem->pushToSystemAffectors(ExampleGeometryCollisionParticleSystemAffector); //Smoke SmokeGenerator = OSG::RateParticleGenerator::create(); //Attach the function objects to the Generator SmokePositionDistribution = createSmokePositionDistribution(); SmokeGenerator->setPositionDistribution(SmokePositionDistribution); SmokeGenerator->setLifespanDistribution(createSmokeLifespanDistribution()); SmokeGenerator->setGenerationRate(50.0); SmokeGenerator->setVelocityDistribution(createSmokeVelocityDistribution()); //Attach the function objects the Affectors SmokeAgeFadeParticleAffector = OSG::AgeFadeParticleAffector::create(); SmokeAgeFadeParticleAffector->setFadeInTime(2.0f); SmokeAgeFadeParticleAffector->setFadeOutTime(5.0f); SmokeAgeFadeParticleAffector->setStartAlpha(0.0f); SmokeAgeFadeParticleAffector->setFadeToAlpha(0.2f); SmokeAgeFadeParticleAffector->setEndAlpha(0.0f); SmokeAgeSizeParticleAffector = OSG::AgeSizeParticleAffector::create(); //ages SmokeAgeSizeParticleAffector->editMFAges()->push_back(0.1); SmokeAgeSizeParticleAffector->editMFAges()->push_back(0.2); SmokeAgeSizeParticleAffector->editMFAges()->push_back(0.3); SmokeAgeSizeParticleAffector->editMFAges()->push_back(0.5); SmokeAgeSizeParticleAffector->editMFAges()->push_back(0.7); SmokeAgeSizeParticleAffector->editMFAges()->push_back(0.8); SmokeAgeSizeParticleAffector->editMFAges()->push_back(1.0); //sizes SmokeAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(0.5,0.5,0.5)); SmokeAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(1.0,1.0,1.0)); SmokeAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(2.0,2.0,2.0)); SmokeAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(3.0,3.0,3.0)); SmokeAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(4.0,4.0,4.0)); SmokeAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(5.0,5.0,5.0)); SmokeAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(6.5,6.5,6.5)); ParticleSystemCoreRefPtr SmokeParticleNodeCore = OSG::ParticleSystemCore::create(); SmokeParticleNodeCore->setSystem(SmokeParticleSystem); SmokeParticleNodeCore->setDrawer(SmokeParticleSystemDrawer); SmokeParticleNodeCore->setMaterial(PSSmokeMaterial); NodeRefPtr SmokeParticleNode = OSG::Node::create(); SmokeParticleNode->setCore(SmokeParticleNodeCore); //end///////////////////// //Shrapnel ShrapnelBurstGenerator = OSG::BurstParticleGenerator::create(); NodeRefPtr ShrapnelParticlePrototypeNode = SceneFileHandler::the()->read("Data/Shrapnel.obj"); NodeParticleSystemCoreRefPtr ShrapnelParticleNodeCore = OSG::NodeParticleSystemCore::create(); ShrapnelParticleNodeCore->setSystem(ShrapnelParticleSystem); ShrapnelParticleNodeCore->setPrototypeNode(ShrapnelParticlePrototypeNode); //Attach the function objects to the Generator ShrapnelPositionDistribution = createShrapnelPositionDistribution(); ShrapnelBurstGenerator->setPositionDistribution(ShrapnelPositionDistribution); ShrapnelBurstGenerator->setLifespanDistribution(createLifespanDistribution()); ShrapnelBurstGenerator->setBurstAmount(50.0); ShrapnelBurstGenerator->setVelocityDistribution(createShrapnelVelocityDistribution()); ShrapnelBurstGenerator->setAccelerationDistribution(createShrapnelAccelerationDistribution()); NodeRefPtr ShrapnelParticleNode = OSG::Node::create(); ShrapnelParticleNode->setCore(ShrapnelParticleNodeCore); //end///////////////////// //fireball FireballGenerator = OSG::BurstParticleGenerator::create(); NodeRefPtr FireballParticlePrototypeNode = SceneFileHandler::the()->read("Data/bubble.obj"); NodeParticleSystemCoreRefPtr FireballParticleNodeCore = OSG::NodeParticleSystemCore::create(); FireballParticleNodeCore->setSystem(FireballParticleSystem); FireballParticleNodeCore->setPrototypeNode(FireballParticlePrototypeNode); //Attach the function objects to the Generator FireballPositionDistribution = createFireballPositionDistribution(); FireballGenerator->setPositionDistribution(FireballPositionDistribution); FireballGenerator->setLifespanDistribution(createFireballLifespanDistribution()); FireballGenerator->setBurstAmount(100.0); FireballGenerator->setVelocityDistribution(createFireballVelocityDistribution()); FireballGenerator->setAccelerationDistribution(createFireballAccelerationDistribution()); //Attach the function objects the Affectors FireballAgeSizeParticleAffector = OSG::AgeSizeParticleAffector::create(); //ages FireballAgeSizeParticleAffector->editMFAges()->push_back(0.1); FireballAgeSizeParticleAffector->editMFAges()->push_back(0.2); FireballAgeSizeParticleAffector->editMFAges()->push_back(0.3); FireballAgeSizeParticleAffector->editMFAges()->push_back(0.5); FireballAgeSizeParticleAffector->editMFAges()->push_back(0.7); FireballAgeSizeParticleAffector->editMFAges()->push_back(0.8); FireballAgeSizeParticleAffector->editMFAges()->push_back(1.0); //sizes FireballAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(2.0,2.0,2.0)); FireballAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(2.3,2.3,2.3)); FireballAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(2.5,2.5,2.5)); FireballAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(3.0,3.0,3.0)); FireballAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(4.0,4.0,4.0)); FireballAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(5.0,5.0,5.0)); FireballAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(6.5,6.5,6.5)); NodeRefPtr FireballParticleNode = OSG::Node::create(); FireballParticleNode->setCore(FireballParticleNodeCore); //end///////////////////// // Make Main Scene Node NodeRefPtr scene = OSG::Node::create(); scene->setCore(OSG::Group::create()); scene->addChild(RocketParticleNode); scene->addChild(SmokeParticleNode); scene->addChild(ShrapnelParticleNode); scene->addChild(FireballParticleNode); scene->addChild(EnvironmentNode); mgr->setRoot(scene); mgr->getNavigator()->set(Pnt3f(0.0,0.0,0.0), Pnt3f(0.0,0.0,-1.0), Vec3f(0.0,1.0,0.0)); mgr->getNavigator()->setMotionFactor(1.0f); mgr->getCamera()->setNear(0.1f); mgr->getCamera()->setFar(1000.0f); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "10RocketLauncher"); //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 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(), ExampleRMA.get(), ExampleAttributeAttractRepelParticleAffector.get())); sceneManager.setRoot(scene); // 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, "17RandomMovement"); //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(20.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->setColorMaterial(GL_AMBIENT_AND_DIFFUSE); //enable depth test DepthChunkRefPtr PSDepthChunk = DepthChunk::create(); ChunkMaterialRefPtr PSMaterial = ChunkMaterial::create(); PSMaterial->addChunk(PSPointChunk); PSMaterial->addChunk(PSMaterialChunkChunk); PSMaterial->addChunk(PSBlendChunk); PSMaterial->addChunk(PSDepthChunk); LineChunkRefPtr PSLineChunk = LineChunk::create(); ChunkMaterialRefPtr TestMaterial = ChunkMaterial::create(); //TestMaterial->addChunk(PointChunk::create()); //TestMaterial->addChunk(LineChunk::create()); TestMaterial->addChunk(PSMaterialChunkChunk); PolygonChunkRefPtr ThePolygonChunk = PolygonChunk::create(); BlendChunkRefPtr TheBlendChunk = BlendChunk::create(); DepthChunkRefPtr TheDepthChunk = DepthChunk::create(); TestMaterial->addChunk(ThePolygonChunk); TestMaterial->addChunk(TheBlendChunk); TestMaterial->addChunk(TheDepthChunk); //Particle System ParticleSystemRecPtr ExampleParticleSystem = ParticleSystem::create(); ExampleParticleSystem->attachUpdateProducer(TutorialWindow); ExampleParticleSystem->addParticle(Pnt3f(-40.0,0.0,0.0), Vec3f(0.0,1.0,0.0), Color4f(1.0,1.0,1.0,1.0), Vec3f(1.0,1.0,1.0), -1, Vec3f(0.0,0.0,0.0), Vec3f(0.0,0.0,0.0)); ExampleParticleSystem->addParticle(Pnt3f(40.0,0.0,0.0), Vec3f(0.0,1.0,0.0), Color4f(1.0,1.0,1.0,1.0), Vec3f(1.0,1.0,1.0), -1, Vec3f(0.0,0.0,0.0), Vec3f(0.0,0.0,0.0)); PointParticleSystemDrawerRecPtr ExamplePointParticleSystemDrawer = PointParticleSystemDrawer::create(); ExamplePointParticleSystemDrawer->setForcePerParticleSizing(false); Matrix ExampleMatrix; ExampleMatrix.setTransform(Vec3f(10.0,10.0,10.0)); TransformRefPtr ExampleXform = Transform::create(); ExampleXform->setMatrix(ExampleMatrix); NodeRefPtr ExampleNode = Node::create(); ExampleNode->setCore(ExampleXform); RateParticleGeneratorRecPtr ExampleGenerator = RateParticleGenerator::create(); // ExampleGenerator->setEmitInWorldSpace(true); ExampleGenerator->setBeacon(ExampleNode); ExampleGenerator->setGenerationRate(5.0); ExampleGenerator->setPositionDistribution(createPositionDistribution()); ExampleGenerator->setLifespanDistribution(createLifespanDistribution()); NewtonParticleAffectorRefPtr ExampleAffector = NewtonParticleAffector::create(); ExampleAffector->setBeacon(ExampleNode); ExampleAffector->setMaxDistance(-1.0); ConditionalParticleAffectorRecPtr ExampleConditionalAffector = ConditionalParticleAffector::create(); ExampleConditionalAffector->setConditionalAttribute("active"); ExampleConditionalAffector->setConditionalOperator(4); //greater than ExampleConditionalAffector->setConditionalValue(0); // testing if the value associated with "test" = 1 ExampleConditionalAffector->pushToAffectors(ExampleAffector); DistanceAttractRepelParticleAffectorRefPtr ExampleAttractRepelAffector = DistanceAttractRepelParticleAffector::create(); ExampleAttractRepelAffector->setDistanceFromSource(DistanceParticleAffector::DISTANCE_FROM_NODE); //Attach the Generators and affectors to the Particle System ExampleParticleSystem->setBeacon(ExampleNode); //ExampleParticleSystem->pushToGenerators(ExampleGenerator); ExampleParticleSystem->pushToAffectors(ExampleConditionalAffector); // ExampleParticleSystem->pushToAffectors(ExampleAttractRepelAffector); ExampleParticleSystem->setMaxParticles(1000); ExampleParticleSystem->setDynamic(true); //Particle System Core ParticleSystemCoreRecPtr ParticleNodeCore = ParticleSystemCore::create(); ParticleNodeCore->setSystem(ExampleParticleSystem); ParticleNodeCore->setDrawer(ExamplePointParticleSystemDrawer); ParticleNodeCore->setMaterial(PSMaterial); ParticleNodeCore->setSortingMode(ParticleSystemCore::BACK_TO_FRONT); NodeRefPtr PSNode = Node::create(); PSNode->setCore(ParticleNodeCore); // Make Main Scene Node and add the Torus NodeRefPtr scene = Node::create(); scene->setCore(Group::create()); scene->addChild(PSNode); TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1, &sceneManager, ParticleNodeCore.get(), ExamplePointParticleSystemDrawer.get(), ExampleParticleSystem.get(), ExampleConditionalAffector.get())); sceneManager.setRoot(scene); // Show the whole Scene sceneManager.showAll(); sceneManager.getCamera()->setFar(1000.0); sceneManager.getCamera()->setNear(0.10); FCFileType::FCPtrStore Containers; Containers.insert(scene); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "16FullTest"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
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->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager)); TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager)); TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager)); TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1, &sceneManager)); //Particle System Material //point 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(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 PSPointMaterial = ChunkMaterial::create(); PSPointMaterial->addChunk(PSPointChunk); PSPointMaterial->addChunk(PSMaterialChunkChunk); PSPointMaterial->addChunk(PSBlendChunk); //smoke material TextureObjChunkRefPtr QuadTextureObjChunk = TextureObjChunk::create(); ImageRefPtr LoadedImage = ImageFileHandler::the()->read("Data/Smoke.png"); QuadTextureObjChunk->setImage(LoadedImage); TextureEnvChunkRefPtr QuadTextureEnvChunk = TextureEnvChunk::create(); QuadTextureEnvChunk->setEnvMode(GL_MODULATE); 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 PSSmokeMaterial = ChunkMaterial::create(); PSSmokeMaterial->addChunk(QuadTextureObjChunk); PSSmokeMaterial->addChunk(PSMaterialChunk); PSSmokeMaterial->addChunk(PSBlendChunk); PSSmokeMaterial->addChunk(QuadTextureEnvChunk); //Particle System //Rocket ParticleSystemRecPtr RocketParticleSystem = ParticleSystem::create(); RocketParticleSystem->attachUpdateProducer(TutorialWindow); //smoke ParticleSystemRecPtr SmokeParticleSystem = ParticleSystem::create(); SmokeParticleSystem->attachUpdateProducer(TutorialWindow); //Shrapnel ParticleSystemRecPtr ShrapnelParticleSystem = ParticleSystem::create(); ShrapnelParticleSystem->attachUpdateProducer(TutorialWindow); //Fireball ParticleSystemRecPtr FireballParticleSystem = ParticleSystem::create(); FireballParticleSystem->attachUpdateProducer(TutorialWindow); //Particle System Drawer //Rocket does not have a drawer because it is being attached to a special node core //Smoke QuadParticleSystemDrawerRecPtr SmokeParticleSystemDrawer = QuadParticleSystemDrawer::create(); //SmokeParticleSystemDrawer->setQuadSizeScaling(Vec2f(0.5f,0.5f)); //Shrapnel PointParticleSystemDrawerRecPtr ExampleShrapnelParticleSystemDrawer = PointParticleSystemDrawer::create(); ExampleShrapnelParticleSystemDrawer->setForcePerParticleSizing(true); //Fireball PointParticleSystemDrawerRecPtr ExampleFireballParticleSystemDrawer = PointParticleSystemDrawer::create(); ExampleFireballParticleSystemDrawer->setForcePerParticleSizing(true); //Particle System Node //collision node //NodeRefPtr EnvironmentNode = makeSphere(2,4.0f); Matrix EnvironmentTransformation; EnvironmentTransformation.setTranslate(0.0f,0.0f,10.0f); TransformRefPtr EnvironmentTransformCore = Transform::create(); EnvironmentTransformCore->setMatrix(EnvironmentTransformation); NodeRefPtr EnvironmentNode = Node::create(); EnvironmentNode->setCore(EnvironmentTransformCore); NodeRefPtr EnvironmentGeoNode = SceneFileHandler::the()->read("Data/house.obj"); if(EnvironmentGeoNode == NULL) { EnvironmentGeoNode = makeTorus(.5, 2, 16, 16); } EnvironmentNode->addChild(EnvironmentGeoNode); NodeRefPtr RocketParticlePrototypeNode = SceneFileHandler::the()->read("Data/rocket.obj"); if(RocketParticlePrototypeNode == NULL) { RocketParticlePrototypeNode = makeTorus(.2, 0.8, 16, 16); } NodeParticleSystemCoreRefPtr RocketParticleNodeCore = NodeParticleSystemCore::create(); RocketParticleNodeCore->setSystem(RocketParticleSystem); RocketParticleNodeCore->setPrototypeNode(RocketParticlePrototypeNode); RocketParticleNodeCore->setNormalSource(NodeParticleSystemCore::NORMAL_VELOCITY); RocketParticleNodeCore->setUpSource(NodeParticleSystemCore::UP_PARTICLE_NORMAL); RocketParticleNodeCore->setUp(Vec3f(0.0f,1.0f,0.0f)); //Geometry Collision Affector GeometryCollisionParticleSystemAffectorRefPtr ExampleGeometryCollisionParticleSystemAffector = GeometryCollisionParticleSystemAffector::create(); ExampleGeometryCollisionParticleSystemAffector->setCollisionNode(EnvironmentNode); ExampleGeometryCollisionParticleSystemAffector->connectParticleCollision(boost::bind(particleCollision, _1)); NodeRefPtr RocketParticleNode = Node::create(); RocketParticleNode->setCore(RocketParticleNodeCore); //Attach the Affector to the Rocket Particle System //RocketParticleSystem->pushToAffectors(); RocketParticleSystem->pushToSystemAffectors(ExampleGeometryCollisionParticleSystemAffector); //Smoke RateParticleGeneratorRecPtr SmokeGenerator = RateParticleGenerator::create(); //Attach the function objects to the Generator Distribution3DRefPtr SmokePositionDistribution = createSmokePositionDistribution(); SmokeGenerator->setPositionDistribution(SmokePositionDistribution); SmokeGenerator->setLifespanDistribution(createSmokeLifespanDistribution()); SmokeGenerator->setGenerationRate(50.0); SmokeGenerator->setVelocityDistribution(createSmokeVelocityDistribution()); //Attach the function objects the Affectors AgeFadeParticleAffectorRecPtr SmokeAgeFadeParticleAffector = AgeFadeParticleAffector::create(); SmokeAgeFadeParticleAffector->setFadeInTime(2.0f); SmokeAgeFadeParticleAffector->setFadeOutTime(5.0f); SmokeAgeFadeParticleAffector->setStartAlpha(0.0f); SmokeAgeFadeParticleAffector->setFadeToAlpha(0.2f); SmokeAgeFadeParticleAffector->setEndAlpha(0.0f); AgeSizeParticleAffectorRecPtr SmokeAgeSizeParticleAffector = AgeSizeParticleAffector::create(); //ages SmokeAgeSizeParticleAffector->editMFAges()->push_back(0.1); SmokeAgeSizeParticleAffector->editMFAges()->push_back(0.2); SmokeAgeSizeParticleAffector->editMFAges()->push_back(0.3); SmokeAgeSizeParticleAffector->editMFAges()->push_back(0.5); SmokeAgeSizeParticleAffector->editMFAges()->push_back(0.7); SmokeAgeSizeParticleAffector->editMFAges()->push_back(0.8); SmokeAgeSizeParticleAffector->editMFAges()->push_back(1.0); //sizes SmokeAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(0.5,0.5,0.5)); SmokeAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(1.0,1.0,1.0)); SmokeAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(2.0,2.0,2.0)); SmokeAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(3.0,3.0,3.0)); SmokeAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(4.0,4.0,4.0)); SmokeAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(5.0,5.0,5.0)); SmokeAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(6.5,6.5,6.5)); ParticleSystemCoreRefPtr SmokeParticleNodeCore = ParticleSystemCore::create(); SmokeParticleNodeCore->setSystem(SmokeParticleSystem); SmokeParticleNodeCore->setDrawer(SmokeParticleSystemDrawer); SmokeParticleNodeCore->setMaterial(PSSmokeMaterial); NodeRefPtr SmokeParticleNode = Node::create(); SmokeParticleNode->setCore(SmokeParticleNodeCore); //end///////////////////// //Shrapnel BurstParticleGeneratorRecPtr ShrapnelBurstGenerator = BurstParticleGenerator::create(); NodeRefPtr ShrapnelParticlePrototypeNode = SceneFileHandler::the()->read("Data/Shrapnel.obj"); NodeParticleSystemCoreRefPtr ShrapnelParticleNodeCore = NodeParticleSystemCore::create(); ShrapnelParticleNodeCore->setSystem(ShrapnelParticleSystem); ShrapnelParticleNodeCore->setPrototypeNode(ShrapnelParticlePrototypeNode); //Attach the function objects to the Generator Distribution3DRefPtr ShrapnelPositionDistribution = createShrapnelPositionDistribution(); ShrapnelBurstGenerator->setPositionDistribution(ShrapnelPositionDistribution); ShrapnelBurstGenerator->setLifespanDistribution(createLifespanDistribution()); ShrapnelBurstGenerator->setBurstAmount(50.0); ShrapnelBurstGenerator->setVelocityDistribution(createShrapnelVelocityDistribution()); ShrapnelBurstGenerator->setAccelerationDistribution(createShrapnelAccelerationDistribution()); NodeRefPtr ShrapnelParticleNode = Node::create(); ShrapnelParticleNode->setCore(ShrapnelParticleNodeCore); //end///////////////////// //fireball BurstParticleGeneratorRecPtr FireballGenerator = BurstParticleGenerator::create(); NodeRefPtr FireballParticlePrototypeNode = SceneFileHandler::the()->read("Data/bubble.obj"); NodeParticleSystemCoreRefPtr FireballParticleNodeCore = NodeParticleSystemCore::create(); FireballParticleNodeCore->setSystem(FireballParticleSystem); FireballParticleNodeCore->setPrototypeNode(FireballParticlePrototypeNode); //Attach the function objects to the Generator Distribution3DRefPtr FireballPositionDistribution = createFireballPositionDistribution(); FireballGenerator->setPositionDistribution(FireballPositionDistribution); FireballGenerator->setLifespanDistribution(createFireballLifespanDistribution()); FireballGenerator->setBurstAmount(100.0); FireballGenerator->setVelocityDistribution(createFireballVelocityDistribution()); FireballGenerator->setAccelerationDistribution(createFireballAccelerationDistribution()); //Attach the function objects the Affectors AgeSizeParticleAffectorRecPtr FireballAgeSizeParticleAffector = AgeSizeParticleAffector::create(); //ages FireballAgeSizeParticleAffector->editMFAges()->push_back(0.1); FireballAgeSizeParticleAffector->editMFAges()->push_back(0.2); FireballAgeSizeParticleAffector->editMFAges()->push_back(0.3); FireballAgeSizeParticleAffector->editMFAges()->push_back(0.5); FireballAgeSizeParticleAffector->editMFAges()->push_back(0.7); FireballAgeSizeParticleAffector->editMFAges()->push_back(0.8); FireballAgeSizeParticleAffector->editMFAges()->push_back(1.0); //sizes FireballAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(2.0,2.0,2.0)); FireballAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(2.3,2.3,2.3)); FireballAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(2.5,2.5,2.5)); FireballAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(3.0,3.0,3.0)); FireballAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(4.0,4.0,4.0)); FireballAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(5.0,5.0,5.0)); FireballAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(6.5,6.5,6.5)); NodeRefPtr FireballParticleNode = Node::create(); FireballParticleNode->setCore(FireballParticleNodeCore); //end///////////////////// //Attach the Affector to the Smoke Particle System SmokeParticleSystem->pushToAffectors(SmokeAgeFadeParticleAffector); SmokeParticleSystem->pushToAffectors(SmokeAgeSizeParticleAffector); //Attach the Affector to the fireball Particle System FireballParticleSystem->pushToAffectors(FireballAgeSizeParticleAffector); // Make Main Scene Node NodeRefPtr scene = Node::create(); scene->setCore(Group::create()); scene->addChild(RocketParticleNode); scene->addChild(SmokeParticleNode); scene->addChild(ShrapnelParticleNode); scene->addChild(FireballParticleNode); scene->addChild(EnvironmentNode); RocketParticleSystem->connectParticleKilled(boost::bind(particleKilled, _1, ShrapnelParticleSystem.get(), ShrapnelBurstGenerator.get(), SmokeParticleSystem.get(), SmokeGenerator.get(), FireballParticleSystem.get(), FireballGenerator.get())); TutorialWindow->connectMousePressed(boost::bind(mousePressed, _1, &sceneManager, RocketParticleSystem.get())); sceneManager.setRoot(scene); //Create the Documentation SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow); sceneManager.getNavigator()->set(Pnt3f(0.0,0.0,-10.0), Pnt3f(0.0,0.0,0.0), Vec3f(0.0,1.0,0.0)); sceneManager.getNavigator()->setMotionFactor(1.0f); sceneManager.getCamera()->setNear(0.1f); sceneManager.getCamera()->setFar(1000.0f); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "20RocketLauncher"); //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 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"); //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); //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(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; }
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(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(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); ChunkMaterialRefPtr PSMaterial = ChunkMaterial::create(); PSMaterial->addChunk(PSPointChunk); PSMaterial->addChunk(PSMaterialChunkChunk); PSMaterial->addChunk(PSBlendChunk); //Particle System ParticleSystemRefPtr 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->attachUpdateListener(TutorialWindow); //Particle System Drawer //Point ExamplePointParticleSystemDrawer = PointParticleSystemDrawer::create(); //ExamplePointParticleSystemDrawer->setForcePerParticleSizing(true); //Line ExampleLineParticleSystemDrawer = LineParticleSystemDrawer::create(); ExampleLineParticleSystemDrawer->setLineDirectionSource(LineParticleSystemDrawer::DIRECTION_NORMAL);//DIRECTION_VELOCITY_CHANGE); ExampleLineParticleSystemDrawer->setLineLengthSource(LineParticleSystemDrawer::LENGTH_SIZE_X); //Quad ExampleQuadParticleSystemDrawer = QuadParticleSystemDrawer::create(); //Disc ExampleDiscParticleSystemDrawer = DiscParticleSystemDrawer::create(); ExampleDiscParticleSystemDrawer->setSegments(16); ExampleDiscParticleSystemDrawer->setCenterAlpha(1.0); ExampleDiscParticleSystemDrawer->setEdgeAlpha(0.0); //Particle System Node ParticleNodeCore = ParticleSystemCore::create(); ParticleNodeCore->setSystem(ExampleParticleSystem); ParticleNodeCore->setDrawer(ExampleLineParticleSystemDrawer); 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); 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, "01ParticleSystemDrawers"); commitChanges(); //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 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); 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, "03RateParticleGenerator"); //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)); TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _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(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); Distribution3DRefPtr PositionDistribution = createPositionDistribution(); Pnt3f PositionReturnValue; //Particle System ParticleSystemRefPtr 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, Vec3f(0.0f,0.0f,1.0f), Color4f(1.0,0.0,0.0,1.0), Vec3f(1.0,1.0,1.0), -1, Vec3f(0.0f,0.0f,0.0f), //Velocity Vec3f(0.0f,0.0f,0.0f) //acceleration ); } ExampleParticleSystem->attachUpdateProducer(TutorialWindow); //Particle System Drawer PointParticleSystemDrawerRefPtr ExampleParticleSystemDrawer = PointParticleSystemDrawer::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 and add the Torus NodeRefPtr scene = Node::create(); scene->setCore(Group::create()); scene->addChild(ParticleNode); sceneManager.setRoot(scene); // Show the whole Scene sceneManager.showAll(); //Create an DistanceKill DistanceKillParticleAffectorRefPtr ExampleDistanceKillParticleAffector = DistanceKillParticleAffector::create(); ExampleDistanceKillParticleAffector->setKillDistance(1000.0f); ExampleDistanceKillParticleAffector->setParticleSystemNode(ParticleNode); ExampleDistanceKillParticleAffector->setDistanceFromSource(DistanceKillParticleAffector::DISTANCE_FROM_CAMERA); ExampleDistanceKillParticleAffector->setDistanceFromCamera(sceneManager.getCamera()); ExampleParticleSystem->pushToAffectors(ExampleDistanceKillParticleAffector); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "09DistanceKillParticleAffector"); //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; }