// // setup scene // static int doMain(int argc, char *argv[]) { preloadSharedObject("OSGFileIO"); preloadSharedObject("OSGImageFileIO"); osgInit(argc,argv); int winid = setupGLUT(&argc, argv); win = GLUTWindow::create(); win->setGlutId(winid); win->init(); if(argc < 2) { FWARNING(("No file given!\n")); FWARNING(("Supported file formats:\n")); std::list<const char*> suffixes; SceneFileHandler::the()->getSuffixList(suffixes); for(std::list<const char*>::iterator it = suffixes.begin(); it != suffixes.end(); ++it) { FWARNING(("%s\n", *it)); } staticScene = createStaticScene(); } else { staticScene = SceneFileHandler::the()->read(argv[1]); } dynamicScene = createDynamicScene(); commitChanges(); mgr = SimpleSceneManager::create(); NodeUnrecPtr root = makeCoredNode<Group>(); root->addChild(staticScene); mgr->setWindow(win); mgr->setRoot (root); GradientBackgroundUnrecPtr background = GradientBackground::create(); background->addLine(Color3f(0,0,0), 0); background->addLine(Color3f(1,1,1), 1); staticVp = win->getPort(0); staticVp->setBackground(background); camera = staticVp->getCamera(); mgr->showAll(); return 0; }
static void createDynamicViewport() { win->subPortByObj(staticVp); FBOBackgroundUnrecPtr fboBckgnd = FBOBackground::create(); fboBckgnd->setFrameBufferObject(spSimpleFBO->fbo()); NodeUnrecPtr root = makeCoredNode<Group>(); root->addChild(dynamicScene); mgr->setRoot(root); dynamicVp = Viewport::create(); dynamicVp->setRoot (rootNode(root)); dynamicVp->setBackground(fboBckgnd); dynamicVp->setCamera (camera); dynamicVp->setSize (0,0, 1,1); mgr->getNavigator()->setViewport(dynamicVp); win->addPort(dynamicVp); mgr->update(); }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); 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(); GradientBackgroundRefPtr TheBackground = GradientBackground::create(); TheBackground->addLine(Color3f(1.0,0.0,0.0), 0.0); TheBackground->addLine(Color3f(0.0,1.0,0.0), 0.2); TheBackground->addLine(Color3f(0.0,0.0,1.0), 0.4); TheBackground->addLine(Color3f(0.0,1.0,1.0), 0.6); TheBackground->addLine(Color3f(1.0,1.0,0.0), 0.8); TheBackground->addLine(Color3f(1.0,1.0,1.0), 1.0); /****************************************************** Create a List. A List has several parts to it: -ListModel: Contains the data which is to be displayed in the List. Data is added as shown below -ListCellRenderer: Creates the Components to be used within the List (the default setting is to create Labels using the desired text). -ListSelectionModel: Determines how the List may be selected. To add values to the list: First, create SFStrings and use the .setValue("Value") function to set their values. Then, use the .pushBack(&SFStringName) to add them to the List. Next, create the CellRenderer and ListSelectionModel defaults. Finally, actually create the List. Set its Model, CellRenderer, and SelectionModel as shown below. Finally, choose the type of display for the List (choices outlined below). ******************************************************/ // Add data to it ExampleListModel = MFieldListModel::create(); ExampleListModel->setContainer(TheBackground); ExampleListModel->setFieldId(GradientBackground::ColorFieldId); /****************************************************** Create ListCellRenderer and ListSelectionModel. Most often the defauls will be used. Note: the ListSelectionModel was created above and is referenced by the ActionListeners. ******************************************************/ /****************************************************** Create List itself and assign its Model, CellRenderer, and SelectionModel to it. -setOrientation(ENUM): Determine the Layout of the cells (Horizontal or Vertical). Takes List::VERTICAL_ORIENTATION and List::HORIZONTAL_ORIENTATION arguments. ******************************************************/ ExampleList = List::create(); ExampleList->setPreferredSize(Vec2f(200, 300)); ExampleList->setOrientation(List::VERTICAL_ORIENTATION); //ExampleList->setOrientation(List::HORIZONTAL_ORIENTATION); ExampleList->setModel(ExampleListModel); ExampleList->setSelectionModel(ExampleListSelectionModel); /****************************************************** Determine the SelectionModel -SINGLE_SELECTION lets you select ONE item via a single mouse click -SINGLE_INTERVAL_SELECTION lets you select one interval via mouse and SHIFT key -MULTIPLE_INTERVAL_SELECTION lets you select via mouse, and SHIFT and CONTRL keys Note: this tutorial is currently set up to allow for this to be changed via TogggleButtons with ActionListeners attached to them so this code is commented out. ******************************************************/ //SelectionModel.setMode(DefaultListSelectionModel::SINGLE_SELECTION); //SelectionModel.setMode(DefaultListSelectionModel::SINGLE_INTERVAL_SELECTION); //SelectionModel.setMode(DefaultListSelectionModel::MULTIPLE_INTERVAL_SELECTION); // Create a ScrollPanel for easier viewing of the List (see 27ScrollPanel) ScrollPanelRefPtr ExampleScrollPanel = ScrollPanel::create(); ExampleScrollPanel->setPreferredSize(Vec2f(200,300)); ExampleScrollPanel->setHorizontalResizePolicy(ScrollPanel::RESIZE_TO_VIEW); //ExampleScrollPanel->setVerticalResizePolicy(ScrollPanel::RESIZE_TO_VIEW); ExampleScrollPanel->setViewComponent(ExampleList); // Create MainFramelayout FlowLayoutRefPtr MainInternalWindowLayout = OSG::FlowLayout::create(); MainInternalWindowLayout->setOrientation(FlowLayout::VERTICAL_ORIENTATION); MainInternalWindowLayout->setMajorAxisAlignment(0.5f); MainInternalWindowLayout->setMinorAxisAlignment(0.5f); LabelRefPtr ListLabel = Label::create(); ListLabel->setText("Background Colors List"); ListLabel->setPreferredSize(Vec2f(200.0f, ListLabel->getPreferredSize().y())); // 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(ListLabel); MainInternalWindow->pushToChildren(ExampleScrollPanel); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.7f,0.5f)); MainInternalWindow->setDrawTitlebar(false); MainInternalWindow->setResizable(false); // Create the Drawing Surface UIDrawingSurfaceRefPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundRefPtr TutorialUIForeground = OSG::UIForeground::create(); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); // Create the SimpleSceneManager helper 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(TheBackground); // 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, "44MFieldList"); //Enter main Loop TutorialWindow->mainLoop(); osgExit(); return 0; }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); { TheLuaManager->init(); // 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); //Setup the Lua Manager BoostPath ModulePath("./Data/"); std::string PackagePath = std::string("?;") + (ModulePath / "?.lua" ).file_string() + ";" + (ModulePath / "?" / "init.lua").file_string(); TheLuaManager->setPackagePath(PackagePath); // Make Torus Node (creates Torus in background of scene) GeometryRefPtr TorusGeometry = makeTorusGeo(.5, 2, 16, 16); setName(TorusGeometry,"Torus Geometry"); //calcVertexTangents(TorusGeometry,0,Geometry::TexCoords7FieldId, Geometry::TexCoords6FieldId); NodeRefPtr TorusGeometryNode = Node::create(); setName(TorusGeometryNode,"Torus Geometry Node"); TorusGeometryNode->setCore(TorusGeometry); //Torus Transformation Node TransformRefPtr TheTorusNodeTransform = Transform::create(); NodeRefPtr TheTorusTransfromNode = Node::create(); TheTorusTransfromNode->setCore(TheTorusNodeTransform); TheTorusTransfromNode->addChild(TorusGeometryNode); setName(TheTorusTransfromNode,"Torus Transform Node"); // Make Main Scene Node and add the Torus NodeRefPtr scene = Node::create(); scene->setCore(Group::create()); scene->addChild(TheTorusTransfromNode); setName(scene,"Scene Node"); //Light Beacon Node TransformRefPtr TheLightBeaconNodeTransform = Transform::create(); NodeRefPtr TheLightBeaconNode = Node::create(); TheLightBeaconNode->setCore(TheLightBeaconNodeTransform); setName(TheLightBeaconNode,"Light Beacon Node"); //Light Node DirectionalLightRefPtr TheLightCore = DirectionalLight::create(); TheLightCore->setDirection(Vec3f(1.0,0.0,0.0)); TheLightCore->setAmbient(Color4f(1.0,1.0,1.0,1.0)); TheLightCore->setDiffuse(Color4f(1.0,1.0,1.0,1.0)); TheLightCore->setSpecular(Color4f(1.0,1.0,1.0,1.0)); TheLightCore->setBeacon(TheLightBeaconNode); NodeRefPtr TheLightNode = Node::create(); TheLightNode->setCore(TheLightCore); TheLightNode->addChild(scene); setName(TheLightNode,"Light Node"); NodeRefPtr RootNode = Node::create(); RootNode->setCore(Group::create()); RootNode->addChild(TheLightNode); RootNode->addChild(TheLightBeaconNode); setName(RootNode,"Root Node"); // Create the Graphics GraphicsRefPtr TutorialGraphics = Graphics2D::create(); // Initialize the LookAndFeelManager to enable default settings LookAndFeelManager::the()->getLookAndFeel()->init(); //Create the Main interface LuaDebuggerInterface TheLuaDebuggerInterface; // 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)); BorderLayoutRefPtr MainInternalWindowLayout = BorderLayout::create(); //Split Panel BorderLayoutConstraintsRefPtr SplitPanelConstraints = BorderLayoutConstraints::create(); SplitPanelConstraints->setRegion(BorderLayoutConstraints::BORDER_CENTER); TheLuaDebuggerInterface.getMainSplitPanel()->setConstraints(SplitPanelConstraints); BorderLayoutConstraintsRefPtr ButtonPanelConstraints = BorderLayoutConstraints::create(); ButtonPanelConstraints->setRegion(BorderLayoutConstraints::BORDER_NORTH); TheLuaDebuggerInterface.getButtonPanel()->setConstraints(ButtonPanelConstraints); BorderLayoutConstraintsRefPtr CodeAreaInfoPanelConstraints = BorderLayoutConstraints::create(); CodeAreaInfoPanelConstraints->setRegion(BorderLayoutConstraints::BORDER_SOUTH); TheLuaDebuggerInterface.getCodeAreaInfoPanel()->setConstraints(CodeAreaInfoPanelConstraints); InternalWindowRefPtr MainInternalWindow = InternalWindow::create(); MainInternalWindow->pushToChildren(TheLuaDebuggerInterface.getButtonPanel()); MainInternalWindow->pushToChildren(TheLuaDebuggerInterface.getMainSplitPanel()); MainInternalWindow->pushToChildren(TheLuaDebuggerInterface.getCodeAreaInfoPanel()); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setTitle("Lua Debugger"); setName(MainInternalWindow,"Internal Window"); // 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); //Scene Background GradientBackgroundRefPtr SceneBackground = GradientBackground::create(); SceneBackground->addLine(Color3f(0.0,0.0,0.0),0.0); setName(SceneBackground,"Scene Background"); // Tell the Manager what to manage sceneManager.setWindow(TutorialWindow); sceneManager.setRoot(RootNode); //sceneManager.setHeadlight(false); // Add the UI Foreground Object to the Scene ViewportRefPtr TutorialViewport = sceneManager.getWindow()->getPort(0); TutorialViewport->addForeground(TutorialUIForeground); TutorialViewport->setBackground(SceneBackground); TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1, &TheLuaDebuggerInterface)); // 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, "03LuaDebugger"); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setPreferredSize(WinSize * 0.85); //Enter main Loop TutorialWindow->mainLoop(); TheLuaManager->uninit(); } 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 TutorialBackground = GradientBackground::create(); TutorialBackground->addLine(Color3f(1.0,0.0,0.0), 0.0); TutorialBackground->addLine(Color3f(0.0,1.0,0.0), 0.2); TutorialBackground->addLine(Color3f(0.0,0.0,1.0), 0.4); TutorialBackground->addLine(Color3f(0.0,1.0,1.0), 0.6); TutorialBackground->addLine(Color3f(1.0,1.0,0.0), 0.8); TutorialBackground->addLine(Color3f(1.0,1.0,1.0), 1.0); TheUndoManager = UndoManager::create(); UndoManagerChangeListener TheUndoManagerChangeListener; TheUndoManager->addChangeListener(&TheUndoManagerChangeListener); LabelRefPtr SingleFieldLabel = OSG::Label::create(); SingleFieldLabel->setText("Single Field"); SingleFieldLabel->setBorders(NULL); SingleFieldLabel->setBackgrounds(NULL); LabelRefPtr MultiFieldLabel = OSG::Label::create(); MultiFieldLabel->setText("Multi Field"); MultiFieldLabel->setBorders(NULL); MultiFieldLabel->setBackgrounds(NULL); LabelRefPtr SinglePtrFieldLabel = OSG::Label::create(); SinglePtrFieldLabel->setText("Single Ptr Field"); SinglePtrFieldLabel->setBorders(NULL); SinglePtrFieldLabel->setBackgrounds(NULL); LabelRefPtr MultiPtrFieldLabel = OSG::Label::create(); MultiPtrFieldLabel->setText("Multi Ptr Field"); MultiPtrFieldLabel->setBorders(NULL); MultiPtrFieldLabel->setBackgrounds(NULL); TabPanelRefPtr ExampleTabPanel = OSG::TabPanel::create(); ExampleTabPanel->setPreferredSize(Vec2f(600,600)); ExampleTabPanel->addTab(SingleFieldLabel, createSingleFieldPanel()); ExampleTabPanel->addTab(MultiFieldLabel, createMultiFieldPanel()); ExampleTabPanel->addTab(SinglePtrFieldLabel, createSinglePtrFieldPanel()); ExampleTabPanel->addTab(MultiPtrFieldLabel, createMultiPtrFieldPanel()); ExampleTabPanel->setTabAlignment(0.5f); ExampleTabPanel->setTabPlacement(TabPanel::PLACEMENT_NORTH); ExampleTabPanel->setSelectedIndex(0); //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); // 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(ExampleTabPanel); 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, "01ChangeFieldCommands"); //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); // GLUT init int winid = setupGLUT(&argc, argv); if(argc >= 2) scene = SceneFileHandler::the()->read(argv[1]); else scene = SceneFileHandler::the()->read("Data/tie.wrl"); if(scene == NULL) scene = makeTorus(0.3, 4, 16, 64); // init material phong_chunk = createPhongShaderMaterial(); // get all the Materials of the current scene getAllMaterials(scene, materials); // add the phong material chunk to every found material for(int i = 0; i < materials.size(); ++i) { (materials[i])->addChunk(phong_chunk); } phong_active = true; // open a new scope, because the pointers below should go out of scope // before entering glutMainLoop. // Otherwise OpenSG will complain about objects being alive after shutdown. { // the connection between GLUT and OpenSG GLUTWindowRefPtr gwin = GLUTWindow::create(); gwin->setGlutId(winid); gwin->init ( ); // create the SimpleSceneManager helper _mgr = new SimpleSceneManager; // tell the manager what to manage _mgr->setWindow (gwin ); _mgr->setRoot (scene); _mgr->turnHeadlightOn( ); commitChanges(); // show the whole scene _mgr->showAll(); // create a gradient background. GradientBackgroundRefPtr gbg = GradientBackground::create(); gbg->clearLines(); gbg->addLine(Color3f(0.7, 0.7, 0.8), 0); gbg->addLine(Color3f(0.0, 0.1, 0.3), 1); //set gradient background ViewportRefPtr vp = gwin->getPort(0); vp->setBackground(gbg); commitChanges(); } // GLUT main loop glutMainLoop(); return 0; }
void ApplicationStartScreen::attachApplication(void) { Inherited::attachApplication(); //Camera Transformation Node Matrix CameraTransformMatrix; CameraTransformMatrix.setTranslate(0.0f,0.0f, 5.0f); TransformRefPtr CameraBeaconTransform = Transform::create(); CameraBeaconTransform->setMatrix(CameraTransformMatrix); NodeRefPtr CameraBeaconNode = Node::create(); CameraBeaconNode->setCore(CameraBeaconTransform); // Make Torus Node (creates Torus in background of scene) NodeRefPtr TorusGeometryNode = NULL; //BoostPath TorusKnotFile(MainApplication::the()->getSettings()->getDataDirectory() / std::string("Models") / std::string("TorusKnot.osb")); //SLOG << "Loading Torus Knot from: " << TorusKnotFile.string() << std::endl; //if(boost::filesystem::exists(TorusKnotFile)) //{ //TorusGeometryNode = SceneFileHandler::the()->read(TorusKnotFile.native_file_string().c_str()); //} //if(TorusGeometryNode == NULL) //{ //SWARNING << "Could not load Torus Knot from: " //<< TorusKnotFile.string() << " because this file doesn't exist." << std::endl; TorusGeometryNode = makeTorus(.5, 2, 64, 64); //} //Scene Transformation TransformRefPtr SceneTransformCore = Transform::create(); NodeRefPtr SceneTransformNode = Node::create(); SceneTransformNode->setCore(SceneTransformCore); SceneTransformNode->addChild(TorusGeometryNode); //Light NodeRefPtr LightBeaconNode = Node::create(); LightBeaconNode->setCore(Transform::create()); DirectionalLightRefPtr SceneLightCore = DirectionalLight::create(); SceneLightCore->setDirection(1.0,0.0,0.0); SceneLightCore->setBeacon(LightBeaconNode); NodeRefPtr SceneLightNode = Node::create(); SceneLightNode->setCore(SceneLightCore); SceneLightNode->addChild(SceneTransformNode); // Make Main Scene Node and add the Torus NodeRefPtr DefaultRootNode = OSG::Node::create(); DefaultRootNode->setCore(OSG::Group::create()); DefaultRootNode->addChild(CameraBeaconNode); DefaultRootNode->addChild(SceneLightNode); DefaultRootNode->addChild(LightBeaconNode); //Camera PerspectiveCameraRefPtr DefaultCamera = PerspectiveCamera::create(); DefaultCamera->setBeacon(CameraBeaconNode); DefaultCamera->setFov (osgDegree2Rad(60.f)); DefaultCamera->setNear (0.1f); DefaultCamera->setFar (10000.f); //Background GradientBackgroundRefPtr DefaultBackground = GradientBackground::create(); DefaultBackground->addLine(Color3f(0.0f,0.0f,0.0f), 0.0f); DefaultBackground->addLine(Color3f(0.0f,0.0f,0.5f), 1.0f); //Animation //KeyFrames KeyframeTransformationSequenceRefPtr TransformationKeyframes = KeyframeTransformationSequenceMatrix4f::create(); OSG::Matrix TempMat; TransformationKeyframes->addKeyframe(TempMat,0.0f); TempMat.setRotate(Quaternion(Vec3f(0.0f,1.0f,0.0f), 3.14159f*0.5)); TransformationKeyframes->addKeyframe(TempMat,4.0f); TempMat.setRotate(Quaternion(Vec3f(0.0f,1.0f,0.0f), 3.14159f*1.0)); TransformationKeyframes->addKeyframe(TempMat,8.0f); TempMat.setRotate(Quaternion(Vec3f(0.0f,1.0f,0.0f), 3.14159f*1.5)); TransformationKeyframes->addKeyframe(TempMat,12.0f); TempMat.setRotate(Quaternion(Vec3f(0.0f,1.0f,0.0f), 0.0f)); TransformationKeyframes->addKeyframe(TempMat,16.0f); //Animator KeyframeAnimatorRefPtr TorusAnimator = OSG::KeyframeAnimator::create(); TorusAnimator->setKeyframeSequence(TransformationKeyframes); //Animation _TorusAnimation = FieldAnimation::create(); _TorusAnimation->setAnimator(TorusAnimator); _TorusAnimation->setInterpolationType(Animator::LINEAR_INTERPOLATION); _TorusAnimation->setCycling(-1); _TorusAnimation->setAnimatedField(SceneTransformCore, std::string("matrix")); _TorusAnimation->attachUpdateProducer(MainApplication::the()->getMainWindow()->editEventProducer()); _TorusAnimation->start(); //Foreground //ImageForegroundRefPtr LogoForeground = ImageForeground::create(); //BoostPath LogoPath(MainApplication::the()->getSettings()->getDataDirectory() / "Images/Logo.png"); //ImageRefPtr LoadedImage = ImageFileHandler::the().read(LogoPath.string().c_str()); // LogoForeground->addImage( LoadedImage, Pnt2f( 0,0 ) ); ForegroundRefPtr UserInterfaceForeground = createInterface(); _TheUIDrawingSurface->setEventProducer(MainApplication::the()->getMainWindow()); if(MainApplication::the()->getMainWindow() != NULL && MainApplication::the()->getMainWindow()->getMFPort()->size() == 0) { ViewportRefPtr DefaultViewport = Viewport::create(); DefaultViewport->setCamera (DefaultCamera); DefaultViewport->setRoot (DefaultRootNode); DefaultViewport->setSize (0.0f,0.0f, 1.0f,1.0f); DefaultViewport->setBackground (DefaultBackground); DefaultViewport->addForeground (UserInterfaceForeground); MainApplication::the()->getMainWindow()->addPort(DefaultViewport); } MainApplication::the()->getMainWindow()->addKeyListener(&_StartScreenKeyListener); MainApplication::the()->getMainWindow()->addUpdateListener(&_ScreenUpdateListener); }
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) 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)); UndoManagerPtr TheUndoManager = UndoManager::create(); CommandManagerPtr TheCommandManager = CommandManager::create(TheUndoManager); //UndoList DefaultListModelRecPtr UndoRedoListModel = DefaultListModel::create(); UndoRedoListModel->pushBack(boost::any(std::string("Top"))); ListRecPtr UndoRedoList = List::create(); UndoRedoList->setPreferredSize(Vec2f(250, 300)); UndoRedoList->setOrientation(List::VERTICAL_ORIENTATION); UndoRedoList->setModel(UndoRedoListModel); UndoRedoList->getSelectionModel()->connectSelectionChanged(boost::bind(&handleUndoRedoListSelectionChanged, _1, TheUndoManager)); ButtonRecPtr UndoButton = OSG::Button::create(); UndoButton->setText("Undo"); UndoButton->setEnabled(false); UndoButton->connectActionPerformed(boost::bind(&handleUndoButtonAction, _1, TheUndoManager)); ButtonRecPtr RedoButton = OSG::Button::create(); RedoButton->setText("Redo"); RedoButton->setEnabled(false); RedoButton->connectActionPerformed(boost::bind(&handleRedoButtonActionPerformed, _1, TheUndoManager)); TheUndoManager->connectStateChanged(boost::bind(&handleUndoManagerStateChanged, _1, UndoButton.get(), RedoButton.get(), UndoRedoListModel.get(), TheUndoManager)); // 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); //Edited Label LabelRecPtr EditedLabel = Label::create(); EditedLabel->setText("Can be edited"); EditedLabel->setPreferredSize(Vec2f(100.0f,18.0f)); //Editor Field LabelRecPtr TheTextEditorLabel = Label::create(); TheTextEditorLabel->setText("Text"); TheTextEditorLabel->setPreferredSize(Vec2f(100.0f, 20.0f)); FieldEditorComponentRefPtr TheTextEditor = FieldEditorFactory::the()->createDefaultEditor(EditedLabel, Label::TextFieldId, TheCommandManager); TheTextEditor->setPreferredSize(Vec2f(100.0f, 20.0f)); LabelRecPtr ThePreferredSizeEditorLabel = Label::create(); ThePreferredSizeEditorLabel->setText("PreferredSize"); ThePreferredSizeEditorLabel->setPreferredSize(Vec2f(100.0f, 20.0f)); FieldEditorComponentRefPtr ThePreferredSizeEditor = FieldEditorFactory::the()->createDefaultEditor(EditedLabel, Label::PreferredSizeFieldId, TheCommandManager); ThePreferredSizeEditor->setPreferredSize(Vec2f(150.0f, 20.0f)); //Editing Panel LayoutRefPtr EditorPanelLayout = OSG::FlowLayout::create(); PanelRecPtr EditorPanel = Panel::create(); EditorPanel->setPreferredSize(Vec2f(200.0f,200.0f)); EditorPanel->pushToChildren(TheTextEditorLabel); EditorPanel->pushToChildren(TheTextEditor); EditorPanel->pushToChildren(ThePreferredSizeEditorLabel); EditorPanel->pushToChildren(ThePreferredSizeEditor); EditorPanel->setLayout(EditorPanelLayout); //Undo Panel LabelRecPtr UndoPanelLabel = Label::create(); UndoPanelLabel->setText("Undo Panel"); UndoPanelLabel->setPreferredSize(Vec2f(100.0f, 20.0f)); LayoutRefPtr UndoPanelLayout = OSG::FlowLayout::create(); PanelRecPtr UndoPanel = Panel::create(); UndoPanel->setPreferredSize(Vec2f(300.0f,300.0f)); UndoPanel->pushToChildren(UndoPanelLabel); UndoPanel->pushToChildren(UndoRedoScrollPanel); UndoPanel->pushToChildren(UndoButton); UndoPanel->pushToChildren(RedoButton); UndoPanel->setLayout(UndoPanelLayout); // 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(EditedLabel); MainInternalWindow->pushToChildren(EditorPanel); MainInternalWindow->pushToChildren(UndoPanel); 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); // Tell the Manager what to manage sceneManager.setWindow(TutorialWindow); sceneManager.setRoot(scene); // Add the UI Foreground Object to the Scene ViewportRefPtr TutorialViewport = sceneManager.getWindow()->getPort(0); TutorialViewport->addForeground(TutorialUIForeground); TutorialViewport->setBackground(TutorialBackground); // 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, "02GenericFieldEditor"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }