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 RotatedComponent. -setAngle(Angle, in radians): Determine the angle the Component initially is rotated. -setInternalComponent(Component): Determine what Component will be rotated. -setResizePolicy(RotatedComponent::ENUM): Takes NO_RESIZING, RESIZE_TO_MIN, or RESIZE_TO_MAX arguments. ******************************************************/ RotatedComponentRecPtr TheRotatedComponent = RotatedComponent::create(); // Define PI Real32 PI(3.14159); TheRotatedComponent->setAngle(PI/4); ComponentRecPtr InnerPanel = createPanel(); TheRotatedComponent->setInternalComponent(InnerPanel); TheRotatedComponent->setResizePolicy(RotatedComponent::RESIZE_TO_MIN); /****************************************************** Create a ToggleButton which can be used to start and stop the Button from rotating. Note: due to the way FlowLayout works you will notice that this ToggleButton will move as well. In cases where a Rotating Component is used, an alternate Layout may be preferred to prevent other Components from moving as well. This is intentionally left this way to illustrate why this might be the case. A SplitPanel with fixed divider for example would prevent the ToggleButton from moving, while still allowing the Panel to move freely. ******************************************************/ ToggleButtonRecPtr RotateControlButton = ToggleButton::create(); RotateControlButton->setText("Start Rotating"); RotateControlButton->setPreferredSize(Vec2f(100.0f, 29.0f)); RotateControlButton->connectButtonSelected(boost::bind(handleButtonSelected, _1, TutorialWindow.get(), TheRotatedComponent.get())); RotateControlButton->connectButtonDeselected(boost::bind(handleButtonDeselected, _1, TutorialWindow.get(), TheRotatedComponent.get())); // 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(TheRotatedComponent); MainInternalWindow->pushToChildren(RotateControlButton); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.8f,0.8f)); 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, "30RotatedComponent"); //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 Components to add to MenuBar Menus. Each MenuBar has multiple Menus which contain multiple MenuItems. -setAcceleratorKey(KeyEventDetails::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(KeyEventDetails::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(KeyEventDetails::KEY_****): sets the key "****" to be underlined within the Menu itself ******************************************************/ // Creates MenuItems as in 25PopupMenu MenuItemRecPtr NewMenuItem = MenuItem::create(); MenuItemRecPtr OpenMenuItem = MenuItem::create(); MenuItemRecPtr CloseMenuItem = MenuItem::create(); MenuItemRecPtr ExitMenuItem = MenuItem::create(); MenuItemRecPtr UndoMenuItem = MenuItem::create(); MenuItemRecPtr RedoMenuItem = MenuItem::create(); //Edits MenuItems NewMenuItem->setText("New ..."); NewMenuItem->setAcceleratorKey(KeyEventDetails::KEY_N); NewMenuItem->setAcceleratorModifiers(KeyEventDetails::KEY_MODIFIER_COMMAND); NewMenuItem->setMnemonicKey(KeyEventDetails::KEY_N); OpenMenuItem->setText("Open ..."); OpenMenuItem->setAcceleratorKey(KeyEventDetails::KEY_P); OpenMenuItem->setAcceleratorModifiers(KeyEventDetails::KEY_MODIFIER_COMMAND); OpenMenuItem->setMnemonicKey(KeyEventDetails::KEY_P); CloseMenuItem->setText("Close ..."); CloseMenuItem->setAcceleratorKey(KeyEventDetails::KEY_W); CloseMenuItem->setAcceleratorModifiers(KeyEventDetails::KEY_MODIFIER_COMMAND); CloseMenuItem->setMnemonicKey(KeyEventDetails::KEY_C); ExitMenuItem->setText("Quit"); ExitMenuItem->setAcceleratorKey(KeyEventDetails::KEY_Q); ExitMenuItem->setAcceleratorModifiers(KeyEventDetails::KEY_MODIFIER_COMMAND); ExitMenuItem->setMnemonicKey(KeyEventDetails::KEY_Q); UndoMenuItem->setText("Undo"); UndoMenuItem->setAcceleratorKey(KeyEventDetails::KEY_Z); UndoMenuItem->setAcceleratorModifiers(KeyEventDetails::KEY_MODIFIER_COMMAND); UndoMenuItem->setMnemonicKey(KeyEventDetails::KEY_U); RedoMenuItem->setText("Redo"); RedoMenuItem->setEnabled(false); RedoMenuItem->setMnemonicKey(KeyEventDetails::KEY_R); // Create a function connection to ExitMenuItem // This is defined above, and will cause the program to quit // when that MenuItem is selected or Control + Q hit ExitMenuItem->connectActionPerformed(boost::bind(handleQuitAction, _1, TutorialWindow.get())); /****************************************************** 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 MenuRecPtr 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(KeyEventDetails::KEY_F); // Creates an Edit menu and adds its MenuItems MenuRecPtr EditMenu = Menu::create(); EditMenu->addItem(UndoMenuItem); EditMenu->addItem(RedoMenuItem); // Labels the Edit Menu EditMenu->setText("Edit"); EditMenu->setMnemonicKey(KeyEventDetails::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 MenuBarRecPtr MainMenuBar = MenuBar::create(); // Adds the two Menus to the MainMenuBar MainMenuBar->addMenu(FileMenu); MainMenuBar->addMenu(EditMenu); // Create two Labels LabelRecPtr ExampleLabel1 = Label::create(); LabelRecPtr ExampleLabel2 = 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 EmptyLayerRecPtr MainInternalWindowBackground = EmptyLayer::create(); EmptyBorderRecPtr MainInternalWindowBorder = EmptyBorder::create(); LayoutRecPtr MainInternalWindowLayout = FlowLayout::create(); InternalWindowRecPtr MainInternalWindow = 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 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, "26MenuBar"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
// Initialize GLUT & OpenSG and set up the scene int main(int argc, char **argv) { // OSG init osgInit(argc,argv); { // Set up Window WindowEventProducerRecPtr TutorialWindow = createNativeWindow(); //Initialize Window TutorialWindow->initWindow(); SimpleSceneManager sceneManager; TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager)); TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager)); // Tell the Manager what to manage sceneManager.setWindow(TutorialWindow); //Attach to events TutorialWindow->connectMousePressed(boost::bind(mousePressed, _1, &sceneManager)); TutorialWindow->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager)); TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager)); TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager)); BoostPath FilePath("../Animation/Data/Nanobot.dae"); if(argc >= 2) { FilePath = BoostPath(argv[1]); if(!boost::filesystem::exists(FilePath)) { std::cerr << "Could not load file: "<< FilePath.string() << ", because no such files exists."<< std::endl; FilePath = BoostPath("../Animation/Data/Nanobot.dae"); } } NodeRefPtr LoadedRoot; std::vector<AnimationRecPtr> LoadedAnimations; FCFileType::FCPtrStore ObjStore; try { ObjStore = FCFileHandler::the()->read(FilePath); } catch(std::exception &ex) { std::cerr << "Failed to load file: " << FilePath.string() << ", error:" << ex.what() << std::endl; return -1; } for(FCFileType::FCPtrStore::iterator StorItor(ObjStore.begin()); StorItor != ObjStore.end(); ++StorItor) { //Animations if((*StorItor)->getType().isDerivedFrom(Animation::getClassType())) { LoadedAnimations.push_back(dynamic_pointer_cast<Animation>(*StorItor)); LoadedAnimations.back()->attachUpdateProducer(TutorialWindow); LoadedAnimations.back()->start(); } //Root Node if((*StorItor)->getType() == Node::getClassType() && dynamic_pointer_cast<Node>(*StorItor)->getParent() == NULL) { LoadedRoot = dynamic_pointer_cast<Node>(*StorItor); } } if(LoadedRoot == NULL) { LoadedRoot = SceneFileHandler::the()->read(FilePath.string().c_str()); } if(LoadedRoot == NULL) { LoadedRoot= makeTorus(.5, 2, 32, 32); } //Make the fog node PostShaderStageRecPtr PostShaderStageCore = PostShaderStage::create(); PostShaderStageCore->clearPasses(); PostShaderStageCore->addPass("", generateNoEffectProg()); DirectionalLightRecPtr SceneLightCore = DirectionalLight::create(); SceneLightCore->setAmbient(Color4f(0.2f, 0.2f, 0.2f, 1.0f)); SceneLightCore->setDiffuse(Color4f(0.8f, 0.8f, 0.8f, 1.0f)); SceneLightCore->setSpecular(Color4f(1.0f, 1.0f, 1.0f, 1.0f)); NodeRefPtr SceneLight = makeNodeFor(SceneLightCore); SceneLight->addChild(LoadedRoot); NodeRefPtr PostShaderStageNode = makeNodeFor(PostShaderStageCore); PostShaderStageNode->addChild(SceneLight); //Make Main Scene Node NodeRefPtr scene = makeCoredNode<Group>(); scene->addChild(PostShaderStageNode); // tell the manager what to manage sceneManager.setRoot (scene); SceneLightCore->setBeacon(sceneManager.getCamera()->getBeacon()); //Create the Documentation Foreground and add it to the viewport SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow); // show the whole scene sceneManager.showAll(); sceneManager.getWindow()->getPort(0)->setTravMask(1); RenderOptionsRecPtr ViewportRenderOptions = RenderOptions::create(); ViewportRenderOptions->setRenderProperties(0x0); ViewportRenderOptions->setRenderProperties(RenderPropertiesPool::the()->getFrom1("Default")); ViewportRenderOptions->setRenderProperties(0x01); sceneManager.getWindow()->getPort(0)->setRenderOptions(ViewportRenderOptions); Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "Collada Loader"); TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1, TutorialWindow.get(), PostShaderStageCore.get())); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
// Initialize GLUT & OpenSG and set up the scene int main(int argc, char **argv) { // OSG init osgInit(argc,argv); { // Set up Window WindowEventProducerRecPtr TutorialWindow = createNativeWindow(); //Initialize Window TutorialWindow->initWindow(); SimpleSceneManager sceneManager; TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager)); TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager)); // Tell the Manager what to manage sceneManager.setWindow(TutorialWindow); //Attach to events TutorialWindow->connectMousePressed(boost::bind(mousePressed, _1, &sceneManager)); TutorialWindow->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager)); TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager)); TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager)); //Torus Material SimpleMaterialUnrecPtr TheTorusMaterial = SimpleMaterial::create(); TheTorusMaterial->setAmbient(Color3f(0.3,0.3,0.3)); TheTorusMaterial->setDiffuse(Color3f(0.7,0.7,0.7)); TheTorusMaterial->setSpecular(Color3f(1.0,1.0,1.0)); TheTorusMaterial->setShininess(20.0); //Torus Geometry GeometryUnrecPtr TorusGeometry = makeTorusGeo(.5, 2, 32, 32); TorusGeometry->setMaterial(TheTorusMaterial); NodeUnrecPtr TorusGeometryNode = Node::create(); TorusGeometryNode->setCore(TorusGeometry); //Make Torus Node NodeUnrecPtr TorusNode = Node::create(); TransformUnrecPtr TorusNodeTrans = Transform::create(); setName(TorusNodeTrans, std::string("TorusNodeTransformationCore")); TorusNode->setCore(TorusNodeTrans); TorusNode->addChild(TorusGeometryNode); //Make Main Scene Node NodeUnrecPtr scene = Node::create(); ComponentTransformUnrecPtr Trans = ComponentTransform::create(); setName(Trans, std::string("MainTransformationCore")); scene->setCore(Trans); // add the torus as a child scene->addChild(TorusNode); AnimationGroupUnrecPtr TheAnimation = setupAnimation(TheTorusMaterial, TorusNodeTrans); TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1, TheAnimation.get(), TutorialWindow.get())); TheAnimation->attachUpdateProducer(TutorialWindow); TheAnimation->start(); // tell the manager what to manage sceneManager.setRoot (scene); //Create the Documentation SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow); // show the whole scene sceneManager.showAll(); Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "07AnimationGroup"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
// Initialize GLUT & OpenSG and set up the scene int main(int argc, char **argv) { OSG::preloadSharedObject("OSGFileIO"); OSG::preloadSharedObject("OSGImageFileIO"); // OSG init osgInit(argc,argv); { // Set up Window WindowEventProducerRecPtr TutorialWindow = createNativeWindow(); //Initialize Window TutorialWindow->initWindow(); SimpleSceneManager sceneManager; TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager)); TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager)); // Tell the Manager what to manage sceneManager.setWindow(TutorialWindow); //Attach to events TutorialWindow->connectMousePressed(boost::bind(mousePressed, _1, &sceneManager)); TutorialWindow->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager)); TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager)); TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager)); TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1, TutorialWindow.get())); //Box Geometry GeometryUnrecPtr BoxGeometry = makeBoxGeo(1.0,1.0,1.0,1,1,1); ChunkMaterialUnrecPtr TheBoxMaterial = ChunkMaterial::create(); BoxGeometry->setMaterial(TheBoxMaterial); NodeUnrecPtr BoxGeometryNode = Node::create(); BoxGeometryNode->setCore(BoxGeometry); //Make Box Node NodeUnrecPtr BoxNode = Node::create(); TransformUnrecPtr BoxNodeTrans; BoxNodeTrans = Transform::create(); BoxNode->setCore(BoxNodeTrans); BoxNode->addChild(BoxGeometryNode); //Make Main Scene Node NodeUnrecPtr scene = Node::create(); ComponentTransformUnrecPtr Trans; Trans = ComponentTransform::create(); scene->setCore(Trans); // add the torus as a child scene->addChild(BoxNode); //Setup the Animation AnimationUnrecPtr TheAnimation = setupAnimation(TheBoxMaterial); TheAnimation->attachUpdateProducer(TutorialWindow); TheAnimation->start(); // tell the manager what to manage sceneManager.setRoot (scene); //Create the Documentation SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow); // show the whole scene sceneManager.showAll(); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "09TextureSelectAnimation"); //Main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
// Initialize GLUT & OpenSG and set up the scene int main(int argc, char **argv) { // OSG init osgInit(argc,argv); { // Set up Window WindowEventProducerRecPtr TutorialWindow = createNativeWindow(); //Initialize Window TutorialWindow->initWindow(); SimpleSceneManager sceneManager; TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager)); TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager)); // Tell the Manager what to manage sceneManager.setWindow(TutorialWindow); //Attach to events TutorialWindow->connectMousePressed(boost::bind(mousePressed, _1, &sceneManager)); TutorialWindow->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager)); TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager)); TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager)); TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1, TutorialWindow.get())); //Torus Node NodeUnrecPtr TorusGeometryNode = makeTorus(.5, 2, 32, 32); //Make Torus Node NodeUnrecPtr TorusNode = Node::create(); TransformUnrecPtr TorusNodeTrans; TorusNodeTrans = Transform::create(); TorusNode->setCore(TorusNodeTrans); TorusNode->addChild(TorusGeometryNode); //Make Main Scene Node NodeUnrecPtr scene = Node::create(); ComponentTransformUnrecPtr Trans; Trans = ComponentTransform::create(); scene->setCore(Trans); // add the torus as a child scene->addChild(TorusNode); //Make a gradient Background GradientBackgroundUnrecPtr TutorialBackground = GradientBackground::create(); TutorialBackground->addLine(Color3f(1.0,0.0,0.0),0.0); TutorialBackground->addLine(Color3f(0.0,1.0,0.0),0.5); TutorialBackground->addLine(Color3f(0.0,0.0,1.0),1.0); setName(TutorialBackground, std::string("TutorialGradientBackground")); AnimationUnrecPtr TheAnimation = setupAnimation(TutorialBackground); TheAnimation->attachUpdateProducer(TutorialWindow); TheAnimation->start(); // tell the manager what to manage sceneManager.setRoot (scene); sceneManager.getWindow()->getPort(0)->setBackground(TutorialBackground); //Create the Documentation SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow); // show the whole scene sceneManager.showAll(); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "03MFieldAnimation"); //Main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); { // Set up Window WindowEventProducerRecPtr TutorialWindow = createNativeWindow(); //Initialize Window TutorialWindow->initWindow(); SimpleSceneManager sceneManager; TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager)); TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager)); // Tell the Manager what to manage sceneManager.setWindow(TutorialWindow); //Attach to events TutorialWindow->connectMousePressed(boost::bind(mousePressed, _1, &sceneManager)); TutorialWindow->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager)); TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager)); TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager)); TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1, TutorialWindow.get())); //Shader Chunk SimpleSHLChunkUnrecPtr TheSHLChunk = SimpleSHLChunk::create(); TheSHLChunk->setVertexProgram(createSHLVertexProg()); TheSHLChunk->setFragmentProgram(createSHLFragProg()); //TheSHLChunk->addUniformVariable("Color1",Vec4f(0.0f,1.0f,0.0f,1.0f)); //TheSHLChunk->addUniformVariable("Color2",Vec4f(1.0f,1.0f,1.0f,1.0f)); //Shader Parameter Chunk SimpleSHLVariableChunkUnrecPtr SHLParameters = SimpleSHLVariableChunk::create(); //Color Parameter SHLParameters->addUniformVariable("Color1",Vec4f(0.0f,1.0f,0.0f,1.0f)); SHLParameters->addUniformVariable("Color2",Vec4f(1.0f,1.0f,1.0f,1.0f)); ChunkMaterialUnrecPtr ShaderMaterial = ChunkMaterial::create(); ShaderMaterial->addChunk(TheSHLChunk); ShaderMaterial->addChunk(SHLParameters); //Torus Node GeometryUnrecPtr TorusGeometry = makeTorusGeo(5.0f,20.0f, 32,32); TorusGeometry->setMaterial(ShaderMaterial); NodeUnrecPtr TorusNode = Node::create(); TorusNode->setCore(TorusGeometry); // Make Main Scene Node NodeUnrecPtr scene = Node::create(); scene->setCore(Group::create()); scene->addChild(TorusNode); sceneManager.setRoot(scene); // Show the whole Scene sceneManager.showAll(); //Create the Animations ShaderVariableVec4fUnrecPtr Color1Parameter; ShaderVariableVec4fUnrecPtr Color2Parameter; Color1Parameter = dynamic_cast<ShaderVariableVec4f*>(const_cast<ShaderVariable*>(SHLParameters->getVariables()->getVariable("Color1"))); Color2Parameter = dynamic_cast<ShaderVariableVec4f*>(const_cast<ShaderVariable*>(SHLParameters->getVariables()->getVariable("Color2"))); commitChanges(); AnimationUnrecPtr TheAnimation = setupAnimation(Color1Parameter, "value"); TheAnimation->attachUpdateProducer(TutorialWindow); TheAnimation->start(); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "04ShaderAnimation"); //Main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); { // Set up Window WindowEventProducerRecPtr TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); // Create the SimpleSceneManager helper SimpleSceneManager sceneManager; TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager)); TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager)); // Tell the Manager what to manage sceneManager.setWindow(TutorialWindow); // 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 = Node::create(); scene->setCore(Group::create()); scene->addChild(TorusGeometryNode); // Create the Graphics GraphicsRefPtr TutorialGraphics = Graphics2D::create(); // Initialize the LookAndFeelManager to enable default settings LookAndFeelManager::the()->getLookAndFeel()->init(); TextEditorRefPtr theTextEditor = TextEditor::create(); theTextEditor->setPreferredSize(Vec2f(1000,700)); theTextEditor->setIsSplit(false); theTextEditor->setClipboardVisible(false); //Toggle Button for clipboard ToggleButtonRefPtr ClipboardButton = ToggleButton::create(); ClipboardButton->setPreferredSize(Vec2f(80, 40)); ClipboardButton->setText("Clipboard"); ClipboardButton->connectButtonSelected(boost::bind(handleClipboardSelected, _1, theTextEditor.get())); ClipboardButton->connectButtonDeselected(boost::bind(handleClipboardDeselected, _1, theTextEditor.get())); //Toggle Button for split panel ToggleButtonRefPtr SplitButton = ToggleButton::create(); SplitButton->setPreferredSize(Vec2f(80, 40)); SplitButton->setText("Split"); SplitButton->connectButtonSelected(boost::bind(handleSplitSelected, _1, theTextEditor.get())); SplitButton->connectButtonDeselected(boost::bind(handleSplitDeselected, _1, theTextEditor.get())); ButtonRefPtr LoadButton = Button::create(); LoadButton->setMinSize(Vec2f(50, 25)); LoadButton->setMaxSize(Vec2f(200, 100)); LoadButton->setPreferredSize(Vec2f(80, 40)); LoadButton->setToolTipText("Click to open a file browser window"); LoadButton->setText("Load File"); LoadButton->connectActionPerformed(boost::bind(handleLoadButtonAction, _1, TutorialWindow.get(), theTextEditor.get())); ButtonRefPtr SaveButton = Button::create(); SaveButton->setMinSize(Vec2f(50, 25)); SaveButton->setMaxSize(Vec2f(200, 100)); SaveButton->setPreferredSize(Vec2f(80, 40)); SaveButton->setToolTipText("Click to save the currently opened file"); SaveButton->setText("Save File"); SaveButton->connectActionPerformed(boost::bind(handleSaveButtonAction, _1, TutorialWindow.get(),theTextEditor.get())); //Button Panel LayoutRefPtr ButtonPanelLayout = FlowLayout::create(); PanelRecPtr ButtonPanel = Panel::createEmpty(); ButtonPanel->setPreferredSize(Vec2f(300, 300)); ButtonPanel->setLayout(ButtonPanelLayout); ButtonPanel->pushToChildren(LoadButton); ButtonPanel->pushToChildren(SaveButton); ButtonPanel->pushToChildren(SplitButton); ButtonPanel->pushToChildren(ClipboardButton); // Create The Main InternalWindow // Create Background to be used with the Main InternalWindow ColorLayerRefPtr MainInternalWindowBackground = ColorLayer::create(); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); LayoutRefPtr MainInternalWindowLayout = FlowLayout::create(); InternalWindowRefPtr MainInternalWindow = InternalWindow::create(); //MainInternalWindow->pushToChildren(TextAreaScrollPanel); MainInternalWindow->pushToChildren(theTextEditor); MainInternalWindow->pushToChildren(ButtonPanel); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.95f,0.95f)); //MainInternalWindow->setDrawTitlebar(true); //MainInternalWindow->setResizable(true); // Create the Drawing Surface UIDrawingSurfaceRefPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundRefPtr TutorialUIForeground = UIForeground::create(); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); sceneManager.setRoot(scene); // Add the UI Foreground Object to the Scene ViewportRefPtr TutorialViewport = sceneManager.getWindow()->getPort(0); TutorialViewport->addForeground(TutorialUIForeground); // Show the whole Scene sceneManager.showAll(); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.95f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "06Editor"); TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1, theTextEditor.get())); commitChanges(); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
// Initialize GLUT & OpenSG and set up the rootNode int main(int argc, char **argv) { // OSG init osgInit(argc,argv); { // Set up Window WindowEventProducerRecPtr TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); SimpleSceneManager sceneManager; TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager)); TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager)); //Attach to events TutorialWindow->connectMousePressed(boost::bind(mousePressed, _1, &sceneManager)); TutorialWindow->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager)); TutorialWindow->connectMouseMoved(boost::bind(mouseMoved, _1, &sceneManager)); TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager)); // Tell the Manager what to manage sceneManager.setWindow(TutorialWindow); UInt32 SceneMask(1), NanobotMask(2), PathMask(4); BoostPath SceneFilePath(".//Data//CellParts.osb"); if(argc >= 2) { SceneFilePath = BoostPath(argv[1]); if(!boost::filesystem::exists(SceneFilePath)) { SceneFilePath = BoostPath(".//Data//CellParts.osb"); } } //Make Base Geometry Node NodeRecPtr SceneGeometryNode = SceneFileHandler::the()->read(SceneFilePath.string().c_str()); SceneGeometryNode->setTravMask(SceneMask); if(SceneGeometryNode == NULL) { SceneGeometryNode = makeTorus(1.0, 10.0, 24, 24); } //Construct the Root Node NodeRecPtr RootNode = makeCoredNode<Group>(); RootNode->addChild(SceneGeometryNode); commitChanges(); //Create the Octree SLOG << "Started Building Octree" << std::endl; SLOG << "This may take some time ..." << std::endl; Time StartTime; StartTime = getSystemTime(); OctreePtr TheOctree = Octree::buildTree(RootNode,SceneMask,6,0.5,true); SLOG << "Building Octree: " << getSystemTime() - StartTime << " s" << std::endl; Pnt3f Min,Max; TheOctree->getRoot()->getVolume(); SLOG << "Octree: "<< std::endl << " Depth: " << TheOctree->getDepth() << std::endl << " Bounds: " << TheOctree->getRoot()->getVolume().getMin() << " : " << TheOctree->getRoot()->getVolume().getMax() << std::endl << " NodeCount: " << TheOctree->getNodeCount() << std::endl << " LeafNodeCount: " << TheOctree->getLeafNodeCount() << std::endl << " BranchNodeCount: " << TheOctree->getBranchNodeCount() << std::endl << " IntersectingNodeCount: " << TheOctree->getIntersectingNodeCount() << std::endl << " IntersectingLeafNodeCount: " << TheOctree->getIntersectingLeafNodeCount() << std::endl; //Make the Nanobot Nodes BoostPath NanobotFilePath(".//Data//Nanobot.osb"); NodeRecPtr NanobotGeoNode = SceneFileHandler::the()->read(NanobotFilePath.string().c_str()); NanobotVector Nanobots; UInt32 NumNanobots(3); for(UInt32 i(0) ; i<NumNanobots ; ++i) { NanobotDetails TheDetails; //Get the Transform node for the Nanobot TheDetails._Transform = Transform::create(); Matrix NanobotMatrix; Pnt3f Min,Max; SceneGeometryNode->getVolume().getBounds(Min,Max); Min = Min + ShrinkFactor; Max = Max - ShrinkFactor; NanobotMatrix.setTranslate(randomOpenPosition(Min,Max,TheOctree).subZero()); NanobotMatrix.setScale(0.06f); TheDetails._Transform->setMatrix(NanobotMatrix); TheDetails._Node = makeNodeFor(TheDetails._Transform); TheDetails._Node->addChild(cloneTree(NanobotGeoNode)); TheDetails._Node->setTravMask(NanobotMask); TheDetails._PathVisNode = Node::create(); Nanobots.push_back(TheDetails); makeNanobotPath(Nanobots.back(), TheOctree, TutorialWindow, Min,Max); } for(UInt32 i(0) ; i<Nanobots.size() ; ++i) { RootNode->addChild(Nanobots[i]._Node); RootNode->addChild(Nanobots[i]._PathVisNode); } commitChanges(); //NodeRecPtr StartNode = makeSphere(1.0, 2); //TransformRecPtr StartNodeTransform = Transform::create(); //Matrix StartNodeMatrix; //StartNodeMatrix.setTranslate(Start); //StartNodeMatrix.setScale(0.1f); //StartNodeTransform->setMatrix(StartNodeMatrix); //NodeRecPtr StartNodeTransformNode = makeNodeFor(StartNodeTransform); //StartNodeTransformNode->addChild(StartNode); //StartNodeTransformNode->setTravMask(PathMask); //RootNode->addChild(StartNodeTransformNode); //NodeRecPtr GoalNode = makeSphere(1.0, 2); //TransformRecPtr GoalNodeTransform = Transform::create(); //Matrix GoalNodeMatrix; //GoalNodeMatrix.setScale(0.1f); //GoalNodeMatrix.setTranslate(Goal); //GoalNodeTransform->setMatrix(GoalNodeMatrix); //NodeRecPtr GoalNodeTransformNode = makeNodeFor(GoalNodeTransform); //GoalNodeTransformNode->addChild(GoalNode); //GoalNodeTransformNode->setTravMask(PathMask); //RootNode->addChild(GoalNodeTransformNode); TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1, TutorialWindow.get(), SceneGeometryNode.get(), TheOctree, Nanobots)); //Set the background SolidBackgroundRecPtr TheBackground = SolidBackground::create(); TheBackground->setColor(Color3f(0.0f,0.0f,0.0f)); // tell the manager what to manage sceneManager.setRoot (RootNode); sceneManager.getWindow()->getPort(0)->setBackground(TheBackground); // show the whole RootNode sceneManager.showAll(); Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "01AStarPathing"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); { // Set up Window WindowEventProducerRecPtr TutorialWindow = createNativeWindow(); SimpleSceneManager sceneManager; TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager)); TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager)); //Initialize Window TutorialWindow->initWindow(); // Tell the Manager what to manage sceneManager.setWindow(TutorialWindow); //Attach to events TutorialWindow->connectMousePressed(boost::bind(mousePressed, _1, &sceneManager)); TutorialWindow->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager)); TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager)); TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager)); //Print key command info std::cout << "\n\nKEY COMMANDS:" << std::endl; std::cout << "space Play/Pause the animation" << std::endl; std::cout << "B Show/Hide the bind pose skeleton" << std::endl; std::cout << "P Show/Hide the current pose skeleton" << std::endl; //std::cout << "1 Play first example animation" << std::endl; //std::cout << "2 Play second example animation" << std::endl; std::cout << "CTRL-Q Exit\n\n" << std::endl; //SkeletonDrawer System Material LineChunkUnrecPtr ExampleLineChunk = LineChunk::create(); ExampleLineChunk->setWidth(2.0f); ExampleLineChunk->setSmooth(true); BlendChunkUnrecPtr ExampleBlendChunk = BlendChunk::create(); ExampleBlendChunk->setSrcFactor(GL_SRC_ALPHA); ExampleBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA); MaterialChunkUnrecPtr ExampleMaterialChunk = MaterialChunk::create(); ExampleMaterialChunk->setAmbient(Color4f(1.0f,1.0f,1.0f,1.0f)); ExampleMaterialChunk->setDiffuse(Color4f(0.0f,0.0f,0.0f,1.0f)); ExampleMaterialChunk->setSpecular(Color4f(0.0f,0.0f,0.0f,1.0f)); ChunkMaterialUnrecPtr ExampleMaterial = ChunkMaterial::create(); ExampleMaterial->addChunk(ExampleLineChunk); ExampleMaterial->addChunk(ExampleMaterialChunk); ExampleMaterial->addChunk(ExampleBlendChunk); GeometryRefPtr SphereGeometry = makeSphereGeo(2, 0.25f); GeometryRefPtr BoxGeometry = makeBoxGeo(0.5f,0.5f,0.5f,1,1,1); //Skeleton SkeletonBlendedGeometryUnrecPtr ExampleSkeleton = SkeletonBlendedGeometry::create(); //Joint TransformRecPtr ExampleRootJoint = Transform::create(); NodeRecPtr ExampleRootJointNode = makeNodeFor(ExampleRootJoint); //Add this joint to the skeleton ExampleSkeleton->pushToJoints(ExampleRootJointNode, Matrix()); NodeRecPtr TempRootJointNode = ExampleRootJointNode; NodeRefPtr GeoNode = makeNodeFor(BoxGeometry); TempRootJointNode->addChild(GeoNode); Matrix TempMat; //Create a set of randomly placed child joints for (Real32 i = 0.0f; i < 5.0f; ++i) { TransformRecPtr ExampleChildJoint = Transform::create(); NodeRecPtr ExampleChildJointNode = makeNodeFor(ExampleChildJoint); GeoNode = makeNodeFor(SphereGeometry); ExampleChildJointNode->addChild(GeoNode); //TempMat.setTranslate(RandomPoolManager::getRandomReal32(0.0, 10.0f), RandomPoolManager::getRandomReal32(0.0f, 10.0f), RandomPoolManager::getRandomReal32(0.0f, 10.0f)); switch((static_cast<UInt32>(i) % 3)) { case 0: TempMat.setTranslate(2.0f,0.0f,0.0f); break; case 1: TempMat.setTranslate(0.0f,2.0f,0.0f); break; case 2: TempMat.setTranslate(0.0f,0.0f,2.0f); break; } //Set bind and current transformations to TempMat (calculated above) ExampleChildJoint->setMatrix(TempMat); //Add ExampleChildJoint as a child to the previous joint TempRootJointNode->addChild(ExampleChildJointNode);//add a Child to the root joint //ExampleChildJoint will be the next parent joint TempRootJointNode = ExampleChildJointNode; //Add this joint to the skeleton Matrix InvBind(TempRootJointNode->getToWorld()); InvBind.invert(); ExampleSkeleton->pushToJoints(ExampleChildJointNode, InvBind); } //SkeletonDrawer SkeletonDrawableUnrecPtr ExampleSkeletonDrawable = SkeletonDrawable::create(); ExampleSkeletonDrawable->setSkeleton(ExampleSkeleton); ExampleSkeletonDrawable->setMaterial(ExampleMaterial); ExampleSkeletonDrawable->setDrawBindPose(false); //By default, we won't draw the skeleton's bind pose ExampleSkeletonDrawable->setBindPoseColor(Color4f(0.0, 1.0, 0.0, 1.0)); //When the skeleton's bind pose is rendered, it will be green ExampleSkeletonDrawable->setDrawPose(true); //By default, we do draw the skeleton's current pose ExampleSkeletonDrawable->setPoseColor(Color4f(0.0, 0.0, 1.0, 1.0)); //The skeleton's current pose is rendered in blue //Skeleton Node NodeUnrecPtr SkeletonNode = Node::create(); SkeletonNode->setCore(ExampleSkeletonDrawable); //Create scene NodeUnrecPtr scene = Node::create(); scene->setCore(Group::create()); scene->addChild(SkeletonNode); scene->addChild(ExampleRootJointNode); sceneManager.setRoot(scene); //Create the Documentation SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow); //Setup the Animation AnimationUnrecPtr TheAnimation = setupAnimation(ExampleRootJoint, dynamic_cast<Transform*>(ExampleRootJointNode->getChild(1)->getCore())); TheAnimation->attachUpdateProducer(TutorialWindow); TheAnimation->start(); TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1, TheAnimation.get(), SkeletonNode.get(), TutorialWindow.get())); // Show the whole Scene sceneManager.showAll(); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "11BoneAnimation"); //Main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }