int main(int argc, char **argv) { // OSG init osgInit(argc,argv); // Set up Window TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); TutorialWindow->setDisplayCallback(display); TutorialWindow->setReshapeCallback(reshape); TutorialKeyListener TheKeyListener; TutorialWindow->addKeyListener(&TheKeyListener); TutorialMouseListener TheTutorialMouseListener; TutorialMouseMotionListener TheTutorialMouseMotionListener; TutorialWindow->addMouseListener(&TheTutorialMouseListener); TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(TutorialWindow); //Particle System Material PointChunkRefPtr PSPointChunk = PointChunk::create(); PSPointChunk->setSize(20.0f); PSPointChunk->setSmooth(true); BlendChunkRefPtr PSBlendChunk = BlendChunk::create(); PSBlendChunk->setSrcFactor(GL_SRC_ALPHA); PSBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA); MaterialChunkRefPtr PSMaterialChunkChunk = MaterialChunk::create(); PSMaterialChunkChunk->setAmbient(Color4f(0.3f,0.3f,0.3f,1.0f)); PSMaterialChunkChunk->setDiffuse(Color4f(0.7f,0.7f,0.7f,1.0f)); PSMaterialChunkChunk->setSpecular(Color4f(0.9f,0.9f,0.9f,1.0f)); PSMaterialChunkChunk->setColorMaterial(GL_AMBIENT_AND_DIFFUSE); ChunkMaterialRefPtr PSMaterial = ChunkMaterial::create(); PSMaterial->addChunk(PSPointChunk); PSMaterial->addChunk(PSMaterialChunkChunk); PSMaterial->addChunk(PSBlendChunk); Distribution3DRefPtr PositionDistribution = createPositionDistribution(); Distribution1DRefPtr LifespanDistribution = createLifespanDistribution(); Pnt3f PositionReturnValue; Time LifespanReturnValue = -1; //Particle System ParticleSystemRefPtr ExampleParticleSystem = OSG::ParticleSystem::create(); for(UInt32 i(0) ; i<200 ; ++i)//controls how many particles are created { if(PositionDistribution != NULL) { PositionReturnValue = Pnt3f(PositionDistribution->generate()); } if(LifespanDistribution != NULL) { LifespanReturnValue = LifespanDistribution->generate(); } ExampleParticleSystem->addParticle( PositionReturnValue, Vec3f(0.0f,0.0f,1.0f), Color4f(1.0,0.0,0.0,1.0), Vec3f(1.0,1.0,1.0), LifespanReturnValue, Vec3f(0.0f,0.0f,0.0f), //Velocity Vec3f(0.0f,0.0f,0.0f) //acceleration ); } ExampleParticleSystem->attachUpdateListener(TutorialWindow); //Particle System Drawer PointParticleSystemDrawerRefPtr ExampleParticleSystemDrawer = OSG::PointParticleSystemDrawer::create(); //Create an CollectiveGravityParticleSystemAffector CollectiveGravityParticleSystemAffectorRefPtr ExampleCollectiveGravityParticleSystemAffector = OSG::CollectiveGravityParticleSystemAffector::create(); ExampleCollectiveGravityParticleSystemAffector->setParticleMass(10000000000.0f); ExampleParticleSystem->pushToSystemAffectors(ExampleCollectiveGravityParticleSystemAffector); //Particle System Node ParticleSystemCoreRefPtr ParticleNodeCore = OSG::ParticleSystemCore::create(); ParticleNodeCore->setSystem(ExampleParticleSystem); ParticleNodeCore->setDrawer(ExampleParticleSystemDrawer); ParticleNodeCore->setMaterial(PSMaterial); NodeRefPtr ParticleNode = OSG::Node::create(); ParticleNode->setCore(ParticleNodeCore); // Make Main Scene Node and add the Torus NodeRefPtr scene = OSG::Node::create(); scene->setCore(OSG::Group::create()); scene->addChild(ParticleNode); mgr->setRoot(scene); // Show the whole Scene mgr->showAll(); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "10GravityParticleSystemAffector"); //Enter main Loop TutorialWindow->mainLoop(); osgExit(); return 0; }
// Initialize WIN32 & OpenSG and set up the scene int main(int argc, char **argv) { // OSG init osgInit(argc,argv); { // create the scene NodeRecPtr scene = makeTorus(.5, 2, 16, 16); //Create a Window object WindowEventProducerRefPtr TheWindow = createNativeWindow(); //Apply window settings TheWindow->setUseCallbackForDraw(true); TheWindow->setUseCallbackForReshape(true); //TheWindow->setFullscreen(true); //Initialize Window TheWindow->initWindow(); commitChanges(); // create the SimpleSceneManager helper SimpleSceneManager sceneManager; TheWindow->setDisplayCallback(boost::bind(display, &sceneManager)); TheWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager)); // tell the manager what to manage sceneManager.setWindow(TheWindow); sceneManager.setRoot (scene); //Attach to the Mouse Events TheWindow->connectMouseClicked(boost::bind(mouseClicked, _1)); TheWindow->connectMousePressed(boost::bind(mousePressed, _1, &sceneManager)); TheWindow->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager)); TheWindow->connectMouseMoved(boost::bind(mouseMoved, _1, &sceneManager)); TheWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager)); TheWindow->connectMouseEntered(boost::bind(mouseEntered, _1)); TheWindow->connectMouseExited(boost::bind(mouseExited, _1)); TheWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager)); //Attach to the Key Events TheWindow->connectKeyPressed(boost::bind(keyPressed, _1)); TheWindow->connectKeyReleased(boost::bind(keyReleased, _1)); TheWindow->connectKeyTyped(boost::bind(keyTyped, _1)); //Attach to the Window Events TheWindow->connectWindowOpened(boost::bind(windowOpened, _1)); TheWindow->connectWindowClosing(boost::bind(windowClosing, _1)); TheWindow->connectWindowClosed(boost::bind(windowClosed, _1)); TheWindow->connectWindowIconified(boost::bind(windowIconified, _1)); TheWindow->connectWindowDeiconified(boost::bind(windowDeiconified, _1)); TheWindow->connectWindowActivated(boost::bind(windowActivated, _1)); TheWindow->connectWindowDeactivated(boost::bind(windowDeactivated, _1)); TheWindow->connectWindowEntered(boost::bind(windowEntered, _1)); TheWindow->connectWindowExited(boost::bind(windowExited, _1)); //Create the Documentation Foreground and add it to the viewport SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TheWindow); // show the whole scene sceneManager.showAll(); // show statistics sceneManager.setStatistics(true); //Open Window Vec2f WinSize(TheWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TheWindow->getDesktopSize() - WinSize) *0.5); TheWindow->openWindow(WinPos, WinSize, "01 Native Window"); //Enter main loop TheWindow->mainLoop(); } osgExit(); return 0; }
Int32 MainApplication::run(int argc, char **argv) { //Get the date/time run _DateTimeRun = boost::posix_time::second_clock::local_time(); //Get the path to the command BoostPath CommandPath(argv[0]); if(!CommandPath.is_complete() && !CommandPath.has_root_directory()) { CommandPath = boost::filesystem::complete(CommandPath); } CommandPath.normalize(); //Parse the Program arguments boost::program_options::variables_map OptionsVariableMap; try { boost::program_options::store(boost::program_options::command_line_parser(argc, argv). options(_OptionsDescription). #ifdef __APPLE__ extra_parser(procSerialNumParser). #endif positional(_PositionalOptions).run(), OptionsVariableMap); boost::program_options::notify(OptionsVariableMap); } catch(boost::program_options::error& e) { std::cout << "Error parsing command line: " << e.what() << std::endl; printCommandLineHelp(); } //Check for the help argument if(OptionsVariableMap.count("help")) { printCommandLineHelp(); return 1; } //Setup the Logging LogLevel KELogLevel(LOG_NOTICE); if(OptionsVariableMap.count("log-level")) { KELogLevel = OptionsVariableMap["log-level"].as<LogLevel>(); } _LogFilePath = getLoggingDir() / BoostPath(boost::posix_time::to_iso_string(_DateTimeRun) + ".log"); //ISO date/time format if(OptionsVariableMap.count("log-file")) { _LogFilePath = BoostPath(OptionsVariableMap["log-file"].as<std::string>()); } if(OptionsVariableMap.count("disable-log")) { _EnableLogging = false; } if(OptionsVariableMap.count("disable-file-log")) { _LogToFile = false; } initializeLogging(_LogFilePath); osgLogP->setLogLevel(KELogLevel, true); osgLogP->setHeaderElem((LOG_TYPE_HEADER | LOG_FUNCNAME_HEADER), true); //Check if the last run crashed if(didCrashLastExecution()) { handleCrashLastExecution(); } //Create a file to indicate if a crash occurs createCrashIndicationFile(); // Set up Settings //Check for the settings file if(OptionsVariableMap.count("settings-file")) { setSettingsLoadFile(BoostPath(OptionsVariableMap["settings-file"].as<std::string>())); } else { //Use default location setSettingsLoadFile(getUserAppDataDir() / BoostPath("KEDefaultSettings.xml")); } loadSettings(getSettingsLoadFile()); //Cleanup the Logging Directory cleanupLoggingDir(); //If the settings aren't being overriden by the command-line options //then set the logging with the settings values if(!OptionsVariableMap.count("log-level")) { osgLogP->setLogLevel(static_cast<LogLevel>(getSettings().get<UInt8>("logging.level")), true); } osgLogP->setHeaderElem(getSettings().get<UInt32>("logging.header_elements"), true); //Initialize OpenSG initOpenSG(argc,argv); //Log information about the Engine { PLOG << "Starting Kabala Engine:" << std::endl; OSG::indentLog(4,PLOG); PLOG << "Arguments: "; for(UInt32 i(0) ; i<argc ; ++i) { PLOG << argv[i] << " "; } PLOG << std::endl; OSG::indentLog(4,PLOG); PLOG << "System:" << std::endl; OSG::indentLog(8,PLOG); PLOG << "Operating System: " << getPlatformName() << std::endl; OSG::indentLog(8,PLOG); PLOG << "Processor: " << getPlatformProcessors() << std::endl; OSG::indentLog(8,PLOG); PLOG << "RAM: " << getPlatformRAM() << std::endl; OSG::indentLog(4,PLOG); PLOG << "Time: " << to_simple_string(_DateTimeRun) << std::endl; OSG::indentLog(4,PLOG); PLOG << "Version: " << getKabalaEngineVersion() << std::endl; OSG::indentLog(8,PLOG); PLOG << "Revision: " << getKabalaEngineBuildRepositoryRevision() << std::endl; OSG::indentLog(8,PLOG); PLOG << "Build Type: " << getKabalaEngineBuildType() << std::endl; OSG::indentLog(4,PLOG); PLOG << "Working Directory: " << boost::filesystem::current_path().string() << std::endl; OSG::indentLog(4,PLOG); PLOG << "Executable Directory: " << CommandPath.parent_path().string() << std::endl; OSG::indentLog(4,PLOG); PLOG << "Settings File: " << getSettingsLoadFile().string() << std::endl; OSG::indentLog(4,PLOG); PLOG << "Logging: " << (_EnableLogging ? "Enabled" : "Disabled" ) << std::endl; if(_EnableLogging) { OSG::indentLog(8,PLOG); PLOG << "Log File: " << (_LogToFile ? _LogFilePath.string() : "Disabled" ) << std::endl; } } //Check if the Data Directory exists if(!boost::filesystem::exists(getSettings().get<BoostPath>("basic.data.directory"))) { BoostPath DataDirPath(getSettings().get<BoostPath>("basic.data.directory")); DataDirPath = boost::filesystem::complete(DataDirPath); DataDirPath.normalize(); SWARNING << "Could not find Application Data directory: \"" << DataDirPath.string() << "\" specified in the Settings file because the directory doesn't exist." << std::endl; //Try to find the data directory in a few locations std::vector<BoostPath> PathsToTry; #ifdef __APPLE__ PathsToTry.push_back(CommandPath.parent_path() / BoostPath("../Resources") / EngineAppDataDirectory); //Path to try for OS X Bundles PathsToTry.push_back(CommandPath.parent_path() / BoostPath("../Resources/share") / EngineAppDataDirectory); //Path to try for OS X Bundles #endif PathsToTry.push_back(BoostPath("/usr/local/share") / EngineAppDataDirectory); PathsToTry.push_back(BoostPath("/usr/share") / EngineAppDataDirectory); PathsToTry.push_back(CommandPath.parent_path() / EngineAppDataDirectory); PathsToTry.push_back(CommandPath.parent_path() / BoostPath("..") / EngineAppDataDirectory); PathsToTry.push_back(CommandPath.parent_path() / BoostPath("../share") / EngineAppDataDirectory); for(UInt32 i(0) ; i<PathsToTry.size() ; ++i) { SNOTICE << "Looking for Data directory in: " << PathsToTry[i].string() << std::endl; if(boost::filesystem::exists(PathsToTry[i])) { PNOTICE << "FOUND" << std::endl; PathsToTry[i].normalize(); getSettings().put("basic.data.directory",PathsToTry[i]); break; } else { PNOTICE << "NOT FOUND" << std::endl; } } } if(!boost::filesystem::exists(getSettings().get<BoostPath>("basic.data.directory"))) { SWARNING << "Could not find Application Data directory: \"" << getSettings().get<BoostPath>("basic.data.directory").string() << "\" because the directory doesn't exist." << std::endl; } else { SLOG << "Using Application Data directory: \"" << getSettings().get<BoostPath>("basic.data.directory").string() << "\"" << std::endl; } // Set up Window WindowEventProducerUnrecPtr MainWindow(createNativeWindow()); setMainWindow(MainWindow); setName(getMainWindow(),"__KABALA_ENGINE_WINDOW_EVENT_PRODUCER"); //If Fullscreen option -> Fullscreen if(OptionsVariableMap.count("fullscreen")) { getMainWindow()->setFullscreen(true); } //If no-fullscreen -> not Fullscreen else if(OptionsVariableMap.count("no-fullscreen")) { getMainWindow()->setFullscreen(false); } //else -> use the value in the settings else { getMainWindow()->setFullscreen(getSettings().get<bool>("basic.window.fullscreen")); } getMainWindow()->initWindow(); _WindowClosingConnection = getMainWindow()->connectWindowClosing(boost::bind(&MainApplication::handleWindowClosing, this, _1)); _WindowClosedConnection = getMainWindow()->connectWindowClosed(boost::bind(&MainApplication::handleWindowClosed, this, _1)); // Initialize the LookAndFeelManager to enable default settings KELookAndFeel::the()->init(); //Open Window Vec2f WindowSize(getSettings().get<Vec2f>("basic.window.size")); if(getSettings().get<Vec2f>("basic.window.size").x() <= 1.0f ) { WindowSize[0] = getMainWindow()->getDesktopSize().x() * getSettings().get<Vec2f>("basic.window.size").x(); } if(getSettings().get<Vec2f>("basic.window.size").y() <= 1.0f ) { WindowSize[1] = getMainWindow()->getDesktopSize().y() * getSettings().get<Vec2f>("basic.window.size").y(); } Pnt2f WindowPos(getSettings().get<Pnt2f>("basic.window.position")); if(getSettings().get<Pnt2f>("basic.window.position").x() < 0.0f ) { WindowPos[0] = (getMainWindow()->getDesktopSize().x() - WindowSize.x()) * 0.5f; } if(getSettings().get<Pnt2f>("basic.window.position").y() < 0.0f ) { WindowPos[1] = (getMainWindow()->getDesktopSize().y() - WindowSize.y()) * 0.5f; } getMainWindow()->openWindow(WindowPos, WindowSize, "Kabala Engine"); //Store a pointer to the application thread //_ApplicationThread = dynamic_cast<OSG::Thread *>(OSG::ThreadManager::getAppThread()); //Create the rendering thread //_RenderThread = OSG::dynamic_pointer_cast<OSG::Thread>(OSG::ThreadManager::the()->getThread("__KABALA_ENGINE_RENDER_THREAD", true)); //Create the loading thread //_LoadingThread = OSG::dynamic_pointer_cast<OSG::Thread>(OSG::ThreadManager::the()->getThread("__KABALA_ENGINE_LOADING_THREAD", true)); //Draw the loading thread activateLoadingScreen(); //Load the Project file, if given if(OptionsVariableMap.count("project-file")) { loadProject(BoostPath(OptionsVariableMap["project-file"].as<std::string>())); } else if(getSettings().get<bool>("basic.load_most_recent_project")) { boost::optional<BoostPath> LastOpenedProjectFile = getSettings().get_optional<BoostPath>("basic.last_opened_project"); if(LastOpenedProjectFile) { loadProject(LastOpenedProjectFile.get()); commitChanges(); } } if(getProject() == NULL) { //Project Failed to load, or file didn't exist ProjectRecPtr NewProject = createDefaultProject(); setProject(NewProject); } //Detach the loading screen detachLoadingScreen(); #ifdef BUILD_WITH_WORLD_BUILDER if(OptionsVariableMap.count("builder")) { attachBuilder(); } else #endif if(OptionsVariableMap.count("play")) { attachPlayer(); if(OptionsVariableMap.count("debug")) { dynamic_cast<ApplicationPlayer*>(getPlayerMode())->enableDebug(true); } } else { #ifdef BUILD_WITH_WORLD_BUILDER if(getSettings().get<std::string>("basic.initial_mode").compare(std::string("builder")) == 0) { attachBuilder(); } else #endif if(getSettings().get<std::string>("basic.initial_mode").compare(std::string("play")) == 0) { attachPlayer(); if(OptionsVariableMap.count("debug") || getSettings().get<bool>("player.debugger.initially_active")) { dynamic_cast<ApplicationPlayer*>(getPlayerMode())->enableDebug(true); } } else { attachStartScreen(); } } //Start the render thread on aspect 1 //_RenderThread->runFunction(MainApplication::mainRenderLoop, 1, NULL); //Start the loading thread on aspect 2 //_LoadingThread->runFunction(MainApplication::mainLoadingLoop, 2, NULL); //Main Loop getMainWindow()->mainLoop(); //Exited Main Loop //Save Settings saveSettings(getSettingsLoadFile()); SLOG << "Stopping Kabala Engine" << std::endl; OSG::indentLog(4,PLOG); PLOG << "Time: " << to_simple_string(boost::posix_time::second_clock::local_time()) << std::endl; //OSG exit OSG::osgExit(); //Uninitialize logging uninitializeLogging(); //Create a file to indicate if a crash occurs removeCrashIndicationFile(); 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; }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); // Set up Window TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); TutorialWindow->setDisplayCallback(display); TutorialWindow->setReshapeCallback(reshape); TutorialKeyListener TheKeyListener; TutorialWindow->addKeyListener(&TheKeyListener); // Make Torus Node (creates Torus in background of scene) NodeRefPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16); // Make Main Scene Node and add the Torus NodeRefPtr scene = OSG::Node::create(); scene->setCore(OSG::Group::create()); scene->addChild(TorusGeometryNode); // Create the Graphics GraphicsRefPtr TutorialGraphics = OSG::Graphics2D::create(); // Initialize the LookAndFeelManager to enable default settings LookAndFeelManager::the()->getLookAndFeel()->init(); /****************************************************** Create and edit a few Button Components. ******************************************************/ ButtonRefPtr ExampleButton1 = OSG::Button::create(); ButtonRefPtr ExampleButton2 = OSG::Button::create(); ButtonRefPtr ExampleButton3 = OSG::Button::create(); ButtonRefPtr ExampleButton4 = OSG::Button::create(); ButtonRefPtr ExampleButton5 = OSG::Button::create(); ButtonRefPtr ExampleButton6 = OSG::Button::create(); ExampleButton1->setPreferredSize(Vec2f(200, 50)); ExampleButton4->setPreferredSize(Vec2f(50, 50)); /****************************************************** Create Flow Layout. Flow Layout arranges objects automatically within the Frame, so that depending on Frame size, the objects may appear in a vertical line, horizontal line, or multiple lines. Objects fill from the upper left hand corner of the Frame across, then down (when the line becomes full) while arranged Horizontally, or from the upper left hand corner across when arranged Vertically, starting a new column when necessary. You can experiment with this by changing the window size, changing the orientation, changing the PreferredSize of the Buttons, or adding more Buttons to the view. Note that if the Frame is too small or resized too much, the FlowLayout will become slightly distorted. For Layouts which will often be dynamically changed, FlowLayout is not the best choice. -setHorizontalGap(int): Determine the Horizontal gap in pixels between Components in FlowLayout. -setVerticalGap(int): Determine the Vertical gap in pixels between Components in FlowLayout. -setOrientation(ENUM): Determine whether the Layout is arranged Vertically or Horizontally. Takes HORIZONTAL_ORIENTATION or VERTICAL_ORIENTATION arguments. -setMajorAxisAlignment(ENUM): Determines the alignment of the entire Layout within its ComponentContainer. See below. -setMinorAxistAlignment(ENUM): Determines the alignment of Components within the Layout. See below. Both of the last two functions take the following arguments: AXIS_MAX_ALIGNMENT, AXIS_CENTER_ALIGNMENT, and AXIS_MIN_ALIGNMENT. MAX puts it to the bottom/right, CENTER centers it, and MIN puts it to the top/left (for Vertical/Horizontal as set above, respectively). ******************************************************/ FlowLayoutRefPtr MainInternalWindowLayout = OSG::FlowLayout::create(); MainInternalWindowLayout->setHorizontalGap(3.0f); MainInternalWindowLayout->setVerticalGap(3.0f); MainInternalWindowLayout->setOrientation(FlowLayout::VERTICAL_ORIENTATION); MainInternalWindowLayout->setMajorAxisAlignment(0.5f); MainInternalWindowLayout->setMinorAxisAlignment(1.0f); // Create The Main InternalWindow // Create Background to be used with the Main InternalWindow ColorLayerRefPtr MainInternalWindowBackground = OSG::ColorLayer::create(); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); InternalWindowRefPtr MainInternalWindow = OSG::InternalWindow::create(); MainInternalWindow->pushToChildren(ExampleButton1); MainInternalWindow->pushToChildren(ExampleButton2); MainInternalWindow->pushToChildren(ExampleButton3); MainInternalWindow->pushToChildren(ExampleButton4); MainInternalWindow->pushToChildren(ExampleButton5); MainInternalWindow->pushToChildren(ExampleButton6); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setDrawTitlebar(false); MainInternalWindow->setResizable(false); // Add a 10 pixel "padding" inside the MainFrame MainInternalWindow->setAllInsets(10); //Create the Drawing Surface UIDrawingSurfaceRefPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundRefPtr TutorialUIForeground = OSG::UIForeground::create(); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(TutorialWindow); mgr->setRoot(scene); // Add the UI Foreground Object to the Scene ViewportRefPtr TutorialViewport = mgr->getWindow()->getPort(0); TutorialViewport->addForeground(TutorialUIForeground); // Show the whole Scene mgr->showAll(); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "05FlowLayout"); //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 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; }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); // Set up Window TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); TutorialWindow->setDisplayCallback(display); TutorialWindow->setReshapeCallback(reshape); TutorialKeyListener TheKeyListener; TutorialWindow->addKeyListener(&TheKeyListener); TutorialMouseListener TheTutorialMouseListener; TutorialMouseMotionListener TheTutorialMouseMotionListener; TutorialWindow->addMouseListener(&TheTutorialMouseListener); TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(TutorialWindow); BlendChunkRefPtr PSBlendChunk = BlendChunk::create(); PSBlendChunk->setSrcFactor(GL_SRC_ALPHA); PSBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA); //Particle System Material TextureObjChunkRefPtr QuadTextureObjChunk = TextureObjChunk::create(); ImageRefPtr LoadedImage = ImageFileHandler::the()->read("./Data/Cloud.png"); QuadTextureObjChunk->setImage(LoadedImage); MaterialChunkRefPtr PSMaterialChunk = MaterialChunk::create(); PSMaterialChunk->setAmbient(Color4f(0.3f,0.3f,0.3f,1.0f)); PSMaterialChunk->setDiffuse(Color4f(0.7f,0.7f,0.7f,1.0f)); PSMaterialChunk->setSpecular(Color4f(0.9f,0.9f,0.9f,1.0f)); PSMaterialChunk->setColorMaterial(GL_AMBIENT_AND_DIFFUSE); ChunkMaterialRefPtr PSMaterial = ChunkMaterial::create(); PSMaterial->addChunk(QuadTextureObjChunk); PSMaterial->addChunk(PSMaterialChunk); PSMaterial->addChunk(PSBlendChunk); //Particle System Material 2 TextureObjChunkRefPtr QuadTextureObjChunk2 = TextureObjChunk::create(); ImageRefPtr LoadedImage2 = ImageFileHandler::the()->read("./Data/Cloud.png"); QuadTextureObjChunk2->setImage(LoadedImage2); MaterialChunkRefPtr PSMaterialChunk2 = MaterialChunk::create(); PSMaterialChunk2->setAmbient(Color4f(0.3f,0.3f,0.3f,1.0f)); PSMaterialChunk2->setDiffuse(Color4f(0.7f,0.7f,0.7f,1.0f)); PSMaterialChunk2->setSpecular(Color4f(0.9f,0.9f,0.9f,1.0f)); PSMaterialChunk2->setColorMaterial(GL_AMBIENT_AND_DIFFUSE); ChunkMaterialRefPtr PSMaterial2 = ChunkMaterial::create(); PSMaterial2->addChunk(QuadTextureObjChunk2); PSMaterial2->addChunk(PSMaterialChunk2); PSMaterial2->addChunk(PSBlendChunk); //Particle System Example1ParticleSystem = OSG::ParticleSystem::create(); Example1ParticleSystem->attachUpdateListener(TutorialWindow); Example2ParticleSystem = OSG::ParticleSystem::create(); Example2ParticleSystem->attachUpdateListener(TutorialWindow); //Particle System Drawer Example1ParticleSystemDrawer = OSG::QuadParticleSystemDrawer::create(); Example2ParticleSystemDrawer = OSG::QuadParticleSystemDrawer::create(); //Attach the function objects to the Generator //Generator 1 ExampleBurstGenerator = OSG::BurstParticleGenerator::create(); ExampleBurstGenerator->setPositionDistribution(createPositionDistribution()); ExampleBurstGenerator->setLifespanDistribution(createLifespanDistribution()); ExampleBurstGenerator->setBurstAmount(50.0); ExampleBurstGenerator->setVelocityDistribution(createVelocityDistribution()); ExampleBurstGenerator->setAccelerationDistribution(createAccelerationDistribution()); ExampleBurstGenerator->setSizeDistribution(createSizeDistribution()); //Generator 2 Example2BurstGenerator = OSG::BurstParticleGenerator::create(); Example2BurstGenerator->setPositionDistribution(createPositionDistribution()); Example2BurstGenerator->setLifespanDistribution(createLifespanDistribution()); Example2BurstGenerator->setBurstAmount(50.0); Example2BurstGenerator->setVelocityDistribution(createVelocityDistribution2()); Example2BurstGenerator->setAccelerationDistribution(createAccelerationDistribution()); Example2BurstGenerator->setSizeDistribution(createSizeDistribution()); //Particle System Node ParticleSystemCoreRefPtr ParticleNodeCore = OSG::ParticleSystemCore::create(); ParticleNodeCore->setSystem(Example1ParticleSystem); ParticleNodeCore->setDrawer(Example1ParticleSystemDrawer); ParticleNodeCore->setMaterial(PSMaterial); NodeRefPtr ParticleNode = OSG::Node::create(); ParticleNode->setCore(ParticleNodeCore); //Particle System Node2 ParticleSystemCoreRefPtr ParticleNodeCore2 = OSG::ParticleSystemCore::create(); ParticleNodeCore2->setSystem(Example2ParticleSystem); ParticleNodeCore2->setDrawer(Example2ParticleSystemDrawer); ParticleNodeCore2->setMaterial(PSMaterial2); NodeRefPtr ParticleNode2 = OSG::Node::create(); ParticleNode2->setCore(ParticleNodeCore2); //Ground Node NodeRefPtr GoundNode = makePlane(30.0,30.0,10,10); Matrix GroundTransformation; GroundTransformation.setRotate(Quaternion(Vec3f(1.0f,0.0,0.0), -3.14195f)); TransformRefPtr GroundTransformCore = Transform::create(); GroundTransformCore->setMatrix(GroundTransformation); NodeRefPtr GroundTransformNode = Node::create(); GroundTransformNode->setCore(GroundTransformCore); GroundTransformNode->addChild(GoundNode); // Make Main Scene Node and add the Torus NodeRefPtr scene = OSG::Node::create(); scene->setCore(OSG::Group::create()); scene->addChild(ParticleNode); scene->addChild(ParticleNode2); scene->addChild(GroundTransformNode); mgr->setRoot(scene); // Show the whole Scene mgr->showAll(); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "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)); //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); // Show the whole Scene sceneManager.showAll(); sceneManager.getCamera()->setFar(1000.0); std::cout << "Vortex Particle Affector Tutorial Controls:\n" << "1: Use point drawer\n" << "2: Use line drawer\n" << "3: Decrease vortex magnitude\n" << "4: Increase vortex magnitude\n" << "Ctrl + Q: Exit Tutorial"; //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 GLUT & OpenSG and set up the rootNode int main(int argc, char **argv) { // OSG init osgInit(argc,argv); // Set up Window TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); TutorialWindow->setDisplayCallback(display); TutorialWindow->setReshapeCallback(reshape); TutorialKeyListener TheKeyListener; TutorialWindow->addKeyListener(&TheKeyListener); TutorialMouseListener TheTutorialMouseListener; TutorialMouseMotionListener TheTutorialMouseMotionListener; TutorialWindow->addMouseListener(&TheTutorialMouseListener); TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(TutorialWindow); //Make Torus Node NodeUnrecPtr TorusNode = makeTorus(.5, 2, 32, 32); //Make Main Scene Node NodeUnrecPtr scene = makeCoredNode<Group>(); setName(scene, "scene"); rootNode = Node::create(); setName(rootNode, "rootNode"); ComponentTransformUnrecPtr Trans; Trans = ComponentTransform::create(); rootNode->setCore(Trans); // add the torus as a child rootNode->addChild(scene); //Setup Physics Scene 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)); //physicsSpace = PhysicsSimpleSpace::create(); //physicsSpace = PhysicsQuadTreeSpace::create(); //physicsSpace = PhysicsHashSpace::create(); physicsSpace = PhysicsSweepAndPruneSpace::create(); CollisionContactParametersUnrecPtr DefaultCollisionParams = CollisionContactParameters::createEmpty(); DefaultCollisionParams->setMode(dContactApprox1 | dContactBounce); DefaultCollisionParams->setMu(0.3); DefaultCollisionParams->setMu2(0.0); DefaultCollisionParams->setBounce(0.2); DefaultCollisionParams->setBounceSpeedThreshold(0.1); 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); physHandler = PhysicsHandler::create(); physHandler->setWorld(physicsWorld); physHandler->pushToSpaces(physicsSpace); physHandler->setUpdateNode(rootNode); physHandler->attachUpdateProducer(TutorialWindow->editEventProducer()); rootNode->addAttachment(physHandler); rootNode->addAttachment(physicsWorld); rootNode->addAttachment(physicsSpace); /************************************************************************/ /* create spaces, geoms and bodys */ /************************************************************************/ //create a group for our space GroupUnrecPtr spaceGroup; spaceGroupNode = makeCoredNode<Group>(&spaceGroup); //create the ground plane GeometryUnrecPtr plane; NodeUnrecPtr planeNode = makeBox(30.0, 30.0, 1.0, 1, 1, 1); plane = dynamic_cast<Geometry*>(planeNode->getCore()); //and its Material SimpleMaterialUnrecPtr 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 PhysicsBoxGeomUnrecPtr 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->addChild(planeNode); planeNode->addAttachment(planeGeom); scene->addChild(spaceGroupNode); //Create Statistics Foreground SimpleStatisticsForegroundUnrecPtr PhysicsStatForeground = SimpleStatisticsForeground::create(); PhysicsStatForeground->setSize(25); PhysicsStatForeground->setColor(Color4f(0,1,0,0.7)); PhysicsStatForeground->addElement(PhysicsHandler::statPhysicsTime, "Physics time: %.3f s"); PhysicsStatForeground->addElement(PhysicsHandler::statCollisionTime, "Collision time: %.3f s"); PhysicsStatForeground->addElement(PhysicsHandler::statSimulationTime, "Simulation time: %.3f s"); PhysicsStatForeground->addElement(PhysicsHandler::statNCollisions, "%d collisions"); PhysicsStatForeground->addElement(PhysicsHandler::statNCollisionTests, "%d collision tests"); PhysicsStatForeground->addElement(PhysicsHandler::statNPhysicsSteps, "%d simulation steps per frame"); // tell the manager what to manage mgr->setRoot (rootNode); mgr->getWindow()->getPort(0)->addForeground(PhysicsStatForeground); physHandler->setStatistics(PhysicsStatForeground->getCollector()); // show the whole rootNode mgr->showAll(); Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "05Explosion"); //Enter main Loop TutorialWindow->mainLoop(); osgExit(); return 0; }
//====================================================================== bool loadFile (const String& fileOrURLPath) { jassert (state == uninitializedState); if (! createNativeWindow()) return false; HRESULT hr = graphBuilder.CoCreateInstance (CLSID_FilterGraph); // basic playback interfaces if (SUCCEEDED (hr)) hr = graphBuilder.QueryInterface (mediaControl); if (SUCCEEDED (hr)) hr = graphBuilder.QueryInterface (mediaPosition); if (SUCCEEDED (hr)) hr = graphBuilder.QueryInterface (mediaEvent); if (SUCCEEDED (hr)) hr = graphBuilder.QueryInterface (basicAudio); // video renderer interface if (SUCCEEDED (hr)) { #if JUCE_MEDIAFOUNDATION if (type == dshowEVR) videoRenderer = new DirectShowHelpers::EVR(); else #endif videoRenderer = new DirectShowHelpers::VMR7(); hr = videoRenderer->create (graphBuilder, baseFilter, hwnd); } // build filter graph if (SUCCEEDED (hr)) hr = graphBuilder->RenderFile (fileOrURLPath.toWideCharPointer(), nullptr); // remove video renderer if not connected (no video) if (SUCCEEDED (hr)) { if (isRendererConnected()) { hasVideo = true; hr = videoRenderer->getVideoSize (videoWidth, videoHeight); } else { hasVideo = false; graphBuilder->RemoveFilter (baseFilter); videoRenderer = nullptr; baseFilter = nullptr; } } // set window to receive events if (SUCCEEDED (hr)) hr = mediaEvent->SetNotifyWindow ((OAHWND) hwnd, graphEventID, 0); if (SUCCEEDED (hr)) { state = stoppedState; return true; } release(); return false; }
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(keyPressed, _1)); // Make Torus Node (creates Torus in background of scene) NodeRecPtr TorusGeometryNode = makeTorus(.5, 2, 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(); // Create a simple Font to be used with the ExampleTextArea UIFontRecPtr ExampleFont = UIFont::create(); ExampleFont->setSize(16); /****************************************************** Create and edit the TextArea and determine its characteristics. A TextArea is a component that allows you to enter text into the box via keyboard input. You can select text by using your mouse or pressing shift and the left and right arrow keys. The only difference between a TextArea and TextField is that a TextArea can have multiple lines of text within it. -setTextColor(Color4f): Determine color of text within TextArea. -setSelectionBoxColor(Color4f): Determine the color that highlighting around the selected text appears. -setSelectionTextColor(Color4f): Determine the color the selected text appears. -setText("TextToBeDisplayed"): Determine initial text within TextArea. -setFont(FontName): Determine the Font used within TextArea -setSelectionStart(StartCharacterNumber): Determine the character which the selection will initially start after. -setSelectionEnd(EndCharacterNumber): Determine the character which the selection will end before. -setCaretPosition(Location): Determine the location of the Caret within the TextArea. Note: this does not do too much currently because the only way to cause the TextArea to gain focus is to click within it, causing the Caret to move. ******************************************************/ // Create a TextArea component TextAreaRecPtr ExampleTextArea = TextArea::create(); ExampleTextArea->setPreferredSize(Vec2f(300, 200)); ExampleTextArea->setMinSize(Vec2f(300, 200)); ExampleTextArea->setTextColor(Color4f(0.0, 0.0, 0.0, 1.0)); ExampleTextArea->setSelectionBoxColor(Color4f(0.0, 0.0, 1.0, 1.0)); ExampleTextArea->setSelectionTextColor(Color4f(1.0, 1.0, 1.0, 1.0)); // Determine the font and initial text ExampleTextArea->setText("What"); ExampleTextArea->setFont(ExampleFont); // This will select the "a" from above ExampleTextArea->setSelectionStart(2); ExampleTextArea->setSelectionEnd(3); ExampleTextArea->setCaretPosition(2); //ExampleTextArea->setLineWrap(false); // Create a ScrollPanel ScrollPanelRecPtr TextAreaScrollPanel = ScrollPanel::create(); TextAreaScrollPanel->setPreferredSize(Vec2f(200,200)); TextAreaScrollPanel->setHorizontalResizePolicy(ScrollPanel::RESIZE_TO_VIEW); // Add the TextArea to the ScrollPanel so it is displayed TextAreaScrollPanel->setViewComponent(ExampleTextArea); // Create The Main InternalWindow // Create Background to be used with the Main InternalWindow ColorLayerRecPtr MainInternalWindowBackground = ColorLayer::create(); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); LayoutRecPtr MainInternalWindowLayout = FlowLayout::create(); InternalWindowRecPtr MainInternalWindow = InternalWindow::create(); MainInternalWindow->pushToChildren(TextAreaScrollPanel); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setDrawTitlebar(false); MainInternalWindow->setResizable(false); // Create the Drawing Surface UIDrawingSurfaceRecPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundRecPtr TutorialUIForeground = UIForeground::create(); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); // Tell the Manager what to manage sceneManager.setRoot(scene); // Add the UI Foreground Object to the Scene ViewportRecPtr TutorialViewport = sceneManager.getWindow()->getPort(0); TutorialViewport->addForeground(TutorialUIForeground); //Create the Documentation Foreground and add it to the viewport SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow); // Show the whole Scene sceneManager.showAll(); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "22TextArea"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); // Set up Window TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); TutorialWindow->setDisplayCallback(display); TutorialWindow->setReshapeCallback(reshape); //Add Window Listener TutorialKeyListener TheKeyListener; TutorialWindow->addKeyListener(&TheKeyListener); TutorialMouseListener TheTutorialMouseListener; TutorialMouseMotionListener TheTutorialMouseMotionListener; TutorialWindow->addMouseListener(&TheTutorialMouseListener); TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(TutorialWindow); //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); //Read skeleton from XML file FCFileType::FCPtrStore NewContainers; NewContainers = FCFileHandler::the()->read(BoostPath("./Data/16Skeleton.xml")); SkeletonUnrecPtr ExampleSkeleton; FCFileType::FCPtrStore::iterator Itor; for(Itor = NewContainers.begin() ; Itor != NewContainers.end() ; ++Itor) { //Only import skeleton data; we ignore anything else saved in the XML file if( (*Itor)->getType() == (Skeleton::getClassType())) { //Set the Skeleton to the one we just read in ExampleSkeleton = (dynamic_pointer_cast<Skeleton>(*Itor)); } } //SkeletonDrawer SkeletonDrawableUnrecPtr ExampleSkeletonDrawable = SkeletonDrawable::create(); ExampleSkeletonDrawable->setSkeleton(ExampleSkeleton); ExampleSkeletonDrawable->setMaterial(ExampleMaterial); //Skeleton Particle System Node NodeUnrecPtr SkeletonNode = Node::create(); SkeletonNode->setCore(ExampleSkeletonDrawable); //Torus Node NodeUnrecPtr TorusNode = makeTorus(.5, 2, 32, 32); // Make Main Scene Node and add the Torus NodeUnrecPtr scene = Node::create(); scene->setCore(Group::create()); scene->addChild(SkeletonNode); //scene->addChild(TorusNode); scene->addChild(makeCoordAxis(10.0)); mgr->setRoot(scene); mgr->turnHeadlightOff(); // Show the whole Scene mgr->showAll(); //Create the Documentation SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow); Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "16LoadXMLSkeleton"); //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; }
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)); // 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); TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1, &sceneManager, ExampleParticleSystem.get(), ExamplePSTrailGenerator.get())); sceneManager.setRoot(scene); //Create the Documentation SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow); // Show the whole Scene sceneManager.getNavigator()->set(Pnt3f(0.0,0.0,100.0), Pnt3f(0.0,0.0,0.0), Vec3f(0.0,1.0,0.0)); sceneManager.getNavigator()->setMotionFactor(1.0f); sceneManager.getCamera()->setFar(10000.0f); sceneManager.getCamera()->setNear(0.1f); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "02ParticleSystemParticleTrail"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); // Set up Window TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); TutorialWindow->setDisplayCallback(display); TutorialWindow->setReshapeCallback(reshape); TutorialKeyListener TheKeyListener; TutorialWindow->addKeyListener(&TheKeyListener); // Make Torus Node (creates Torus in background of scene) NodeRefPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16); // Make Main Scene Node and add the Torus NodeRefPtr scene = OSG::Node::create(); scene->setCore(OSG::Group::create()); scene->addChild(TorusGeometryNode); // Create the Graphics GraphicsRefPtr TutorialGraphics = OSG::Graphics2D::create(); // Initialize the LookAndFeelManager to enable default settings LookAndFeelManager::the()->getLookAndFeel()->init(); //Background SolidBackgroundRefPtr TutorialBackground = SolidBackground::create(); TutorialBackground->setColor(Color3f(1.0,0.0,0.0)); TheUndoManager = UndoManager::create(); UndoManagerChangeListener TheUndoManagerChangeListener; TheUndoManager->addChangeListener(&TheUndoManagerChangeListener); TheCommandManager = CommandManager::create(TheUndoManager); //UndoList UndoRedoListModel = DefaultListModel::create(); UndoRedoListModel->pushBack(boost::any(std::string("Top"))); ListSelectionModelPtr UndoRedoListSelectionModel(new DefaultListSelectionModel()); UndoRedoList = List::create(); UndoRedoList->setPreferredSize(Vec2f(200, 300)); UndoRedoList->setOrientation(List::VERTICAL_ORIENTATION); UndoRedoList->setModel(UndoRedoListModel); UndoRedoList->setSelectionModel(UndoRedoListSelectionModel); UndoRedoListListener TheUndoRedoListListener; UndoRedoList->getSelectionModel()->addListSelectionListener(&TheUndoRedoListListener); UndoButton = OSG::Button::create(); UndoButton->setText("Undo"); UndoButton->setEnabled(TheUndoManager->numberOfUndos() != 0); UndoButtonActionListener TheUndoButtonActionListener; UndoButton->addActionListener(&TheUndoButtonActionListener); RedoButton = OSG::Button::create(); RedoButton->setText("Redo"); RedoButton->setEnabled(TheUndoManager->numberOfRedos() != 0); RedoButtonActionListener TheRedoButtonActionListener; RedoButton->addActionListener(&TheRedoButtonActionListener); // Create a ScrollPanel for easier viewing of the List (see 27ScrollPanel) ScrollPanelRefPtr UndoRedoScrollPanel = ScrollPanel::create(); UndoRedoScrollPanel->setPreferredSize(Vec2f(200,200)); UndoRedoScrollPanel->setHorizontalResizePolicy(ScrollPanel::RESIZE_TO_VIEW); UndoRedoScrollPanel->setViewComponent(UndoRedoList); //Background Editor Field //FieldEditorComponentRefPtr TheEditor = FieldEditorFactory::the()->createDefaultEditor(TutorialBackground, SolidBackground::ColorFieldId, TheCommandManager); FieldEditorComponentRefPtr TheEditor = FieldEditorFactory::the()->createDefaultEditor(RedoButton, Button::TextFieldId, TheCommandManager); TheEditor->setPreferredSize(Vec2f(100.0f, 20.0f)); // Create The Main InternalWindow // Create Background to be used with the Main InternalWindow ColorLayerRefPtr MainInternalWindowBackground = OSG::ColorLayer::create(); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); InternalWindowRefPtr MainInternalWindow = OSG::InternalWindow::create(); LayoutRefPtr MainInternalWindowLayout = OSG::FlowLayout::create(); MainInternalWindow->pushToChildren(TheEditor); MainInternalWindow->pushToChildren(UndoRedoScrollPanel); MainInternalWindow->pushToChildren(UndoButton); MainInternalWindow->pushToChildren(RedoButton); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.95f,0.95f)); MainInternalWindow->setDrawTitlebar(false); MainInternalWindow->setResizable(false); // Create the Drawing Surface UIDrawingSurfaceRefPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundRefPtr TutorialUIForeground = OSG::UIForeground::create(); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(TutorialWindow); mgr->setRoot(scene); // Add the UI Foreground Object to the Scene ViewportRefPtr TutorialViewport = mgr->getWindow()->getPort(0); TutorialViewport->addForeground(TutorialUIForeground); TutorialViewport->setBackground(TutorialBackground); // Show the whole Scene mgr->showAll(); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "02GenericFieldEditor"); //Enter main Loop TutorialWindow->mainLoop(); osgExit(); return 0; }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); { // Set up Window WindowEventProducerRecPtr TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); // Create the SimpleSceneManager helper SimpleSceneManager sceneManager; TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager)); TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager)); // Tell the Manager what to manage sceneManager.setWindow(TutorialWindow); //Attach to events TutorialWindow->connectMousePressed(boost::bind(mousePressed, _1, &sceneManager)); TutorialWindow->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager)); TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager)); TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager)); //Particle System Material PointChunkRefPtr PSPointChunk = PointChunk::create(); PSPointChunk->setSize(10.0f); PSPointChunk->setSmooth(true); BlendChunkRefPtr PSBlendChunk = BlendChunk::create(); PSBlendChunk->setSrcFactor(GL_SRC_ALPHA); PSBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA); MaterialChunkRefPtr PSMaterialChunkChunk = MaterialChunk::create(); PSMaterialChunkChunk->setAmbient(Color4f(0.2f,0.6f,0.5f,0.3f)); PSMaterialChunkChunk->setDiffuse(Color4f(0.2f,0.9f,0.1f,0.3f)); PSMaterialChunkChunk->setSpecular(Color4f(0.5f,0.4f,0.2f,0.6f)); PSMaterialChunkChunk->setEmission(Color4f(0.2f,0.6f,0.5f,0.3f)); PSMaterialChunkChunk->setColorMaterial(GL_NONE); //enable depth test DepthChunkRefPtr PSDepthChunk = DepthChunk::create(); ChunkMaterialRefPtr PSMaterial = ChunkMaterial::create(); PSMaterial->addChunk(PSPointChunk); PSMaterial->addChunk(PSMaterialChunkChunk); PSMaterial->addChunk(PSBlendChunk); PSMaterial->addChunk(PSDepthChunk); //Particle System ParticleSystemRefPtr ExampleParticleSystem = ParticleSystem::create(); ExampleParticleSystem->attachUpdateProducer(TutorialWindow); //Particle System Drawer //Point PointParticleSystemDrawerRecPtr ExamplePointParticleSystemDrawer = PointParticleSystemDrawer::create(); //ExamplePointParticleSystemDrawer->setForcePerParticleSizing(true); //Line LineParticleSystemDrawerRecPtr ExampleLineParticleSystemDrawer = LineParticleSystemDrawer::create(); ExampleLineParticleSystemDrawer->setLineDirectionSource(LineParticleSystemDrawer::DIRECTION_NORMAL);//DIRECTION_VELOCITY_CHANGE); ExampleLineParticleSystemDrawer->setLineLengthSource(LineParticleSystemDrawer::LENGTH_SIZE_X); ExampleLineParticleSystemDrawer->setEndPointFading(Vec2f(1.0,0.0)); //Quad QuadParticleSystemDrawerRecPtr ExampleQuadParticleSystemDrawer = QuadParticleSystemDrawer::create(); ExampleQuadParticleSystemDrawer->setQuadSizeScaling(Vec2f(0.1,0.1)); ExampleQuadParticleSystemDrawer->setNormalAndUpSource(QuadParticleSystemDrawer::NORMAL_PARTICLE_NORMAL,QuadParticleSystemDrawer::UP_STATIC); RateParticleGeneratorRefPtr ExampleGeneratorTheSequel = RateParticleGenerator::create(); //Attach the function objects to the Generator ExampleGeneratorTheSequel->setPositionDistribution(createPositionDistribution()); ExampleGeneratorTheSequel->setLifespanDistribution(createLifespanDistribution()); ExampleGeneratorTheSequel->setGenerationRate(300.0); ExampleGeneratorTheSequel->setVelocityDistribution(createVelocityDistribution()); //Attach the Generator to the Particle System //ExampleParticleSystem->pushToGenerators(ExampleGenerator); ExampleParticleSystem->setMaxParticles(500); ExampleParticleSystem->pushToGenerators(ExampleGeneratorTheSequel); //Particle System Node ParticleSystemCoreRecPtr ParticleNodeCore = ParticleSystemCore::create(); ParticleNodeCore->setSystem(ExampleParticleSystem); ParticleNodeCore->setDrawer(ExampleQuadParticleSystemDrawer); ParticleNodeCore->setMaterial(PSMaterial); ParticleNodeCore->setSortingMode(ParticleSystemCore::BACK_TO_FRONT); NodeRefPtr ParticleNode = Node::create(); ParticleNode->setCore(ParticleNodeCore); // Make Main Scene Node and add the Torus NodeRefPtr scene = Node::create(); scene->setCore(Group::create()); scene->addChild(ParticleNode); TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1, &sceneManager, ParticleNodeCore.get(), ExamplePointParticleSystemDrawer.get(), ExampleLineParticleSystemDrawer.get(), ExampleQuadParticleSystemDrawer.get())); sceneManager.setRoot(scene); //Create the Documentation SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow); // Show the whole Scene sceneManager.showAll(); sceneManager.getCamera()->setFar(500.0); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "14ParticleSorting"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); // Set up Window TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); TutorialWindow->setDisplayCallback(display); TutorialWindow->setReshapeCallback(reshape); TutorialKeyListener TheKeyListener; TutorialWindow->addKeyListener(&TheKeyListener); TutorialMouseListener TheTutorialMouseListener; TutorialMouseMotionListener TheTutorialMouseMotionListener; TutorialWindow->addMouseListener(&TheTutorialMouseListener); TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(TutorialWindow); //Particle System Material //point material PointChunkRefPtr PSPointChunk = PointChunk::create(); PSPointChunk->setSize(5.0f); PSPointChunk->setSmooth(true); BlendChunkRefPtr PSBlendChunk = BlendChunk::create(); PSBlendChunk->setSrcFactor(GL_SRC_ALPHA); PSBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA); MaterialChunkRefPtr PSMaterialChunkChunk = MaterialChunk::create(); PSMaterialChunkChunk->setAmbient(Color4f(0.3f,0.3f,0.3f,1.0f)); PSMaterialChunkChunk->setDiffuse(Color4f(0.7f,0.7f,0.7f,1.0f)); PSMaterialChunkChunk->setSpecular(Color4f(0.9f,0.9f,0.9f,1.0f)); PSMaterialChunkChunk->setColorMaterial(GL_AMBIENT_AND_DIFFUSE); ChunkMaterialRefPtr PSPointMaterial = ChunkMaterial::create(); PSPointMaterial->addChunk(PSPointChunk); PSPointMaterial->addChunk(PSMaterialChunkChunk); PSPointMaterial->addChunk(PSBlendChunk); //smoke material TextureObjChunkRefPtr QuadTextureObjChunk = TextureObjChunk::create(); ImageRefPtr LoadedImage = ImageFileHandler::the()->read("Data/Checker.jpg"); QuadTextureObjChunk->setImage(LoadedImage); TextureEnvChunkRefPtr QuadTextureEnvChunk = TextureEnvChunk::create(); QuadTextureEnvChunk->setEnvMode(GL_MODULATE); MaterialChunkRefPtr PSMaterialChunk = MaterialChunk::create(); PSMaterialChunk->setAmbient(Color4f(0.3f,0.3f,0.3f,1.0f)); PSMaterialChunk->setDiffuse(Color4f(0.7f,0.7f,0.7f,1.0f)); PSMaterialChunk->setSpecular(Color4f(0.9f,0.9f,0.9f,1.0f)); PSMaterialChunk->setColorMaterial(GL_AMBIENT_AND_DIFFUSE); ChunkMaterialRefPtr PSSmokeMaterial = ChunkMaterial::create(); PSSmokeMaterial->addChunk(QuadTextureObjChunk); PSSmokeMaterial->addChunk(PSMaterialChunk); PSSmokeMaterial->addChunk(PSMaterialChunk); PSSmokeMaterial->addChunk(QuadTextureEnvChunk); //Particle System //Rocket RocketParticleSystem = OSG::ParticleSystem::create(); RocketParticleSystem->attachUpdateListener(TutorialWindow); TutorialRocketParticleSystemListener TheRocketListener; RocketParticleSystem->addParticleSystemListener(&TheRocketListener); //smoke SmokeParticleSystem = OSG::ParticleSystem::create(); SmokeParticleSystem->attachUpdateListener(TutorialWindow); //Shrapnel ShrapnelParticleSystem = OSG::ParticleSystem::create(); ShrapnelParticleSystem->attachUpdateListener(TutorialWindow); //Fireball FireballParticleSystem = OSG::ParticleSystem::create(); FireballParticleSystem->attachUpdateListener(TutorialWindow); //Particle System Drawer //Rocket does not have a drawer because it is being attached to a special node core //Smoke SmokeParticleSystemDrawer = OSG::QuadParticleSystemDrawer::create(); //SmokeParticleSystemDrawer->setQuadSizeScaling(Vec2f(0.5f,0.5f)); //Shrapnel ExampleShrapnelParticleSystemDrawer = OSG::PointParticleSystemDrawer::create(); ExampleShrapnelParticleSystemDrawer->setForcePerParticleSizing(true); //Fireball ExampleFireballParticleSystemDrawer = OSG::PointParticleSystemDrawer::create(); ExampleFireballParticleSystemDrawer->setForcePerParticleSizing(true); //Particle System Node //collision node //NodeRefPtr EnvironmentNode = makeSphere(2,4.0f); Matrix EnvironmentTransformation; EnvironmentTransformation.setScale(0.1f); TransformRefPtr EnvironmentTransformCore = Transform::create(); EnvironmentTransformCore->setMatrix(EnvironmentTransformation); NodeRefPtr EnvironmentNode = Node::create(); EnvironmentNode->setCore(EnvironmentTransformCore); //EnvironmentNode->addChild(SceneFileHandler::the()->read("Data/Chloroplast.osb")); EnvironmentNode->addChild(SceneFileHandler::the()->read("Data/house.obj")); //NodeRefPtr ParticlePrototypeNode = makeTorus(1.0,4.0,16,16); NodeRefPtr RocketParticlePrototypeNode = SceneFileHandler::the()->read("Data/rocket.obj"); if(RocketParticlePrototypeNode == NULL) { RocketParticlePrototypeNode = makeTorus(.5, 2, 16, 16); } NodeParticleSystemCoreRefPtr RocketParticleNodeCore = OSG::NodeParticleSystemCore::create(); RocketParticleNodeCore->setSystem(RocketParticleSystem); RocketParticleNodeCore->setPrototypeNode(RocketParticlePrototypeNode); RocketParticleNodeCore->setNormalSource(NodeParticleSystemCore::NORMAL_VELOCITY); RocketParticleNodeCore->setUpSource(NodeParticleSystemCore::UP_PARTICLE_NORMAL); RocketParticleNodeCore->setUp(Vec3f(0.0f,1.0f,0.0f)); //Geometry Collision Affector GeometryCollisionParticleSystemAffectorRefPtr ExampleGeometryCollisionParticleSystemAffector = GeometryCollisionParticleSystemAffector::create(); ExampleGeometryCollisionParticleSystemAffector->setCollisionNode(EnvironmentNode); TutorialParticleCollisionListener TheCollisionListener; ExampleGeometryCollisionParticleSystemAffector->addParticleGeometryCollisionListener(&TheCollisionListener); NodeRefPtr RocketParticleNode = OSG::Node::create(); RocketParticleNode->setCore(RocketParticleNodeCore); //Attach the Affector to the Rocket Particle System //RocketParticleSystem->pushToAffectors(); RocketParticleSystem->pushToSystemAffectors(ExampleGeometryCollisionParticleSystemAffector); //Smoke SmokeGenerator = OSG::RateParticleGenerator::create(); //Attach the function objects to the Generator SmokePositionDistribution = createSmokePositionDistribution(); SmokeGenerator->setPositionDistribution(SmokePositionDistribution); SmokeGenerator->setLifespanDistribution(createSmokeLifespanDistribution()); SmokeGenerator->setGenerationRate(50.0); SmokeGenerator->setVelocityDistribution(createSmokeVelocityDistribution()); //Attach the function objects the Affectors SmokeAgeFadeParticleAffector = OSG::AgeFadeParticleAffector::create(); SmokeAgeFadeParticleAffector->setFadeInTime(2.0f); SmokeAgeFadeParticleAffector->setFadeOutTime(5.0f); SmokeAgeFadeParticleAffector->setStartAlpha(0.0f); SmokeAgeFadeParticleAffector->setFadeToAlpha(0.2f); SmokeAgeFadeParticleAffector->setEndAlpha(0.0f); SmokeAgeSizeParticleAffector = OSG::AgeSizeParticleAffector::create(); //ages SmokeAgeSizeParticleAffector->editMFAges()->push_back(0.1); SmokeAgeSizeParticleAffector->editMFAges()->push_back(0.2); SmokeAgeSizeParticleAffector->editMFAges()->push_back(0.3); SmokeAgeSizeParticleAffector->editMFAges()->push_back(0.5); SmokeAgeSizeParticleAffector->editMFAges()->push_back(0.7); SmokeAgeSizeParticleAffector->editMFAges()->push_back(0.8); SmokeAgeSizeParticleAffector->editMFAges()->push_back(1.0); //sizes SmokeAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(0.5,0.5,0.5)); SmokeAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(1.0,1.0,1.0)); SmokeAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(2.0,2.0,2.0)); SmokeAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(3.0,3.0,3.0)); SmokeAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(4.0,4.0,4.0)); SmokeAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(5.0,5.0,5.0)); SmokeAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(6.5,6.5,6.5)); ParticleSystemCoreRefPtr SmokeParticleNodeCore = OSG::ParticleSystemCore::create(); SmokeParticleNodeCore->setSystem(SmokeParticleSystem); SmokeParticleNodeCore->setDrawer(SmokeParticleSystemDrawer); SmokeParticleNodeCore->setMaterial(PSSmokeMaterial); NodeRefPtr SmokeParticleNode = OSG::Node::create(); SmokeParticleNode->setCore(SmokeParticleNodeCore); //end///////////////////// //Shrapnel ShrapnelBurstGenerator = OSG::BurstParticleGenerator::create(); NodeRefPtr ShrapnelParticlePrototypeNode = SceneFileHandler::the()->read("Data/Shrapnel.obj"); NodeParticleSystemCoreRefPtr ShrapnelParticleNodeCore = OSG::NodeParticleSystemCore::create(); ShrapnelParticleNodeCore->setSystem(ShrapnelParticleSystem); ShrapnelParticleNodeCore->setPrototypeNode(ShrapnelParticlePrototypeNode); //Attach the function objects to the Generator ShrapnelPositionDistribution = createShrapnelPositionDistribution(); ShrapnelBurstGenerator->setPositionDistribution(ShrapnelPositionDistribution); ShrapnelBurstGenerator->setLifespanDistribution(createLifespanDistribution()); ShrapnelBurstGenerator->setBurstAmount(50.0); ShrapnelBurstGenerator->setVelocityDistribution(createShrapnelVelocityDistribution()); ShrapnelBurstGenerator->setAccelerationDistribution(createShrapnelAccelerationDistribution()); NodeRefPtr ShrapnelParticleNode = OSG::Node::create(); ShrapnelParticleNode->setCore(ShrapnelParticleNodeCore); //end///////////////////// //fireball FireballGenerator = OSG::BurstParticleGenerator::create(); NodeRefPtr FireballParticlePrototypeNode = SceneFileHandler::the()->read("Data/bubble.obj"); NodeParticleSystemCoreRefPtr FireballParticleNodeCore = OSG::NodeParticleSystemCore::create(); FireballParticleNodeCore->setSystem(FireballParticleSystem); FireballParticleNodeCore->setPrototypeNode(FireballParticlePrototypeNode); //Attach the function objects to the Generator FireballPositionDistribution = createFireballPositionDistribution(); FireballGenerator->setPositionDistribution(FireballPositionDistribution); FireballGenerator->setLifespanDistribution(createFireballLifespanDistribution()); FireballGenerator->setBurstAmount(100.0); FireballGenerator->setVelocityDistribution(createFireballVelocityDistribution()); FireballGenerator->setAccelerationDistribution(createFireballAccelerationDistribution()); //Attach the function objects the Affectors FireballAgeSizeParticleAffector = OSG::AgeSizeParticleAffector::create(); //ages FireballAgeSizeParticleAffector->editMFAges()->push_back(0.1); FireballAgeSizeParticleAffector->editMFAges()->push_back(0.2); FireballAgeSizeParticleAffector->editMFAges()->push_back(0.3); FireballAgeSizeParticleAffector->editMFAges()->push_back(0.5); FireballAgeSizeParticleAffector->editMFAges()->push_back(0.7); FireballAgeSizeParticleAffector->editMFAges()->push_back(0.8); FireballAgeSizeParticleAffector->editMFAges()->push_back(1.0); //sizes FireballAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(2.0,2.0,2.0)); FireballAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(2.3,2.3,2.3)); FireballAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(2.5,2.5,2.5)); FireballAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(3.0,3.0,3.0)); FireballAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(4.0,4.0,4.0)); FireballAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(5.0,5.0,5.0)); FireballAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(6.5,6.5,6.5)); NodeRefPtr FireballParticleNode = OSG::Node::create(); FireballParticleNode->setCore(FireballParticleNodeCore); //end///////////////////// // Make Main Scene Node NodeRefPtr scene = OSG::Node::create(); scene->setCore(OSG::Group::create()); scene->addChild(RocketParticleNode); scene->addChild(SmokeParticleNode); scene->addChild(ShrapnelParticleNode); scene->addChild(FireballParticleNode); scene->addChild(EnvironmentNode); mgr->setRoot(scene); mgr->getNavigator()->set(Pnt3f(0.0,0.0,0.0), Pnt3f(0.0,0.0,-1.0), Vec3f(0.0,1.0,0.0)); mgr->getNavigator()->setMotionFactor(1.0f); mgr->getCamera()->setNear(0.1f); mgr->getCamera()->setFar(1000.0f); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "10RocketLauncher"); //Enter main Loop TutorialWindow->mainLoop(); osgExit(); return 0; }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); // Set up Window TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); TutorialWindow->setDisplayCallback(display); TutorialWindow->setReshapeCallback(reshape); TutorialKeyListener TheKeyListener; TutorialWindow->addKeyListener(&TheKeyListener); // Make Torus Node (creates Torus in background of scene) NodeRefPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16); // Make Main Scene Node and add the Torus NodeRefPtr scene = OSG::Node::create(); scene->setCore(OSG::Group::create()); scene->addChild(TorusGeometryNode); // Create the Graphics GraphicsRefPtr TutorialGraphics = OSG::Graphics2D::create(); // Initialize the LookAndFeelManager to enable default settings LookAndFeelManager::the()->getLookAndFeel()->init(); /****************************************************** Create Components to add to MenuBar Menus. Each MenuBar has multiple Menus which contain multiple MenuItems. -setAcceleratorKey(KeyEvent::KEY_*): This links the key "*" as a shortcut to selecting the item it is attached to. An example of this would be Q with Control+Q causing programs to quit. -setAcceleratorModifiers(KeyEvent::KEY_MODIFIER_*): This adds the "*" key as another requirement to cause the item to be selected. Things such as "CONTROL" are likely to be used here (as mentioned above, both Control and Q are specified). Note: These shortcuts will be shown in the list with the MenuItem they are attached to. -setMnemonicKey(KeyEvent::KEY_****): sets the key "****" to be underlined within the Menu itself ******************************************************/ // Creates MenuItems as in 25PopupMenu MenuItemRefPtr NewMenuItem = MenuItem::create(); MenuItemRefPtr OpenMenuItem = MenuItem::create(); MenuItemRefPtr CloseMenuItem = MenuItem::create(); MenuItemRefPtr ExitMenuItem = MenuItem::create(); MenuItemRefPtr UndoMenuItem = MenuItem::create(); MenuItemRefPtr RedoMenuItem = MenuItem::create(); //Edits MenuItems NewMenuItem->setText("New ..."); NewMenuItem->setAcceleratorKey(KeyEvent::KEY_N); NewMenuItem->setAcceleratorModifiers(KeyEvent::KEY_MODIFIER_COMMAND); NewMenuItem->setMnemonicKey(KeyEvent::KEY_N); OpenMenuItem->setText("Open ..."); OpenMenuItem->setAcceleratorKey(KeyEvent::KEY_P); OpenMenuItem->setAcceleratorModifiers(KeyEvent::KEY_MODIFIER_COMMAND); OpenMenuItem->setMnemonicKey(KeyEvent::KEY_P); CloseMenuItem->setText("Close ..."); CloseMenuItem->setAcceleratorKey(KeyEvent::KEY_W); CloseMenuItem->setAcceleratorModifiers(KeyEvent::KEY_MODIFIER_COMMAND); CloseMenuItem->setMnemonicKey(KeyEvent::KEY_C); ExitMenuItem->setText("Quit"); ExitMenuItem->setAcceleratorKey(KeyEvent::KEY_Q); ExitMenuItem->setAcceleratorModifiers(KeyEvent::KEY_MODIFIER_COMMAND); ExitMenuItem->setMnemonicKey(KeyEvent::KEY_Q); UndoMenuItem->setText("Undo"); UndoMenuItem->setAcceleratorKey(KeyEvent::KEY_Z); UndoMenuItem->setAcceleratorModifiers(KeyEvent::KEY_MODIFIER_COMMAND); UndoMenuItem->setMnemonicKey(KeyEvent::KEY_U); RedoMenuItem->setText("Redo"); RedoMenuItem->setEnabled(false); RedoMenuItem->setMnemonicKey(KeyEvent::KEY_R); // Create an ActionListener and assign it to ExitMenuItem // This is defined above, and will cause the program to quit // when that MenuItem is selected or Control + Q hit QuitActionListener TheQuitActionListener; ExitMenuItem->addActionListener( &TheQuitActionListener); /****************************************************** Create Menu Components to add to MenuBar and adds above Components to them. Note: setAcceleratorKey, setAcceleratorModifiers, and setMnemnoicKey all apply to Menus in addition to MenuItems. ******************************************************/ // Create a File menu and adds its MenuItems MenuRefPtr FileMenu = Menu::create(); FileMenu->addItem(NewMenuItem); FileMenu->addItem(OpenMenuItem); FileMenu->addItem(CloseMenuItem); FileMenu->addSeparator(); FileMenu->addItem(ExitMenuItem); // Labels the File Menu FileMenu->setText("File"); FileMenu->setMnemonicKey(KeyEvent::KEY_F); // Creates an Edit menu and adds its MenuItems MenuRefPtr EditMenu = Menu::create(); EditMenu->addItem(UndoMenuItem); EditMenu->addItem(RedoMenuItem); // Labels the Edit Menu EditMenu->setText("Edit"); EditMenu->setMnemonicKey(KeyEvent::KEY_E); /****************************************************** Create MainMenuBar and adds the Menus created above to it. Also creates several Backgrounds to improve MenuBar overall look. Both the MenuBar and Menu can have Backgrounds; the set up currently is to have EmptyBackgrounds in each Menu allowing a single overall MenuBar Background which is given to the MenuBar itself. This can be easily changed by adding different Backgrounds to the File and Edit Menus. Note: The MenuBar is added to the MainFrame below. ******************************************************/ // Creates two Backgrounds MenuBarRefPtr MainMenuBar = MenuBar::create(); // Adds the two Menus to the MainMenuBar MainMenuBar->addMenu(FileMenu); MainMenuBar->addMenu(EditMenu); // Create two Labels LabelRefPtr ExampleLabel1 = OSG::Label::create(); LabelRefPtr ExampleLabel2 = OSG::Label::create(); ExampleLabel1->setText("Look up in the corner!"); ExampleLabel1->setPreferredSize(Vec2f(150, 25)); ExampleLabel2->setText("Hit Control + Z"); ExampleLabel2->setPreferredSize(Vec2f(150, 25)); // Create The Main InternalWindow // Create Background to be used with the Main InternalWindow EmptyLayerRefPtr MainInternalWindowBackground = OSG::EmptyLayer::create(); EmptyBorderRefPtr MainInternalWindowBorder = OSG::EmptyBorder::create(); LayoutRefPtr MainInternalWindowLayout = OSG::FlowLayout::create(); InternalWindowRefPtr MainInternalWindow = OSG::InternalWindow::create(); MainInternalWindow->pushToChildren(ExampleLabel1); MainInternalWindow->pushToChildren(ExampleLabel2); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setMenuBar(MainMenuBar); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setBorders(MainInternalWindowBorder); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(1.0f,1.0f)); MainInternalWindow->setDrawTitlebar(false); MainInternalWindow->setResizable(false); // Create the Drawing Surface UIDrawingSurfaceRefPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundRefPtr TutorialUIForeground = OSG::UIForeground::create(); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(TutorialWindow); mgr->setRoot(scene); // Add the UI Foreground Object to the Scene ViewportRefPtr TutorialViewport = mgr->getWindow()->getPort(0); TutorialViewport->addForeground(TutorialUIForeground); // Show the whole Scene mgr->showAll(); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "26MenuBar"); //Enter main Loop TutorialWindow->mainLoop(); osgExit(); return 0; }
// Initialize OpenSG and set up the scene int main(int argc, char **argv) { //Print key command info std::cout << "\n\nKEY COMMANDS:" << std::endl; std::cout << "space Play/Pause the animation" << std::endl; std::cout << "CTRL-Q Exit\n\n" << std::endl; // OSG init osgInit(argc,argv); // Set up Window TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); TutorialWindow->setDisplayCallback(display); TutorialWindow->setReshapeCallback(reshape); //Add Window Listener TutorialKeyListener TheKeyListener; TutorialWindow->addKeyListener(&TheKeyListener); TutorialMouseListener TheTutorialMouseListener; TutorialMouseMotionListener TheTutorialMouseMotionListener; TutorialWindow->addMouseListener(&TheTutorialMouseListener); TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(TutorialWindow); //Torus Geometry TorusGeometry = makeTorusGeo(.5, 2, 16, 16); NodeUnrecPtr TorusGeometryNode = Node::create(); TorusGeometryNode->setCore(TorusGeometry); //Make Torus Node NodeUnrecPtr TorusNode = Node::create(); TransformUnrecPtr TorusNodeTrans; TorusNodeTrans = Transform::create(); setName(TorusNodeTrans, std::string("TorusNodeTransformationCore")); TorusNode->setCore(TorusNodeTrans); TorusNode->addChild(TorusGeometryNode); //Make Main Scene Node NodeUnrecPtr scene = Node::create(); //ComponentTransformUnrecPtr Trans; //Trans = ComponentTransform::create(); //setName(Trans, std::string("MainTransformationCore")); scene->setCore(Group::create()); // add the torus as a child scene->addChild(TorusNode); setupAnimation(); mgr->setRoot (scene); // show the whole scene mgr->showAll(); Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "15LoadXMLAnimation"); //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)); // Make Torus Node (creates Torus in background of scene) NodeRecPtr TorusGeometryNode = makeTorus(.5, 2, 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(); ColorChooserRecPtr TheColorChooser = ColorChooser::create(); TheColorChooser->setColor(Color4f(1.0f,0.0f,0.0f,1.0f)); // Create Background to be used with the MainInternalWindow ColorLayerRecPtr MainInternalWindowBackground = ColorLayer::create(); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); // Create The Internal Window InternalWindowRecPtr MainInternalWindow = InternalWindow::create(); LayoutRecPtr MainInternalWindowLayout = FlowLayout::create(); // Assign the Button to the MainInternalWindow so it will be displayed // when the view is rendered. MainInternalWindow->pushToChildren(TheColorChooser); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setPosition(Pnt2f(50,50)); MainInternalWindow->setPreferredSize(Vec2f(400,400)); MainInternalWindow->setTitle(std::string("Internal Window")); // Create the Drawing Surface UIDrawingSurfaceRecPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundRecPtr TutorialUIForeground = UIForeground::create(); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); sceneManager.setRoot(scene); // Add the UI Foreground Object to the Scene ViewportRecPtr TutorialViewport = sceneManager.getWindow()->getPort(0); TutorialViewport->addForeground(TutorialUIForeground); //Create the Documentation Foreground and add it to the viewport SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow); // Show the whole Scene sceneManager.showAll(); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "39ColorChooser"); //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)); // Tell the Manager what to manage sceneManager->setWindow(TutorialWindow); TutorialWindow->connectKeyTyped(boost::bind(keyPressed, _1)); // Make Torus Node (creates Torus in background of scene) NodeRecPtr TorusGeometryNode = makeTorus(.5, 2, 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(); /****************************************************** Create PopupMenu Components -MenuItem: These are items that are contained within a Menu; they are the things you click on to cause something to occur -SeperatorMenuItem: These place a seperator line between items in a Menu -Menu: These are sub-menus within another Menu; MenuItems and SeperatorMenuItems are added to a Menu ******************************************************/ MenuItemRecPtr MenuItem1 = MenuItem::create(); MenuItemRecPtr MenuItem2 = MenuItem::create(); MenuItemRecPtr MenuItem3 = MenuItem::create(); MenuItemRecPtr MenuItem4 = MenuItem::create(); MenuItemRecPtr SubMenuItem1 = MenuItem::create(); MenuItemRecPtr SubMenuItem2 = MenuItem::create(); MenuItemRecPtr SubMenuItem3 = MenuItem::create(); MenuRecPtr ExampleSubMenu = Menu::create(); /****************************************************** Edit the MenuItems -setText("TEXT"): Sets the text on the item to be TEXT -setEnabled(Boolean): sets the menu item to be either enabled or disabled ******************************************************/ MenuItem1->setText("Menu Item 1"); MenuItem2->setText("Menu Item 2"); MenuItem3->setText("Menu Item 3"); MenuItem4->setText("Menu Item 4"); MenuItem4->setEnabled(false); SubMenuItem1->setText("SubMenu Item 1"); SubMenuItem2->setText("SubMenu Item 2"); SubMenuItem3->setText("SubMenu Item 3"); ExampleSubMenu->setText("Sub Menu"); // This adds three MenuItems to the Menu, // creating a submenu. Note this does not // involve begin/endEditCPs to do ExampleSubMenu->addItem(SubMenuItem1); ExampleSubMenu->addItem(SubMenuItem2); ExampleSubMenu->addItem(SubMenuItem3); /****************************************************** Create the PopupMenu itself. Items are added in the order in which they will be displayed (top to bottom) via addItem(ItemToBeAdded) The PopupMenu is attached to a Button below using setPopupMenu(PopupMenuName). Note: PopupMenus can be added to any Component. ******************************************************/ PopupMenuRecPtr ExamplePopupMenu = PopupMenu::create(); ExamplePopupMenu->setMinSize(Vec2f(100.0f, 20.0f)); ExamplePopupMenu->setMaxSize(Vec2f(100.0f, 80.0f)); ExamplePopupMenu->addItem(MenuItem1); ExamplePopupMenu->addItem(MenuItem2); ExamplePopupMenu->addItem(MenuItem3); ExamplePopupMenu->addSeparator(); ExamplePopupMenu->addItem(ExampleSubMenu); ExamplePopupMenu->addItem(MenuItem4); // Create a Button and Font UIFontRecPtr PopupMenuButtonFont = UIFont::create(); PopupMenuButtonFont->setSize(16); ButtonRecPtr PopupMenuButton = Button::create(); PopupMenuButton->setText("RightClickMe!"); // Add the PopupMenu to PopupMenuButton so that when right clicked, // the PopupMenu will appear PopupMenuButton->setPopupMenu(ExamplePopupMenu); PopupMenuButton->setPreferredSize(Vec2f(200,100)); PopupMenuButton->setFont(PopupMenuButtonFont); // Create The Main InternalWindow // Create Background to be used with the Main InternalWindow ColorLayerRecPtr MainInternalWindowBackground = ColorLayer::create(); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); LayoutRecPtr MainInternalWindowLayout = FlowLayout::create(); InternalWindowRecPtr MainInternalWindow = InternalWindow::create(); MainInternalWindow->pushToChildren(PopupMenuButton); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setDrawTitlebar(false); MainInternalWindow->setResizable(false); // Create the Drawing Surface UIDrawingSurfaceRecPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundRecPtr TutorialUIForeground = UIForeground::create(); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); // Tell the Manager what to manage sceneManager->setRoot(scene); // Add the UI Foreground Object to the Scene ViewportRecPtr TutorialViewport = sceneManager->getWindow()->getPort(0); TutorialViewport->addForeground(TutorialUIForeground); //Create the Documentation Foreground and add it to the viewport SimpleScreenDoc TheSimpleScreenDoc(sceneManager, TutorialWindow); // Show the whole Scene sceneManager->showAll(); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "01RubberBandCamera"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
int main(int argc, char **argv) { OSG::preloadSharedObject("OSGImageFileIO"); // OSG init osgInit(argc,argv); // Set up Window TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); TutorialWindow->setDisplayCallback(display); TutorialWindow->setReshapeCallback(reshape); TutorialKeyListener TheKeyListener; TutorialWindow->addKeyListener(&TheKeyListener); TutorialMouseListener TheTutorialMouseListener; TutorialMouseMotionListener TheTutorialMouseMotionListener; TutorialWindow->addMouseListener(&TheTutorialMouseListener); TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(TutorialWindow); // 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 ExampleParticleSystem = OSG::ParticleSystem::create(); ExampleParticleSystem->attachUpdateListener(TutorialWindow); //Age Particle Function. Controls which image is shown when, based on the age of a particle. AgeFunc = OSG::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 - ExampleParticleSystemDrawer = OSG::QuadSequenceParticleSystemDrawer::create(); // image dimensions (in pixels) are required if there is a border on the images. ExampleParticleSystemDrawer->setImageDimensions(OSG::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(OSG::Vec2b(3,2)); // width of the border on each side of the image, in pixels. ExampleParticleSystemDrawer->setBorderOffsets(OSG::Vec2b(0,0)); // this is the age function we just created above. ExampleParticleSystemDrawer->setSequenceFunction(AgeFunc); ExampleParticleGenerator = OSG::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(2.0f); //Particle System Node ParticleSystemCoreRefPtr ParticleNodeCore = OSG::ParticleSystemCore::create(); ParticleNodeCore->setSystem(ExampleParticleSystem); ParticleNodeCore->setDrawer(ExampleParticleSystemDrawer); ParticleNodeCore->setMaterial(PSMaterial); ParticleNodeCore->setSortingMode(ParticleSystemCore::BACK_TO_FRONT); NodeRefPtr ParticleNode = OSG::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 = OSG::Node::create(); scene->setCore(OSG::Group::create()); scene->addChild(ParticleNode); mgr->setRoot(scene); // Show the whole Scene mgr->showAll(); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "05a - QuadSequenceParticleDrawer"); //Enter main Loop TutorialWindow->mainLoop(); osgExit(); return 0; }