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; }
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; }
// Initialize GLUT & OpenSG and set up the scene int main(int argc, char **argv) { // OSG init osgInit(argc,argv); { // Set up Window WindowEventProducerRecPtr TutorialWindow = createNativeWindow(); //Initialize Window TutorialWindow->initWindow(); 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)); BoostPath FilePath("../Animation/Data/Nanobot.dae"); if(argc >= 2) { FilePath = BoostPath(argv[1]); if(!boost::filesystem::exists(FilePath)) { std::cerr << "Could not load file: "<< FilePath.string() << ", because no such files exists."<< std::endl; FilePath = BoostPath("../Animation/Data/Nanobot.dae"); } } NodeRefPtr LoadedRoot; std::vector<AnimationRecPtr> LoadedAnimations; FCFileType::FCPtrStore ObjStore; try { ObjStore = FCFileHandler::the()->read(FilePath); } catch(std::exception &ex) { std::cerr << "Failed to load file: " << FilePath.string() << ", error:" << ex.what() << std::endl; return -1; } for(FCFileType::FCPtrStore::iterator StorItor(ObjStore.begin()); StorItor != ObjStore.end(); ++StorItor) { //Animations if((*StorItor)->getType().isDerivedFrom(Animation::getClassType())) { LoadedAnimations.push_back(dynamic_pointer_cast<Animation>(*StorItor)); LoadedAnimations.back()->attachUpdateProducer(TutorialWindow); LoadedAnimations.back()->start(); } //Root Node if((*StorItor)->getType() == Node::getClassType() && dynamic_pointer_cast<Node>(*StorItor)->getParent() == NULL) { LoadedRoot = dynamic_pointer_cast<Node>(*StorItor); } } if(LoadedRoot == NULL) { LoadedRoot = SceneFileHandler::the()->read(FilePath.string().c_str()); } if(LoadedRoot == NULL) { LoadedRoot= makeTorus(.5, 2, 32, 32); } //Make the fog node PostShaderStageRecPtr PostShaderStageCore = PostShaderStage::create(); PostShaderStageCore->clearPasses(); PostShaderStageCore->addPass("", generateNoEffectProg()); DirectionalLightRecPtr SceneLightCore = DirectionalLight::create(); SceneLightCore->setAmbient(Color4f(0.2f, 0.2f, 0.2f, 1.0f)); SceneLightCore->setDiffuse(Color4f(0.8f, 0.8f, 0.8f, 1.0f)); SceneLightCore->setSpecular(Color4f(1.0f, 1.0f, 1.0f, 1.0f)); NodeRefPtr SceneLight = makeNodeFor(SceneLightCore); SceneLight->addChild(LoadedRoot); NodeRefPtr PostShaderStageNode = makeNodeFor(PostShaderStageCore); PostShaderStageNode->addChild(SceneLight); //Make Main Scene Node NodeRefPtr scene = makeCoredNode<Group>(); scene->addChild(PostShaderStageNode); // tell the manager what to manage sceneManager.setRoot (scene); SceneLightCore->setBeacon(sceneManager.getCamera()->getBeacon()); //Create the Documentation Foreground and add it to the viewport SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow); // show the whole scene sceneManager.showAll(); sceneManager.getWindow()->getPort(0)->setTravMask(1); RenderOptionsRecPtr ViewportRenderOptions = RenderOptions::create(); ViewportRenderOptions->setRenderProperties(0x0); ViewportRenderOptions->setRenderProperties(RenderPropertiesPool::the()->getFrom1("Default")); ViewportRenderOptions->setRenderProperties(0x01); sceneManager.getWindow()->getPort(0)->setRenderOptions(ViewportRenderOptions); Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "Collada Loader"); TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1, TutorialWindow.get(), PostShaderStageCore.get())); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
// Initialize GLUT & OpenSG and set up the rootNode 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->connectKeyReleased(boost::bind(keyReleased, _1)); //Make Main Scene Node NodeRefPtr scene = makeCoredNode<Group>(); setName(scene, "scene"); NodeRecPtr rootNode = Node::create(); setName(rootNode, "rootNode"); ComponentTransformRefPtr Trans = ComponentTransform::create(); rootNode->setCore(Trans); rootNode->addChild(scene); //Light Beacon Matrix LightTransformMat; LightTransformMat.setTranslate(Vec3f(50.0,0.0,100.0)); TransformRefPtr LightTransform = Transform::create(); LightTransform->setMatrix(LightTransformMat); NodeRefPtr TutorialLightBeacon = Node::create(); TutorialLightBeacon->setCore(LightTransform); //Light Node PointLightRefPtr TutorialLight = PointLight::create(); TutorialLight->setBeacon(TutorialLightBeacon); NodeRefPtr TutorialLightNode = Node::create(); TutorialLightNode->setCore(TutorialLight); scene->addChild(TutorialLightNode); scene->addChild(TutorialLightBeacon); //Setup Physics Scene PhysicsWorldRecPtr physicsWorld = PhysicsWorld::create(); physicsWorld->setWorldContactSurfaceLayer(0.005); physicsWorld->setAutoDisableFlag(1); physicsWorld->setAutoDisableTime(0.75); physicsWorld->setWorldContactMaxCorrectingVel(100.0); physicsWorld->setGravity(Vec3f(0.0, 0.0, -9.81)); PhysicsHashSpaceRecPtr physicsSpace = PhysicsHashSpace::create(); //Setup the default collision parameters CollisionContactParametersRefPtr DefaultCollisionParams = CollisionContactParameters::createEmpty(); DefaultCollisionParams->setMode(dContactApprox1); DefaultCollisionParams->setMu(1.0); DefaultCollisionParams->setMu2(0.0); DefaultCollisionParams->setBounce(0.0); DefaultCollisionParams->setBounceSpeedThreshold(0.0); DefaultCollisionParams->setSoftCFM(0.1); DefaultCollisionParams->setSoftERP(0.2); DefaultCollisionParams->setMotion1(0.0); DefaultCollisionParams->setMotion2(0.0); DefaultCollisionParams->setMotionN(0.0); DefaultCollisionParams->setSlip1(0.0); DefaultCollisionParams->setSlip2(0.0); physicsSpace->setDefaultCollisionParameters(DefaultCollisionParams); PhysicsHandlerRecPtr physHandler = PhysicsHandler::create(); physHandler->setWorld(physicsWorld); physHandler->pushToSpaces(physicsSpace); physHandler->setUpdateNode(rootNode); physHandler->attachUpdateProducer(TutorialWindow); rootNode->addAttachment(physHandler); rootNode->addAttachment(physicsWorld); rootNode->addAttachment(physicsSpace); /************************************************************************/ /* create spaces, geoms and bodys */ /************************************************************************/ //create a group for our space GroupRefPtr spaceGroup; NodeRecPtr spaceGroupNode = makeCoredNode<Group>(&spaceGroup); //create the ground terrain GeometryRefPtr TerrainGeo = buildTerrain(Vec2f(400.0,400.0),25,25); //and its Material SimpleMaterialRefPtr TerrainMat = SimpleMaterial::create(); TerrainMat->setAmbient(Color3f(0.3,0.5,0.3)); TerrainMat->setDiffuse(Color3f(0.5,0.9,0.5)); TerrainGeo->setMaterial(TerrainMat); NodeRefPtr TerrainNode = Node::create(); TerrainNode->setCore(TerrainGeo); //create ODE data PhysicsGeomRefPtr TerrainODEGeom = PhysicsTriMeshGeom::create(); //add geom to space for collision TerrainODEGeom->setSpace(physicsSpace); //set the geometryNode to fill the ode-triMesh dynamic_pointer_cast<PhysicsTriMeshGeom>(TerrainODEGeom)->setGeometryNode(TerrainNode); //add attachments //add Attachments to nodes... spaceGroupNode->addAttachment(physicsSpace); spaceGroupNode->addChild(TerrainNode); TerrainNode->addAttachment(TerrainODEGeom); TutorialLightNode->addChild(spaceGroupNode); //Create Character PhysicsBodyRefPtr CharacterPhysicsBody = buildCharacter(Vec3f(5.0,5.0,10.0), Pnt3f((Real32)(rand()%100)-50.0,(Real32)(rand()%100)-50.0,25.0), spaceGroupNode, physicsWorld, physicsSpace); PhysicsLMotorJointRefPtr CharacterMover = buildMover(CharacterPhysicsBody); TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1, spaceGroupNode.get(), physicsWorld.get(), physicsSpace.get())); TutorialWindow->connectUpdate(boost::bind(handleUpdate, _1, CharacterPhysicsBody.get(), CharacterMover.get())); // tell the manager what to manage sceneManager.setRoot (rootNode); // show the whole rootNode sceneManager.showAll(); Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "03CharacterTerrain"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
// Initialize GLUT & OpenSG and set up the scene int main(int argc, char **argv) { OSG::preloadSharedObject("OSGFileIO"); OSG::preloadSharedObject("OSGImageFileIO"); // OSG init osgInit(argc,argv); { // Set up Window WindowEventProducerRecPtr TutorialWindow = createNativeWindow(); //Initialize Window TutorialWindow->initWindow(); 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)); TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1, TutorialWindow.get())); //Box Geometry GeometryUnrecPtr BoxGeometry = makeBoxGeo(1.0,1.0,1.0,1,1,1); ChunkMaterialUnrecPtr TheBoxMaterial = ChunkMaterial::create(); BoxGeometry->setMaterial(TheBoxMaterial); NodeUnrecPtr BoxGeometryNode = Node::create(); BoxGeometryNode->setCore(BoxGeometry); //Make Box Node NodeUnrecPtr BoxNode = Node::create(); TransformUnrecPtr BoxNodeTrans; BoxNodeTrans = Transform::create(); BoxNode->setCore(BoxNodeTrans); BoxNode->addChild(BoxGeometryNode); //Make Main Scene Node NodeUnrecPtr scene = Node::create(); ComponentTransformUnrecPtr Trans; Trans = ComponentTransform::create(); scene->setCore(Trans); // add the torus as a child scene->addChild(BoxNode); //Setup the Animation AnimationUnrecPtr TheAnimation = setupAnimation(TheBoxMaterial); TheAnimation->attachUpdateProducer(TutorialWindow); TheAnimation->start(); // tell the manager what to manage 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, "09TextureSelectAnimation"); //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) { 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 WindowEventProducerRecPtr TutorialWindow = createNativeWindow(); SimpleSceneManager sceneManager; TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager)); TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager)); //Initialize Window TutorialWindow->initWindow(); // 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)); //Print key command info std::cout << "\n\nKEY COMMANDS:" << std::endl; std::cout << "space Play/Pause the animation" << std::endl; std::cout << "B Show/Hide the bind pose skeleton" << std::endl; std::cout << "P Show/Hide the current pose skeleton" << std::endl; //std::cout << "1 Play first example animation" << std::endl; //std::cout << "2 Play second example animation" << std::endl; std::cout << "CTRL-Q Exit\n\n" << std::endl; //SkeletonDrawer System Material LineChunkUnrecPtr ExampleLineChunk = LineChunk::create(); ExampleLineChunk->setWidth(2.0f); ExampleLineChunk->setSmooth(true); BlendChunkUnrecPtr ExampleBlendChunk = BlendChunk::create(); ExampleBlendChunk->setSrcFactor(GL_SRC_ALPHA); ExampleBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA); MaterialChunkUnrecPtr ExampleMaterialChunk = MaterialChunk::create(); ExampleMaterialChunk->setAmbient(Color4f(1.0f,1.0f,1.0f,1.0f)); ExampleMaterialChunk->setDiffuse(Color4f(0.0f,0.0f,0.0f,1.0f)); ExampleMaterialChunk->setSpecular(Color4f(0.0f,0.0f,0.0f,1.0f)); ChunkMaterialUnrecPtr ExampleMaterial = ChunkMaterial::create(); ExampleMaterial->addChunk(ExampleLineChunk); ExampleMaterial->addChunk(ExampleMaterialChunk); ExampleMaterial->addChunk(ExampleBlendChunk); GeometryRefPtr SphereGeometry = makeSphereGeo(2, 0.25f); GeometryRefPtr BoxGeometry = makeBoxGeo(0.5f,0.5f,0.5f,1,1,1); //Skeleton SkeletonBlendedGeometryUnrecPtr ExampleSkeleton = SkeletonBlendedGeometry::create(); //Joint TransformRecPtr ExampleRootJoint = Transform::create(); NodeRecPtr ExampleRootJointNode = makeNodeFor(ExampleRootJoint); //Add this joint to the skeleton ExampleSkeleton->pushToJoints(ExampleRootJointNode, Matrix()); NodeRecPtr TempRootJointNode = ExampleRootJointNode; NodeRefPtr GeoNode = makeNodeFor(BoxGeometry); TempRootJointNode->addChild(GeoNode); Matrix TempMat; //Create a set of randomly placed child joints for (Real32 i = 0.0f; i < 5.0f; ++i) { TransformRecPtr ExampleChildJoint = Transform::create(); NodeRecPtr ExampleChildJointNode = makeNodeFor(ExampleChildJoint); GeoNode = makeNodeFor(SphereGeometry); ExampleChildJointNode->addChild(GeoNode); //TempMat.setTranslate(RandomPoolManager::getRandomReal32(0.0, 10.0f), RandomPoolManager::getRandomReal32(0.0f, 10.0f), RandomPoolManager::getRandomReal32(0.0f, 10.0f)); switch((static_cast<UInt32>(i) % 3)) { case 0: TempMat.setTranslate(2.0f,0.0f,0.0f); break; case 1: TempMat.setTranslate(0.0f,2.0f,0.0f); break; case 2: TempMat.setTranslate(0.0f,0.0f,2.0f); break; } //Set bind and current transformations to TempMat (calculated above) ExampleChildJoint->setMatrix(TempMat); //Add ExampleChildJoint as a child to the previous joint TempRootJointNode->addChild(ExampleChildJointNode);//add a Child to the root joint //ExampleChildJoint will be the next parent joint TempRootJointNode = ExampleChildJointNode; //Add this joint to the skeleton Matrix InvBind(TempRootJointNode->getToWorld()); InvBind.invert(); ExampleSkeleton->pushToJoints(ExampleChildJointNode, InvBind); } //SkeletonDrawer SkeletonDrawableUnrecPtr ExampleSkeletonDrawable = SkeletonDrawable::create(); ExampleSkeletonDrawable->setSkeleton(ExampleSkeleton); ExampleSkeletonDrawable->setMaterial(ExampleMaterial); ExampleSkeletonDrawable->setDrawBindPose(false); //By default, we won't draw the skeleton's bind pose ExampleSkeletonDrawable->setBindPoseColor(Color4f(0.0, 1.0, 0.0, 1.0)); //When the skeleton's bind pose is rendered, it will be green ExampleSkeletonDrawable->setDrawPose(true); //By default, we do draw the skeleton's current pose ExampleSkeletonDrawable->setPoseColor(Color4f(0.0, 0.0, 1.0, 1.0)); //The skeleton's current pose is rendered in blue //Skeleton Node NodeUnrecPtr SkeletonNode = Node::create(); SkeletonNode->setCore(ExampleSkeletonDrawable); //Create scene NodeUnrecPtr scene = Node::create(); scene->setCore(Group::create()); scene->addChild(SkeletonNode); scene->addChild(ExampleRootJointNode); sceneManager.setRoot(scene); //Create the Documentation SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow); //Setup the Animation AnimationUnrecPtr TheAnimation = setupAnimation(ExampleRootJoint, dynamic_cast<Transform*>(ExampleRootJointNode->getChild(1)->getCore())); TheAnimation->attachUpdateProducer(TutorialWindow); TheAnimation->start(); TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1, TheAnimation.get(), SkeletonNode.get(), TutorialWindow.get())); // 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, "11BoneAnimation"); //Main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
// Initialize GLUT & OpenSG and set up the rootNode int main(int argc, char **argv) { // OSG init osgInit(argc,argv); { // Set up Window WindowEventProducerRecPtr TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); SimpleSceneManager sceneManager; TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager)); TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager)); //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)); // Tell the Manager what to manage sceneManager.setWindow(TutorialWindow); //Make Base Geometry Node NodeRecPtr TriGeometryBase = makeTorus(0.5, 1.0, 24, 24); //Make Main Scene Node NodeRecPtr scene = makeCoredNode<Group>(); setName(scene, "scene"); NodeRecPtr rootNode = Node::create(); setName(rootNode, "rootNode"); ComponentTransformRecPtr Trans; Trans = ComponentTransform::create(); rootNode->setCore(Trans); // add the torus as a child rootNode->addChild(scene); //Make The Physics Characteristics Node PhysicsCharacteristicsDrawableRecPtr PhysDrawable = PhysicsCharacteristicsDrawable::create(); PhysDrawable->setRoot(rootNode); NodeRecPtr PhysDrawableNode = Node::create(); PhysDrawableNode->setCore(PhysDrawable); PhysDrawableNode->setTravMask(TypeTraits<UInt32>::getMin()); rootNode->addChild(PhysDrawableNode); //Setup Physics Scene PhysicsWorldRecPtr physicsWorld = PhysicsWorld::create(); physicsWorld->setWorldContactSurfaceLayer(0.005); physicsWorld->setAutoDisableFlag(1); physicsWorld->setAutoDisableTime(0.75); physicsWorld->setWorldContactMaxCorrectingVel(100.0); physicsWorld->setGravity(Vec3f(0.0, 0.0, -9.81)); PhysicsHashSpaceRecPtr physicsSpace = PhysicsHashSpace::create(); PhysicsHandlerRecPtr physHandler = PhysicsHandler::create(); physHandler->setWorld(physicsWorld); physHandler->pushToSpaces(physicsSpace); physHandler->setUpdateNode(rootNode); physHandler->attachUpdateProducer(TutorialWindow); /************************************************************************/ /* create spaces, geoms and bodys */ /************************************************************************/ //create a group for our space GroupRecPtr spaceGroup; NodeRecPtr spaceGroupNode = makeCoredNode<Group>(&spaceGroup); //create the ground plane GeometryRecPtr plane; NodeRecPtr planeNode = makeBox(30.0, 30.0, 1.0, 1, 1, 1); plane = dynamic_cast<Geometry*>(planeNode->getCore()); //and its Material SimpleMaterialRecPtr plane_mat = SimpleMaterial::create(); plane_mat->setAmbient(Color3f(0.7,0.7,0.7)); plane_mat->setDiffuse(Color3f(0.9,0.6,1.0)); plane->setMaterial(plane_mat); //create Physical Attachments PhysicsBoxGeomRecPtr planeGeom = PhysicsBoxGeom::create(); planeGeom->setLengths(Vec3f(30.0, 30.0, 1.0)); //add geoms to space for collision planeGeom->setSpace(physicsSpace); //add Attachments to nodes... spaceGroupNode->addAttachment(physicsSpace); spaceGroupNode->addAttachment(physHandler); spaceGroupNode->addAttachment(physicsWorld); spaceGroupNode->addChild(planeNode); planeNode->addAttachment(planeGeom); scene->addChild(spaceGroupNode); //Create Statistics Foreground SimpleStatisticsForegroundRecPtr PhysicsStatForeground = SimpleStatisticsForeground::create(); PhysicsStatForeground->setSize(25); PhysicsStatForeground->setColor(Color4f(0,1,0,0.7)); PhysicsStatForeground->addElement(WindowEventProducer::statWindowLoopTime, "Draw FPS: %r.3f"); PhysicsStatForeground->getCollector()->getElem(WindowEventProducer::statWindowLoopTime, true); PhysicsStatForeground->addElement(RenderAction::statNGeometries, "%d Nodes drawn"); PhysicsStatForeground->getCollector()->getElem(RenderAction::statNGeometries, true); PhysicsStatForeground->addElement(PhysicsHandler::statPhysicsTime, "Physics time: %.3f s"); PhysicsStatForeground->getCollector()->getElem(PhysicsHandler::statPhysicsTime, true); PhysicsStatForeground->addElement(PhysicsHandler::statCollisionTime, "Collision time: %.3f s"); PhysicsStatForeground->getCollector()->getElem(PhysicsHandler::statCollisionTime, true); PhysicsStatForeground->addElement(PhysicsHandler::statSimulationTime, "Simulation time: %.3f s"); PhysicsStatForeground->getCollector()->getElem(PhysicsHandler::statSimulationTime, true); PhysicsStatForeground->addElement(PhysicsHandler::statNCollisions, "%d collisions"); PhysicsStatForeground->getCollector()->getElem(PhysicsHandler::statNCollisions, true); PhysicsStatForeground->addElement(PhysicsHandler::statNCollisionTests, "%d collision tests"); PhysicsStatForeground->getCollector()->getElem(PhysicsHandler::statNCollisionTests, true); PhysicsStatForeground->addElement(PhysicsHandler::statNPhysicsSteps, "%d simulation steps per frame"); PhysicsStatForeground->getCollector()->getElem(PhysicsHandler::statNPhysicsSteps, true); TutorialWindow->connectUpdate(boost::bind(handleStatisticsReset, _1), boost::signals2::at_front); StatCollector::setGlobalCollector(PhysicsStatForeground->getCollector()); SimpleStatisticsForegroundRecPtr RenderStatForeground = SimpleStatisticsForeground::create(); RenderStatForeground->setSize(25); RenderStatForeground->setColor(Color4f(0,1,0,0.7)); // tell the manager what to manage sceneManager.setRoot (rootNode); sceneManager.getWindow()->getPort(0)->addForeground(PhysicsStatForeground); sceneManager.getWindow()->getPort(0)->addForeground(RenderStatForeground); TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1, TriGeometryBase.get(), spaceGroupNode.get(), PhysDrawableNode.get(), physicsWorld.get(), physicsSpace.get())); // show the whole rootNode sceneManager.getNavigator()->set(Pnt3f(20.0,20.0,10.0), Pnt3f(0.0,0.0,0.0), Vec3f(0.0,0.0,1.0)); sceneManager.getNavigator()->setMotionFactor(1.0f); sceneManager.getCamera()->setFar(10000.0f); sceneManager.getCamera()->setNear(0.1f); Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "01SimplePhysics"); //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 PointChunkRecPtr PSPointChunk = PointChunk::create(); PSPointChunk->setSize(5.0f); PSPointChunk->setSmooth(true); BlendChunkRecPtr PSBlendChunk = BlendChunk::create(); PSBlendChunk->setSrcFactor(GL_SRC_ALPHA); PSBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA); MaterialChunkRecPtr PSMaterialChunkChunk = MaterialChunk::create(); PSMaterialChunkChunk->setAmbient(Color4f(0.5f,0.5f,0.5f,0.3f)); PSMaterialChunkChunk->setDiffuse(Color4f(0.8f,0.8f,0.8f,0.3f)); PSMaterialChunkChunk->setSpecular(Color4f(1.0f,1.0f,1.0f,0.3f)); PSMaterialChunkChunk->setColorMaterial(GL_AMBIENT_AND_DIFFUSE); ChunkMaterialRecPtr PSMaterial = ChunkMaterial::create(); PSMaterial->addChunk(PSPointChunk); PSMaterial->addChunk(PSMaterialChunkChunk); PSMaterial->addChunk(PSBlendChunk); //Particle System ParticleSystemRecPtr ExampleParticleSystem = ParticleSystem::create(); for(UInt32 i(0) ; i<10 ; ++i) { ExampleParticleSystem->addParticle(Pnt3f(i,i,i), Vec3f(0.0,0.0f,1.0f), Color4f(1.0,0.0,0.0,0.5), Vec3f(1.0,1.0,1.0), -1.0, Vec3f(0.0f,0.0f,0.0f), //Velocity Vec3f(0.0f,0.0f,0.0f) ); } ExampleParticleSystem->attachUpdateProducer(TutorialWindow); //Particle System Drawer //Point PointParticleSystemDrawerRecPtr ExamplePointDrawer = PointParticleSystemDrawer::create(); //ExamplePointParticleSystemDrawer->setForcePerParticleSizing(true); //Line LineParticleSystemDrawerRecPtr ExampleLineDrawer = LineParticleSystemDrawer::create(); ExampleLineDrawer->setLineDirectionSource(LineParticleSystemDrawer::DIRECTION_NORMAL);//DIRECTION_VELOCITY_CHANGE); ExampleLineDrawer->setLineLengthSource(LineParticleSystemDrawer::LENGTH_SIZE_X); //Quad QuadParticleSystemDrawerRecPtr ExampleQuadDrawer = QuadParticleSystemDrawer::create(); //Disc DiscParticleSystemDrawerRecPtr ExampleDiscDrawer = DiscParticleSystemDrawer::create(); ExampleDiscDrawer->setSegments(16); ExampleDiscDrawer->setCenterAlpha(1.0); ExampleDiscDrawer->setEdgeAlpha(0.0); //Particle System Node ParticleSystemCoreRecPtr ParticleNodeCore = ParticleSystemCore::create(); ParticleNodeCore->setSystem(ExampleParticleSystem); ParticleNodeCore->setDrawer(ExampleLineDrawer); ParticleNodeCore->setMaterial(PSMaterial); NodeRecPtr ParticleNode = Node::create(); ParticleNode->setCore(ParticleNodeCore); // Make Main Scene Node NodeRecPtr scene = Node::create(); scene->setCore(Group::create()); scene->addChild(ParticleNode); sceneManager.setRoot(scene); TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1, &sceneManager, ParticleNodeCore.get(), ExamplePointDrawer, ExampleLineDrawer, ExampleQuadDrawer, ExampleDiscDrawer )); //Create the Documentation SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow); // Show the whole Scene sceneManager.showAll(); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "01ParticleSystemDrawers"); commitChanges(); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
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)); //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)); // Tell the Manager what to manage sceneManager.setWindow(TutorialWindow); VideoWrapperRecPtr TheVideo = getDefaultVideoManager()->createVideoWrapper(); TheVideo->attachUpdateProducer(TutorialWindow); TheVideo->connectStarted(boost::bind(handleVideoStarted, _1)); TheVideo->connectPaused(boost::bind(handleVideoPaused, _1)); TheVideo->connectUnpaused(boost::bind(handleVideoUnpaused, _1)); TheVideo->connectStopped(boost::bind(handleVideoStopped, _1)); TheVideo->connectClosed(boost::bind(handleVideoClosed, _1)); TheVideo->connectSeeked(boost::bind(handleVideoSeeked, _1)); TheVideo->connectCycled(boost::bind(handleVideoCycled, _1)); TheVideo->connectOpened(boost::bind(handleVideoOpened, _1)); TheVideo->connectEnded(boost::bind(handleVideoEnded, _1)); BoostPath VideoFilePath("./Data/ExampleVideo.avi"); if(argc >= 2) { VideoFilePath = BoostPath(argv[1]); if(!boost::filesystem::exists(VideoFilePath)) { std::cerr << "Could not load file: "<< VideoFilePath.string() << ", because no such files exists."<< std::endl; VideoFilePath = BoostPath("./Data/ExampleVideo.avi"); } } TheVideo->open(VideoFilePath, TutorialWindow); TheVideo->pause(); if(TheVideo->hasAudio()) { TheVideo->enableAudio(); TheVideo->setAudioVolume(0.5f); } //Wait for the video to initialize std::cout << "Dimensions: " << TheVideo->getWidth() << "x" << TheVideo->getHeight() << std::endl; Real32 AspectRatio(static_cast<Real32>(TheVideo->getWidth())/static_cast<Real32>(TheVideo->getHeight())); //Real32 AspectRatio(4.0f/3.0f); // Set filtering modes. LINEAR is cheap and good if the image size // changes very little (i.e. the window is about the same size as // the images). //TheVideo->setMinFilter(GL_LINEAR); TheVideo->setMinFilter(GL_NEAREST); TheVideo->setMagFilter(GL_LINEAR); //TheVideo->setMagFilter(GL_NEAREST); // Set the wrapping modes. We don't need repetition, it might actually // introduce artifactes at the borders, so switch it off. TheVideo->setWrapS(GL_CLAMP_TO_EDGE); TheVideo->setWrapT(GL_CLAMP_TO_EDGE); TheVideo->setScale(false); ChunkMaterialUnrecPtr VideoMaterial = ChunkMaterial::create(); VideoMaterial->addChunk(TheVideo); StateChunkUnrecPtr pMChunk = MaterialChunk::create(); VideoMaterial->addChunk(pMChunk); // create the scene //Plane Geometry GeometryRecPtr PlaneGeometry = makePlaneGeo(10.0*AspectRatio,10.0,10,10); PlaneGeometry->setMaterial(VideoMaterial); NodeRecPtr PlaneGeometryNode = Node::create(); PlaneGeometryNode->setCore(PlaneGeometry); //Box Geometry GeometryRecPtr BoxGeometry = makeBoxGeo(10.0*AspectRatio,10.0,10.0,2,2,2); BoxGeometry->setMaterial(VideoMaterial); NodeRecPtr BoxGeometryNode = Node::create(); BoxGeometryNode->setCore(BoxGeometry); //Sphere Geometry GeometryRecPtr SphereGeometry = makeSphereGeo(2,5.0); SphereGeometry->setMaterial(VideoMaterial); NodeRecPtr SphereGeometryNode = Node::create(); SphereGeometryNode->setCore(SphereGeometry); //Torus Geometry GeometryRecPtr TorusGeometry = makeTorusGeo(2.0,5.0,32,32); TorusGeometry->setMaterial(VideoMaterial); NodeRecPtr TorusGeometryNode = Node::create(); TorusGeometryNode->setCore(TorusGeometry); //Switch Node SwitchRecPtr GeometryNodeSwitch = Switch::create(); GeometryNodeSwitch->setChoice(0); NodeRecPtr SwitchNode = Node::create(); SwitchNode->setCore(GeometryNodeSwitch); SwitchNode->addChild(PlaneGeometryNode); SwitchNode->addChild(BoxGeometryNode); SwitchNode->addChild(SphereGeometryNode); SwitchNode->addChild(TorusGeometryNode); NodeRecPtr scene = Node::create(); TransformRecPtr trans = Transform::create(); scene->setCore(trans); scene->addChild(SwitchNode); TutorialWindow->connectKeyTyped(boost::bind(handleKeyTyped, _1, TheVideo.get(), GeometryNodeSwitch.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, "01PlayVideo"); commitChanges(); //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)); TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1, &sceneManager)); //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 = 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->attachUpdateProducer(TutorialWindow); //Particle System Drawer (Line) LineParticleSystemDrawerRefPtr ExampleParticleSystemDrawer = 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 = 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 = 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); //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, "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); TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1)); 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)); BoostPath EffectFilePath("./Data/goochyPt.cgfx"); if(argc >= 2) { EffectFilePath = BoostPath(argv[1]); if(!boost::filesystem::exists(EffectFilePath)) { std::cerr << "Could not load file: "<< EffectFilePath.string() << ", because no such files exists."<< std::endl; EffectFilePath = BoostPath("./Data/goochyPt.cgfx"); } } //Make the CgFX Material CgFXMaterialRecPtr ExampleMaterial = CgFXMaterial::create(); ExampleMaterial->setEffectFile(EffectFilePath.string()); // Make Torus Node (creates Torus in background of scene) GeometryRefPtr TorusGeometry = makeTorusGeo(.5, 2, 16, 16); //GeometryRefPtr TorusGeometry = makeBoxGeo(1.0,1.0,1.0,1,1,1); TorusGeometry->setMaterial(ExampleMaterial); TorusGeometry->setDlistCache(false); NodeRefPtr TorusGeometryNode = makeNodeFor(TorusGeometry); // Make Main Scene Node and add the Torus NodeRefPtr scene = OSG::Node::create(); scene->setCore(OSG::Group::create()); scene->addChild(TorusGeometryNode); sceneManager.setRoot(scene); //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, "04CgFXMaterial"); commitChanges(); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
// Initialize GLUT & OpenSG and set up the rootNode int main(int argc, char **argv) { // OSG init osgInit(argc,argv); { // Set up Window WindowEventProducerRecPtr TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); SimpleSceneManager sceneManager; TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager)); TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager)); //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->connectKeyPressed(boost::bind(keyPressed,_1)); // Tell the Manager what to manage sceneManager.setWindow(TutorialWindow); UInt32 SceneMask(1), PathMask(4); BoostPath SceneFilePath(".//Data//CellParts.osb"); if(argc >= 2) { SceneFilePath = BoostPath(argv[1]); if(!boost::filesystem::exists(SceneFilePath)) { SceneFilePath = BoostPath(".//Data//CellParts.osb"); } } //Make Base Geometry Node NodeRecPtr SceneGeometryNode = SceneFileHandler::the()->read(SceneFilePath.string().c_str()); SceneGeometryNode->setTravMask(SceneMask); if(SceneGeometryNode == NULL) { SceneGeometryNode = makeTorus(1.0, 10.0, 24, 24); } //Construct the Root Node NodeRecPtr RootNode = makeCoredNode<Group>(); RootNode->addChild(SceneGeometryNode); commitChanges(); //Create the Octree SLOG << "Started Building Octree" << std::endl; SLOG << "This may take some time ..." << std::endl; Time StartTime; StartTime = getSystemTime(); OctreePtr TheOctree = Octree::buildTree(RootNode,SceneMask,6,1.5,true); SLOG << "Building Octree: " << getSystemTime() - StartTime << " s" << std::endl; Pnt3f Min,Max; TheOctree->getRoot()->getVolume(); SLOG << "Octree: "<< std::endl << " Depth: " << TheOctree->getDepth() << std::endl << " Bounds: " << TheOctree->getRoot()->getVolume().getMin() << " : " << TheOctree->getRoot()->getVolume().getMax() << std::endl << " NodeCount: " << TheOctree->getNodeCount() << std::endl << " LeafNodeCount: " << TheOctree->getLeafNodeCount() << std::endl << " BranchNodeCount: " << TheOctree->getBranchNodeCount() << std::endl << " IntersectingNodeCount: " << TheOctree->getIntersectingNodeCount() << std::endl << " IntersectingLeafNodeCount: " << TheOctree->getIntersectingLeafNodeCount() << std::endl; //Create the Path Geometry //Generate the Path OctreeAStarAlgorithm AlgorithmObj; SLOG << "Started AStar Search" << std::endl; StartTime = getSystemTime(); Pnt3f Start(-4.01f,1.01f,10.01f),Goal(-4.01f,-0.01f,-7.01f); std::vector<Pnt3f> Path = AlgorithmObj.search(TheOctree,Start,Goal); Path.front() = Start; Path.back() = Goal; SLOG << "Finished AStar Search: " << getSystemTime() - StartTime << " s" << std::endl; NodeRecPtr PathNode = createPathGeometry(Path); PathNode->setTravMask(PathMask); RootNode->addChild(PathNode); NodeRecPtr StartNode = makeSphere(1.0, 2); TransformRecPtr StartNodeTransform = Transform::create(); Matrix StartNodeMatrix; StartNodeMatrix.setTranslate(Start); StartNodeMatrix.setScale(0.1f); StartNodeTransform->setMatrix(StartNodeMatrix); NodeRecPtr StartNodeTransformNode = makeNodeFor(StartNodeTransform); StartNodeTransformNode->addChild(StartNode); StartNodeTransformNode->setTravMask(PathMask); RootNode->addChild(StartNodeTransformNode); NodeRecPtr GoalNode = makeSphere(1.0, 2); TransformRecPtr GoalNodeTransform = Transform::create(); Matrix GoalNodeMatrix; GoalNodeMatrix.setScale(0.1f); GoalNodeMatrix.setTranslate(Goal); GoalNodeTransform->setMatrix(GoalNodeMatrix); NodeRecPtr GoalNodeTransformNode = makeNodeFor(GoalNodeTransform); GoalNodeTransformNode->addChild(GoalNode); GoalNodeTransformNode->setTravMask(PathMask); RootNode->addChild(GoalNodeTransformNode); //Set the background SolidBackgroundRecPtr TheBackground = SolidBackground::create(); TheBackground->setColor(Color3f(0.0f,0.0f,0.0f)); // tell the manager what to manage sceneManager.setRoot (RootNode); sceneManager.getWindow()->getPort(0)->setBackground(TheBackground); // show the whole RootNode sceneManager.showAll(); Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "01AStarPathing"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
// Initialize WIN32 & OpenSG and set up the scene 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)); //Sound Emitter Node SoundEmitterRecPtr TheEmitter = SoundEmitter::create(); TheEmitter->attachUpdateProducer(TutorialWindow); NodeUnrecPtr TheEmitterNode = Node::create(); TheEmitterNode->setCore(TheEmitter); //Sphere Transformation Node Matrix Translate; Translate.setTranslate(0.0,0.0,-5.0); Matrix Rotation; Rotation.setRotate(Quaternion(Vec3f(0.0,1.0,0.0), 0.0)); Matrix Total(Translate); Total.mult(Rotation); TransformRecPtr TheSphereTransform = Transform::create(); TheSphereTransform->setMatrix(Total); NodeUnrecPtr SphereTransformNode = Node::create(); SphereTransformNode->setCore(TheSphereTransform); SphereTransformNode->addChild(makeSphere(2, 1.0)); SphereTransformNode->addChild(TheEmitterNode); // create the scene NodeUnrecPtr scene = Node::create(); scene->setCore(Group::create()); scene->addChild(SphereTransformNode); // tell the manager what to manage sceneManager.setRoot (scene); CameraUnrecPtr TheCamera = sceneManager.getCamera(); TheCamera->setNear(0.1); TheCamera->setFar(100.0); //Initialize the Sound Manager SoundManager::the()->attachUpdateProducer(TutorialWindow); SoundManager::the()->setCamera(sceneManager.getCamera()); SoundRecPtr PopSound = SoundManager::the()->createSound(); PopSound->setFile(BoostPath("./Data/pop.wav")); PopSound->setVolume(1.0); PopSound->setStreaming(false); PopSound->setLooping(-1); PopSound->setEnable3D(true); PopSound->connectSoundPlayed (boost::bind(handleSoundPlayed, _1)); PopSound->connectSoundStopped (boost::bind(handleSoundStopped, _1)); PopSound->connectSoundPaused (boost::bind(handleSoundPaused, _1)); PopSound->connectSoundUnpaused(boost::bind(handleSoundUnpaused, _1)); PopSound->connectSoundLooped (boost::bind(handleSoundLooped, _1)); //Attach this sound to the emitter node TheEmitter->setSound(PopSound); TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1, TheEmitter.get())); TutorialWindow->connectUpdate(boost::bind(handleUpdate, _1, TheSphereTransform.get())); //Create the Documentation SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow); Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "02 Sound3D Window"); //Enter main loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
// Initialize GLUT & OpenSG and set up the rootNode int main(int argc, char **argv) { // OSG init osgInit(argc,argv); { // Set up Window WindowEventProducerRecPtr TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); SimpleSceneManager sceneManager; TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager)); TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager)); //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)); // Tell the Manager what to manage sceneManager.setWindow(TutorialWindow); UInt32 SceneMask(1), NanobotMask(2), PathMask(4); BoostPath SceneFilePath(".//Data//CellParts.osb"); if(argc >= 2) { SceneFilePath = BoostPath(argv[1]); if(!boost::filesystem::exists(SceneFilePath)) { SceneFilePath = BoostPath(".//Data//CellParts.osb"); } } //Make Base Geometry Node NodeRecPtr SceneGeometryNode = SceneFileHandler::the()->read(SceneFilePath.string().c_str()); SceneGeometryNode->setTravMask(SceneMask); if(SceneGeometryNode == NULL) { SceneGeometryNode = makeTorus(1.0, 10.0, 24, 24); } //Construct the Root Node NodeRecPtr RootNode = makeCoredNode<Group>(); RootNode->addChild(SceneGeometryNode); commitChanges(); //Create the Octree SLOG << "Started Building Octree" << std::endl; SLOG << "This may take some time ..." << std::endl; Time StartTime; StartTime = getSystemTime(); OctreePtr TheOctree = Octree::buildTree(RootNode,SceneMask,6,0.5,true); SLOG << "Building Octree: " << getSystemTime() - StartTime << " s" << std::endl; Pnt3f Min,Max; TheOctree->getRoot()->getVolume(); SLOG << "Octree: "<< std::endl << " Depth: " << TheOctree->getDepth() << std::endl << " Bounds: " << TheOctree->getRoot()->getVolume().getMin() << " : " << TheOctree->getRoot()->getVolume().getMax() << std::endl << " NodeCount: " << TheOctree->getNodeCount() << std::endl << " LeafNodeCount: " << TheOctree->getLeafNodeCount() << std::endl << " BranchNodeCount: " << TheOctree->getBranchNodeCount() << std::endl << " IntersectingNodeCount: " << TheOctree->getIntersectingNodeCount() << std::endl << " IntersectingLeafNodeCount: " << TheOctree->getIntersectingLeafNodeCount() << std::endl; //Make the Nanobot Nodes BoostPath NanobotFilePath(".//Data//Nanobot.osb"); NodeRecPtr NanobotGeoNode = SceneFileHandler::the()->read(NanobotFilePath.string().c_str()); NanobotVector Nanobots; UInt32 NumNanobots(3); for(UInt32 i(0) ; i<NumNanobots ; ++i) { NanobotDetails TheDetails; //Get the Transform node for the Nanobot TheDetails._Transform = Transform::create(); Matrix NanobotMatrix; Pnt3f Min,Max; SceneGeometryNode->getVolume().getBounds(Min,Max); Min = Min + ShrinkFactor; Max = Max - ShrinkFactor; NanobotMatrix.setTranslate(randomOpenPosition(Min,Max,TheOctree).subZero()); NanobotMatrix.setScale(0.06f); TheDetails._Transform->setMatrix(NanobotMatrix); TheDetails._Node = makeNodeFor(TheDetails._Transform); TheDetails._Node->addChild(cloneTree(NanobotGeoNode)); TheDetails._Node->setTravMask(NanobotMask); TheDetails._PathVisNode = Node::create(); Nanobots.push_back(TheDetails); makeNanobotPath(Nanobots.back(), TheOctree, TutorialWindow, Min,Max); } for(UInt32 i(0) ; i<Nanobots.size() ; ++i) { RootNode->addChild(Nanobots[i]._Node); RootNode->addChild(Nanobots[i]._PathVisNode); } commitChanges(); //NodeRecPtr StartNode = makeSphere(1.0, 2); //TransformRecPtr StartNodeTransform = Transform::create(); //Matrix StartNodeMatrix; //StartNodeMatrix.setTranslate(Start); //StartNodeMatrix.setScale(0.1f); //StartNodeTransform->setMatrix(StartNodeMatrix); //NodeRecPtr StartNodeTransformNode = makeNodeFor(StartNodeTransform); //StartNodeTransformNode->addChild(StartNode); //StartNodeTransformNode->setTravMask(PathMask); //RootNode->addChild(StartNodeTransformNode); //NodeRecPtr GoalNode = makeSphere(1.0, 2); //TransformRecPtr GoalNodeTransform = Transform::create(); //Matrix GoalNodeMatrix; //GoalNodeMatrix.setScale(0.1f); //GoalNodeMatrix.setTranslate(Goal); //GoalNodeTransform->setMatrix(GoalNodeMatrix); //NodeRecPtr GoalNodeTransformNode = makeNodeFor(GoalNodeTransform); //GoalNodeTransformNode->addChild(GoalNode); //GoalNodeTransformNode->setTravMask(PathMask); //RootNode->addChild(GoalNodeTransformNode); TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1, TutorialWindow.get(), SceneGeometryNode.get(), TheOctree, Nanobots)); //Set the background SolidBackgroundRecPtr TheBackground = SolidBackground::create(); TheBackground->setColor(Color3f(0.0f,0.0f,0.0f)); // tell the manager what to manage sceneManager.setRoot (RootNode); sceneManager.getWindow()->getPort(0)->setBackground(TheBackground); // show the whole RootNode sceneManager.showAll(); Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "01AStarPathing"); //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 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; }
// Initialize GLUT & OpenSG and set up the scene int main(int argc, char **argv) { // OSG init osgInit(argc,argv); { // Set up Window WindowEventProducerRecPtr TutorialWindow = createNativeWindow(); //Initialize Window TutorialWindow->initWindow(); 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)); //Torus Material SimpleMaterialUnrecPtr TheTorusMaterial = SimpleMaterial::create(); TheTorusMaterial->setAmbient(Color3f(0.3,0.3,0.3)); TheTorusMaterial->setDiffuse(Color3f(0.7,0.7,0.7)); TheTorusMaterial->setSpecular(Color3f(1.0,1.0,1.0)); TheTorusMaterial->setShininess(20.0); //Torus Geometry GeometryUnrecPtr TorusGeometry = makeTorusGeo(.5, 2, 32, 32); TorusGeometry->setMaterial(TheTorusMaterial); NodeUnrecPtr TorusGeometryNode = Node::create(); TorusGeometryNode->setCore(TorusGeometry); //Make Torus Node NodeUnrecPtr TorusNode = Node::create(); TransformUnrecPtr TorusNodeTrans = Transform::create(); setName(TorusNodeTrans, std::string("TorusNodeTransformationCore")); TorusNode->setCore(TorusNodeTrans); TorusNode->addChild(TorusGeometryNode); //Make Main Scene Node NodeUnrecPtr scene = Node::create(); ComponentTransformUnrecPtr Trans = ComponentTransform::create(); setName(Trans, std::string("MainTransformationCore")); scene->setCore(Trans); // add the torus as a child scene->addChild(TorusNode); AnimationGroupUnrecPtr TheAnimation = setupAnimation(TheTorusMaterial, TorusNodeTrans); TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1, TheAnimation.get(), TutorialWindow.get())); TheAnimation->attachUpdateProducer(TutorialWindow); TheAnimation->start(); // tell the manager what to manage sceneManager.setRoot (scene); //Create the Documentation SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow); // show the whole scene sceneManager.showAll(); Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "07AnimationGroup"); //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(); //Initialize Window TutorialWindow->initWindow(); 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)); TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1, TutorialWindow.get())); //Shader Chunk SimpleSHLChunkUnrecPtr TheSHLChunk = SimpleSHLChunk::create(); TheSHLChunk->setVertexProgram(createSHLVertexProg()); TheSHLChunk->setFragmentProgram(createSHLFragProg()); //TheSHLChunk->addUniformVariable("Color1",Vec4f(0.0f,1.0f,0.0f,1.0f)); //TheSHLChunk->addUniformVariable("Color2",Vec4f(1.0f,1.0f,1.0f,1.0f)); //Shader Parameter Chunk SimpleSHLVariableChunkUnrecPtr SHLParameters = SimpleSHLVariableChunk::create(); //Color Parameter SHLParameters->addUniformVariable("Color1",Vec4f(0.0f,1.0f,0.0f,1.0f)); SHLParameters->addUniformVariable("Color2",Vec4f(1.0f,1.0f,1.0f,1.0f)); ChunkMaterialUnrecPtr ShaderMaterial = ChunkMaterial::create(); ShaderMaterial->addChunk(TheSHLChunk); ShaderMaterial->addChunk(SHLParameters); //Torus Node GeometryUnrecPtr TorusGeometry = makeTorusGeo(5.0f,20.0f, 32,32); TorusGeometry->setMaterial(ShaderMaterial); NodeUnrecPtr TorusNode = Node::create(); TorusNode->setCore(TorusGeometry); // Make Main Scene Node NodeUnrecPtr scene = Node::create(); scene->setCore(Group::create()); scene->addChild(TorusNode); sceneManager.setRoot(scene); // Show the whole Scene sceneManager.showAll(); //Create the Animations ShaderVariableVec4fUnrecPtr Color1Parameter; ShaderVariableVec4fUnrecPtr Color2Parameter; Color1Parameter = dynamic_cast<ShaderVariableVec4f*>(const_cast<ShaderVariable*>(SHLParameters->getVariables()->getVariable("Color1"))); Color2Parameter = dynamic_cast<ShaderVariableVec4f*>(const_cast<ShaderVariable*>(SHLParameters->getVariables()->getVariable("Color2"))); commitChanges(); AnimationUnrecPtr TheAnimation = setupAnimation(Color1Parameter, "value"); TheAnimation->attachUpdateProducer(TutorialWindow); TheAnimation->start(); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "04ShaderAnimation"); //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; }
// Initialize GLUT & OpenSG and set up the scene int main(int argc, char **argv) { // OSG init osgInit(argc,argv); { // Set up Window WindowEventProducerRecPtr TutorialWindow = createNativeWindow(); //Initialize Window TutorialWindow->initWindow(); 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)); TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1, TutorialWindow.get())); //Torus Node NodeUnrecPtr TorusGeometryNode = makeTorus(.5, 2, 32, 32); //Make Torus Node NodeUnrecPtr TorusNode = Node::create(); TransformUnrecPtr TorusNodeTrans; TorusNodeTrans = Transform::create(); TorusNode->setCore(TorusNodeTrans); TorusNode->addChild(TorusGeometryNode); //Make Main Scene Node NodeUnrecPtr scene = Node::create(); ComponentTransformUnrecPtr Trans; Trans = ComponentTransform::create(); scene->setCore(Trans); // add the torus as a child scene->addChild(TorusNode); //Make a gradient Background GradientBackgroundUnrecPtr TutorialBackground = GradientBackground::create(); TutorialBackground->addLine(Color3f(1.0,0.0,0.0),0.0); TutorialBackground->addLine(Color3f(0.0,1.0,0.0),0.5); TutorialBackground->addLine(Color3f(0.0,0.0,1.0),1.0); setName(TutorialBackground, std::string("TutorialGradientBackground")); AnimationUnrecPtr TheAnimation = setupAnimation(TutorialBackground); TheAnimation->attachUpdateProducer(TutorialWindow); TheAnimation->start(); // tell the manager what to manage sceneManager.setRoot (scene); sceneManager.getWindow()->getPort(0)->setBackground(TutorialBackground); //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, "03MFieldAnimation"); //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; }
// Initialize WIN32 & OpenSG and set up the scene int main(int argc, char **argv) { std::cout << "\n\nKEY COMMANDS:" << std::endl << "space Play/Pause the playing sounds" << std::endl << "1 Play Pop Sound" << std::endl << "2 Play Click Sound" << std::endl << "CTRL-Q Exit\n\n" << std::endl; // 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)); // create the scene NodeUnrecPtr scene = makeTorus(1.0, 2.0, 16, 16); //Initialize the Sound Manager SoundManager::the()->attachUpdateProducer(TutorialWindow); SoundManager::the()->setCamera(sceneManager.getCamera()); //Create Pop Sound SoundRecPtr ZapSound = SoundManager::the()->createSound(); ZapSound->setFile(BoostPath("./Data/zap.wav")); ZapSound->setVolume(1.0); ZapSound->setStreaming(false); ZapSound->setLooping(1); //Attach Sound Events ZapSound->connectSoundPlayed (boost::bind(handleSoundPlayed, _1)); ZapSound->connectSoundStopped (boost::bind(handleSoundStopped, _1)); ZapSound->connectSoundPaused (boost::bind(handleSoundPaused, _1)); ZapSound->connectSoundUnpaused(boost::bind(handleSoundUnpaused, _1)); ZapSound->connectSoundLooped (boost::bind(handleSoundLooped, _1)); //Create Click Sound SoundRecPtr ClickSound = SoundManager::the()->createSound(); ClickSound->setFile(BoostPath("./Data/click.wav")); ClickSound->setVolume(1.0); ClickSound->setStreaming(false); ClickSound->setLooping(0); //Attach Sound Events ClickSound->connectSoundPlayed (boost::bind(handleSoundPlayed, _1)); ClickSound->connectSoundStopped (boost::bind(handleSoundStopped, _1)); ClickSound->connectSoundPaused (boost::bind(handleSoundPaused, _1)); ClickSound->connectSoundUnpaused(boost::bind(handleSoundUnpaused, _1)); ClickSound->connectSoundLooped (boost::bind(handleSoundLooped, _1)); TutorialWindow->connectKeyTyped(boost::bind(&KeyTypedHandler::keyTyped, _1, ZapSound.get(), ClickSound.get())); // tell the manager what to manage sceneManager.setRoot (scene); // show the whole scene sceneManager.showAll(); Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "01 DefaultSound Window"); //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/Explosion.png"); QuadTextureChunk->setImage(LoadedImage); TextureEnvChunkRefPtr QuadTextureEnvChunk = TextureEnvChunk::create(); QuadTextureEnvChunk->setEnvMode(GL_MODULATE); BlendChunkRefPtr PSBlendChunk = BlendChunk::create(); PSBlendChunk->setSrcFactor(GL_SRC_ALPHA); PSBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA); MaterialChunkRefPtr PSMaterialChunk = MaterialChunk::create(); PSMaterialChunk->setLit(false); ChunkMaterialRefPtr PSMaterial = ChunkMaterial::create(); PSMaterial->addChunk(QuadTextureChunk); PSMaterial->addChunk(QuadTextureEnvChunk); PSMaterial->addChunk(PSMaterialChunk); PSMaterial->addChunk(PSBlendChunk); //Particle System ParticleSystemRecPtr ExplosionParticleSystem = ParticleSystem::create(); ExplosionParticleSystem->attachUpdateProducer(TutorialWindow); //Age Particle Function. Controls which image is shown when, based on the age of a particle. AgeParticleFunctionRecPtr AgeFunc = AgeParticleFunction::create(); AgeFunc->setSequenceTime(0.07f); // image changes every 0.1 seconds. AgeFunc->setSequenceOrder(AgeParticleFunction::CUSTOM); // using the custom sequence below. /* Here, a custom sequence for the image ordering is assembled. The image sequence will be shown in the order specified here. Once the end of the sequence is reached, the sequence repeats. */ UInt32 NumImages(25); for(UInt32 i(0) ; i<NumImages ; ++i) { AgeFunc->editMFCustomSequence()->push_back(i); } //Particle System Drawer - QuadSequenceParticleSystemDrawerRecPtr ExplosionParticleSystemDrawer = QuadSequenceParticleSystemDrawer::create(); // image dimensions (in pixels) are required if there is a border on the images. ExplosionParticleSystemDrawer->setImageDimensions(Vec2us(320,320)); // The "dimensions" of the sequence contained in the image. For this image, // there are 3 images in the "x" direction, and two in the "y" direction, for a // total of 6. ExplosionParticleSystemDrawer->setSequenceDimensions(Vec2b(5,5)); // width of the border on each side of the image, in pixels. ExplosionParticleSystemDrawer->setBorderOffsets(Vec2b(0,0)); // this is the age function we just created above. ExplosionParticleSystemDrawer->setSequenceFunction(AgeFunc); RateParticleGeneratorRecPtr ExplosionParticleGenerator = RateParticleGenerator::create(); //Attach the function objects to the Generator ExplosionParticleGenerator->setPositionDistribution(createPositionDistribution()); ExplosionParticleGenerator->setLifespanDistribution(createLifespanDistribution()); ExplosionParticleGenerator->setVelocityDistribution(createVelocityDistribution()); ExplosionParticleGenerator->setAccelerationDistribution(createAccelerationDistribution()); ExplosionParticleGenerator->setSizeDistribution(createSizeDistribution()); ExplosionParticleGenerator->setGenerationRate(100.0f); //Particle System Node ParticleSystemCoreRefPtr ExplosionParticleCore = ParticleSystemCore::create(); ExplosionParticleCore->setSystem(ExplosionParticleSystem); ExplosionParticleCore->setDrawer(ExplosionParticleSystemDrawer); ExplosionParticleCore->setMaterial(PSMaterial); ExplosionParticleCore->setSortingMode(ParticleSystemCore::BACK_TO_FRONT); NodeRefPtr ExplosionParticleNode = Node::create(); ExplosionParticleNode->setCore(ExplosionParticleCore); ExplosionParticleSystem->addParticle(Pnt3f(10.0,0.0,0.0), 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)); ExplosionParticleSystem->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)); ExplosionParticleSystem->pushToGenerators(ExplosionParticleGenerator); AgeSizeParticleAffectorRecPtr ExampleAgeSizeParticleAffector = AgeSizeParticleAffector::create(); //Age and size ExampleAgeSizeParticleAffector->editMFAges()->push_back(0.0); ExampleAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(0.2,0.2,0.2)); ExampleAgeSizeParticleAffector->editMFAges()->push_back(1.0); ExampleAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(4.0,4.0,4.0)); ExampleAgeSizeParticleAffector->editMFAges()->push_back(1.8); ExampleAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(2.2,2.2,0.1)); //Age Fade Affector AgeFadeParticleAffectorRecPtr ExampleAgeFadeParticleAffector = AgeFadeParticleAffector::create(); //Age and size ExampleAgeFadeParticleAffector->setStartAlpha(0.0f); ExampleAgeFadeParticleAffector->setFadeInTime(0.5f); ExampleAgeFadeParticleAffector->setFadeToAlpha(1.0f); ExampleAgeFadeParticleAffector->setFadeOutTime(0.5f); ExampleAgeFadeParticleAffector->setEndAlpha(0.0f); ExplosionParticleSystem->pushToAffectors(ExampleAgeFadeParticleAffector); //Smoke Particle System VortexParticleAffectorRecPtr SmokeVortexAffector = VortexParticleAffector::create(); SmokeVortexAffector->setMagnitude(0.2); SmokeVortexAffector->setVortexAxis(Vec3f(0.0,1.0,0.0)); // field rotates around y axis NodeRefPtr VortexBeacon = makeCoredNode<Group>(); SmokeVortexAffector->setBeacon(VortexBeacon); // set to 'emulate' from (0,0,0) SmokeVortexAffector->setMaxDistance(-1.0); // particles affected regardless of distance SmokeVortexAffector->setAttenuation(0.25); // strength of uniform field dimishes by dist^attenuation AgeFadeParticleAffectorRecPtr SmokeAgeFadeParticleAffector = AgeFadeParticleAffector::create(); //Age and size SmokeAgeFadeParticleAffector->setStartAlpha(0.0f); SmokeAgeFadeParticleAffector->setFadeInTime(0.2f); SmokeAgeFadeParticleAffector->setFadeToAlpha(1.0f); SmokeAgeFadeParticleAffector->setFadeOutTime(3.5f); SmokeAgeFadeParticleAffector->setEndAlpha(0.0f); RateParticleGeneratorRecPtr SmokeParticleGenerator = RateParticleGenerator::create(); SmokeParticleGenerator->setSizeDistribution(createSmokeSizeDistribution()); SmokeParticleGenerator->setPositionDistribution(createSmokePositionDistribution()); SmokeParticleGenerator->setLifespanDistribution(createSmokeLifespanDistribution()); SmokeParticleGenerator->setVelocityDistribution(createSmokeVelocityDistribution()); SmokeParticleGenerator->setColorDistribution(createSmokeColorDistribution()); SmokeParticleGenerator->setGenerationRate(80.0f); ParticleSystemRecPtr SmokeParticleSystem = ParticleSystem::create(); SmokeParticleSystem->pushToGenerators(SmokeParticleGenerator); SmokeParticleSystem->attachUpdateProducer(TutorialWindow); SmokeParticleSystem->pushToAffectors(SmokeAgeFadeParticleAffector); SmokeParticleSystem->pushToAffectors(SmokeVortexAffector); TextureObjChunkRefPtr SmokeTextureObjChunk = TextureObjChunk::create(); ImageRefPtr SmokeImage = ImageFileHandler::the()->read("Data/Smoke.png"); SmokeTextureObjChunk->setImage(SmokeImage); ChunkMaterialRefPtr SmokeMaterial = ChunkMaterial::create(); SmokeMaterial->addChunk(SmokeTextureObjChunk); SmokeMaterial->addChunk(QuadTextureEnvChunk); SmokeMaterial->addChunk(PSMaterialChunk); SmokeMaterial->addChunk(PSBlendChunk); SmokeMaterial->setSortKey(-1.0f); QuadParticleSystemDrawerRecPtr SmokeParticleSystemDrawer = QuadParticleSystemDrawer::create(); ParticleSystemCoreRefPtr SmokeParticleCore = ParticleSystemCore::create(); SmokeParticleCore->setSystem(SmokeParticleSystem); SmokeParticleCore->setDrawer(SmokeParticleSystemDrawer); SmokeParticleCore->setMaterial(SmokeMaterial); SmokeParticleCore->setSortingMode(ParticleSystemCore::BACK_TO_FRONT); NodeRefPtr SmokeParticleNode = Node::create(); SmokeParticleNode->setCore(SmokeParticleCore); // Make Main Scene Node and add the Torus NodeRefPtr scene = makeCoredNode<Group>(); scene->addChild(ExplosionParticleNode); scene->addChild(SmokeParticleNode); scene->addChild(VortexBeacon); 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, "06Explosion"); //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); 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)); TutorialWindow->connectKeyTyped(boost::bind(keyPressed, _1)); // Make Main Scene Node NodeRecPtr Scene = makeCoredNode<Group>(); NodeRecPtr TorusNode = createTorus(); NodeRecPtr SphereNode = createSphere(); NodeRecPtr ConeNode = createCone(); NodeRecPtr BoxNode = createBox(); Scene->addChild(TorusNode); Scene->addChild(SphereNode); Scene->addChild(ConeNode); Scene->addChild(BoxNode); // Create the Graphics GraphicsRecPtr TutorialGraphics = Graphics2D::create(); // Initialize the LookAndFeelManager to enable default settings LookAndFeelManager::the()->getLookAndFeel()->init(); /****************************************************** Create a Background ******************************************************/ ColorLayerRecPtr GreyBackground = ColorLayer::create(); GreyBackground->setColor(Color4f(.93,.93,.93,1.0)); /****************************************************** Create some Borders ******************************************************/ LineBorderRecPtr PanelBorder = LineBorder::create(); EmptyBorderRecPtr Panel1Border = EmptyBorder::create(); EmptyBorderRecPtr Panel2Border = EmptyBorder::create(); EmptyBorderRecPtr emptyBorder = EmptyBorder::create(); PanelBorder->setColor(Color4f(0.0,0.0,0.0,1.0)); PanelBorder->setWidth(1); Panel1Border->setTopWidth(0); Panel1Border->setBottomWidth(6); Panel1Border->setLeftWidth(0); Panel1Border->setRightWidth(0); Panel2Border->setTopWidth(0); Panel2Border->setBottomWidth(0); Panel2Border->setLeftWidth(0); Panel2Border->setRightWidth(0); /****************************************************** Create some Labels and stuff to go with them ******************************************************/ LabelRecPtr LeftPanelLabel1 = Label::create(); UIFontRecPtr LeftPanelLabel1Font = UIFont::create(); LeftPanelLabel1Font->setSize(50); LeftPanelLabel1->setBorders(emptyBorder); LeftPanelLabel1->setBackgrounds(GreyBackground); LeftPanelLabel1->setFont(LeftPanelLabel1Font); LeftPanelLabel1->setText("OSG Gui"); LeftPanelLabel1->setPreferredSize(Vec2f(300, 100)); LeftPanelLabel1->setAlignment(Vec2f(0.0f, 0.5f)); /****************************************************** Create some Layouts ******************************************************/ BoxLayoutRecPtr MainInternalWindowLayout = BoxLayout::create(); FlowLayoutRecPtr LeftPanelLayout = FlowLayout::create(); BoxLayoutRecPtr RightPanelLayout = BoxLayout::create(); MainInternalWindowLayout->setOrientation(BoxLayout::HORIZONTAL_ORIENTATION); LeftPanelLayout->setOrientation(FlowLayout::HORIZONTAL_ORIENTATION); LeftPanelLayout->setMinorAxisAlignment(1.0f); RightPanelLayout->setOrientation(BoxLayout::VERTICAL_ORIENTATION); /****************************************************** Create MainFrame and Panels ******************************************************/ PanelRecPtr LeftPanel = Panel::createEmpty(); PanelRecPtr RightPanel = Panel::createEmpty(); // LeftPanel stuff LeftPanel->setPreferredSize(Vec2f(400, 500)); LeftPanel->pushToChildren(LeftPanelLabel1); PanelRecPtr LeftPanelButtonPanel = createLeftPanelButtonPanel(); LeftPanel->pushToChildren(LeftPanelButtonPanel); PanelRecPtr LeftPanelRadioTextPanel = createLeftPanelRadioTextPanel(); LeftPanel->pushToChildren(LeftPanelRadioTextPanel); LeftPanel->setLayout(LeftPanelLayout); LeftPanel->setBackgrounds(GreyBackground); LeftPanel->setBorders(Panel1Border); //RightPanel stuff RightPanel->setPreferredSize(Vec2f(200, 620)); PanelRecPtr RightPanelButtonPanel = createRightPanelButtonPanel(); RightPanel->pushToChildren(RightPanelButtonPanel); PanelRecPtr RightPanelCheckPanel = createRightPanelCheckPanel(TorusNode, SphereNode, ConeNode, BoxNode); RightPanel->pushToChildren(RightPanelCheckPanel); RightPanel->setLayout(RightPanelLayout); RightPanel->setBackgrounds(GreyBackground); RightPanel->setBorders(Panel2Border); // Create The Main InternalWindow InternalWindowRecPtr MainInternalWindow = InternalWindow::create(); MainInternalWindow->pushToChildren(LeftPanel); MainInternalWindow->pushToChildren(RightPanel); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(GreyBackground); MainInternalWindow->setBorders(PanelBorder); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(1.0f,1.0f)); MainInternalWindow->setDrawTitlebar(false); MainInternalWindow->setResizable(false); //MainInternalWindow->setOpacity(0.7f); // Create the Drawing Surface UIDrawingSurfaceRecPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); // Make A 3D Rectangle to draw the UI on UIRectangleRecPtr UIRectCore = UIRectangle::create(); UIRectCore->setPoint(Pnt3f(-310.0,-310.0,370.0)); UIRectCore->setWidth(620); UIRectCore->setHeight(620); UIRectCore->setDrawingSurface(TutorialDrawingSurface); NodeRecPtr UIRectNode = Node::create(); UIRectNode->setCore(UIRectCore); // add the UIRect as a child Scene->addChild(UIRectNode); sceneManager.setRoot(Scene); // Show the whole Scene sceneManager.showAll(); //Create the Documentation Foreground and add it to the viewport SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "21ExampleInterface"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
// Initialize WIN32 & OpenSG and set up the scene int main(int argc, char **argv) { preloadSharedObject("OSGTBFileIO"); // 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)); TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1)); // create the scene NodeUnrecPtr scene = makeTorus(1.0, 2.0, 16, 16); sceneManager.setRoot (scene); //Create the Documentation SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow); // show the whole scene sceneManager.showAll(); //Load Sound Definitions FCFileType::FCPtrStore NewContainers; NewContainers = FCFileHandler::the()->read(BoostPath("Data/04SoundData.xml")); FCFileType::FCPtrStore::iterator Itor; for(Itor = NewContainers.begin() ; Itor != NewContainers.end() ; ++Itor) { //Get Sounds if( (*Itor)->getType().isDerivedFrom(Sound::getClassType())) { Sounds.push_back(dynamic_pointer_cast<Sound>(*Itor)); Sounds.back()->connectSoundPlayed (boost::bind(handleSoundPlayed, _1)); Sounds.back()->connectSoundStopped (boost::bind(handleSoundStopped, _1)); Sounds.back()->connectSoundPaused (boost::bind(handleSoundPaused, _1)); Sounds.back()->connectSoundUnpaused(boost::bind(handleSoundUnpaused, _1)); Sounds.back()->connectSoundLooped (boost::bind(handleSoundLooped, _1)); } //Get Sound Groups if( (*Itor)->getType().isDerivedFrom(SoundGroup::getClassType())) { SoundGroups.push_back(dynamic_pointer_cast<SoundGroup>(*Itor)); } } //Initialize the Sound Manager SoundManager::the()->attachUpdateProducer(TutorialWindow); SoundManager::the()->setCamera(sceneManager.getCamera()); Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "04 XML Sound Loading Window"); //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 SimpleSceneManagerRefPtr sceneManager = SimpleSceneManager::create(); TutorialWindow->setDisplayCallback(boost::bind(display, sceneManager)); TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, sceneManager)); 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)); TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1)); // Tell the Manager what to manage sceneManager->setWindow(TutorialWindow); // Make Torus Node (creates Torus in background of scene) NodeRecPtr TorusGeometryNode = makeTorus(90, 270, 16, 16); // Make Main Scene Node and add the Torus NodeRecPtr scene = Node::create(); scene->setCore(Group::create()); scene->addChild(TorusGeometryNode); // Create the Graphics GraphicsRecPtr TutorialGraphics = Graphics2D::create(); // Initialize the LookAndFeelManager to enable default settings LookAndFeelManager::the()->getLookAndFeel()->init(); /****************************************************** The Drawing Surface is created the same as with previous Tutorials (however the MainInternalWindow is created in a function below). ******************************************************/ UIDrawingSurfaceRecPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->setCursorAsImage(WindowEventProducer::CURSOR_POINTER, BoostPath("./Data/cursor.png"), Vec2f(-1.0f,-1.0f), Vec2f(-12.0f,-20.0f)); InternalWindowRecPtr MainUIWindow = createMainInternalWindow(); TutorialDrawingSurface->openWindow(MainUIWindow); /****************************************************** Create the 3D UIRectangle. This allows the DrawingSurface to be rotated relative to the screen, allowing a 3D aspect to the DrawingSurface. The Surface can still be interacted with, so Buttons, Menus, etc. all will still function normally. -setPoint(Pnt3f): Determine the location of the UIRectangle in 3D space. Keep in mind that (0,0,0) is located directly in the center of the sceen. (For our purposes it is the center of the tori.) The point is located on the lower left corner of the rectangle. -setWidth(float): Determine the Width of the UIRectangle. This may physically appear different depending on where the UIRectangle is placed as above (due to it being located further away, etc). -setHeight(float): Determine the Height of the UIRectangle. This may physically appear different depending on where the UIRectangle is placed as above (due to it being located further away, etc). -setDrawingSurface(DrawingSurface): Determine what DrawingSurface is drawn on the UIRectangle. This will typically be the main DrawingSurface, however, multiple DrawingSurfaces can be used with multiple UIRectangles. ******************************************************/ //Make A 3D Rectangle to draw the UI on UIRectangleRecPtr ExampleUIRectangle = UIRectangle::create(); ExampleUIRectangle->setPoint(Pnt3f(-250,-250,200)); ExampleUIRectangle->setWidth(500.0); ExampleUIRectangle->setHeight(500.0); ExampleUIRectangle->setDrawingSurface(TutorialDrawingSurface); /****************************************************** Because the previous Tutorials used a Viewport to view the scene, which is no longer being used, the UIRectangle must be added to the scene for it to be displayed (identical to how the Torus is added). First, create a Node, and set its core to be the UIRectangle. Then, add that to the scene Node which is created above. This scene is then set as the Root for the view. It is possible to change this Root to be just the UIRectangle (as commented out below). ******************************************************/ NodeRecPtr ExampleUIRectangleNode = Node::create(); ExampleUIRectangleNode->setCore(ExampleUIRectangle); // Add the UIRectangle as a child to the scene scene->addChild(ExampleUIRectangleNode); // Tell the Manager what to manage sceneManager->setRoot(scene); //sceneManager->setRoot(ExampleUIRectangleNode); // Show the whole Scene sceneManager->showAll(); //Create the Documentation Foreground and add it to the viewport SimpleScreenDoc TheSimpleScreenDoc(sceneManager, TutorialWindow); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "20UIRectangle"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }