int main(int argc, char **argv) { // OSG init osgInit(argc,argv); TutorialWindowEventProducer = createDefaultWindowEventProducer(); WindowPtr MainWindow = TutorialWindowEventProducer->initWindow(); TutorialWindowEventProducer->setDisplayCallback(display); TutorialWindowEventProducer->setReshapeCallback(reshape); TutorialKeyListener TheKeyListener; TutorialWindowEventProducer->addKeyListener(&TheKeyListener); // Make Torus Node (creates Torus in background of scene) NodePtr TorusGeometryNode = makeTorus(.5, 2, 16, 16); // Make Main Scene Node and add the Torus NodePtr scene = osg::Node::create(); beginEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask); scene->setCore(osg::Group::create()); scene->addChild(TorusGeometryNode); endEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask); // Create the Graphics GraphicsPtr TutorialGraphics = osg::Graphics2D::create(); // Initialize the LookAndFeelManager to enable default settings LookAndFeelManager::the()->getLookAndFeel()->init(); //Create InventoryItems ExampleInventory = Inventory::create(); GenericInventoryItemPtr ExampleItem1 = GenericInventoryItem::create(); GenericInventoryItemPtr ExampleItem2 = GenericInventoryItem::create(); GenericInventoryItemPtr ExampleItem3 = GenericInventoryItem::create(); GenericInventoryItemPtr ExampleItem4 = GenericInventoryItem::create(); GenericInventoryItemPtr ExampleItem5 = GenericInventoryItem::create(); GenericInventoryItemPtr ExampleItem6 = GenericInventoryItem::create(); GenericInventoryItemPtr ExampleItem7 = GenericInventoryItem::create(); beginEditCP(ExampleItem1, InventoryItem::NameFieldMask | GenericInventoryItem::DetailsFieldMask); ExampleItem1->setName(std::string("David K")); ExampleItem1->setDetails(std::string("Major: Human Computer Interaction \nDegree: PhD \nDepartment: Computer Science \nCollege: LAS")); endEditCP(ExampleItem1, InventoryItem::NameFieldMask | GenericInventoryItem::DetailsFieldMask); beginEditCP(ExampleItem2, InventoryItem::NameFieldMask | GenericInventoryItem::DetailsFieldMask); ExampleItem2->setName(std::string("Eve W")); ExampleItem2->setDetails(std::string("Department: Genetics Development and Cell Biology\n\nCollege: Agriculture")); endEditCP(ExampleItem2, InventoryItem::NameFieldMask | GenericInventoryItem::DetailsFieldMask); beginEditCP(ExampleItem3, InventoryItem::NameFieldMask | GenericInventoryItem::DetailsFieldMask); ExampleItem3->setName(std::string("Will S")); ExampleItem3->setDetails(std::string("Major: Art And Design\nDegree: BFA\nDepartment: Art and Design\nCollege: Design")); endEditCP(ExampleItem3, InventoryItem::NameFieldMask | GenericInventoryItem::DetailsFieldMask); beginEditCP(ExampleItem4, InventoryItem::NameFieldMask | GenericInventoryItem::DetailsFieldMask); ExampleItem4->setName(std::string("Eric L")); ExampleItem4->setDetails(std::string("Major: Software Engineering\nDegree: BS\nDepartment: Software Engineering\nCollege: Engineering")); endEditCP(ExampleItem4, InventoryItem::NameFieldMask | GenericInventoryItem::DetailsFieldMask); beginEditCP(ExampleItem5, InventoryItem::NameFieldMask | GenericInventoryItem::DetailsFieldMask); ExampleItem5->setName(std::string("Jeffery F")); ExampleItem5->setDetails(std::string("Major: Integrated Studio Arts\nDegree: BFA\nDepartment: Art and Design\nCollege: Design")); endEditCP(ExampleItem5, InventoryItem::NameFieldMask | GenericInventoryItem::DetailsFieldMask); beginEditCP(ExampleItem6, InventoryItem::NameFieldMask | GenericInventoryItem::DetailsFieldMask); ExampleItem6->setName(std::string("Tao L")); ExampleItem6->setDetails(std::string("Major: Computer Engineering\nDegree: PhD\nDepartment: Computer Engineering\nCollege: Engineering")); endEditCP(ExampleItem6, InventoryItem::NameFieldMask | GenericInventoryItem::DetailsFieldMask); beginEditCP(ExampleItem7, InventoryItem::NameFieldMask | GenericInventoryItem::DetailsFieldMask); ExampleItem7->setName(std::string("Daniel G")); ExampleItem7->setDetails(std::string("Major: Computer Engineering\nDegree: BS\nDepartment: Computer Engineering\nCollege: Engineering")); endEditCP(ExampleItem7, InventoryItem::NameFieldMask | GenericInventoryItem::DetailsFieldMask); ExampleInventory->addItem(ExampleItem1); ExampleInventory->addItem(ExampleItem2); ExampleInventory->addItem(ExampleItem3); ExampleInventory->addItem(ExampleItem4); ExampleInventory->addItem(ExampleItem5); ExampleInventory->addItem(ExampleItem6); ExampleInventory->addItem(ExampleItem7); /****************************************************** 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 = InventoryListModel::create(); beginEditCP(ExampleListModel, InventoryListModel::CurrentInventoryFieldMask); ExampleListModel->setCurrentInventory(ExampleInventory); endEditCP(ExampleListModel, InventoryListModel::CurrentInventoryFieldMask); /****************************************************** 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(); beginEditCP(ExampleList, List::PreferredSizeFieldMask | List::OrientationFieldMask | List::ModelFieldMask); ExampleList->setPreferredSize(Vec2f(200, 300)); ExampleList->setOrientation(List::VERTICAL_ORIENTATION); //ExampleList->setOrientation(List::HORIZONTAL_ORIENTATION); ExampleList->setModel(ExampleListModel); endEditCP(ExampleList, List::PreferredSizeFieldMask | List::OrientationFieldMask | List::ModelFieldMask); ExampleList->setSelectionModel(ExampleListSelectionModel); InventoryListListener TheInventoryListListener; ExampleList->getSelectionModel()->addListSelectionListener(&TheInventoryListListener); // Create The Main InternalWindow // Create Background to be used with the Main InternalWindow ColorLayerPtr MainInternalWindowBackground = osg::ColorLayer::create(); beginEditCP(MainInternalWindowBackground, ColorLayer::ColorFieldMask); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); endEditCP(MainInternalWindowBackground, ColorLayer::ColorFieldMask); /****************************************************** 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) ScrollPanelPtr ExampleScrollPanel = ScrollPanel::create(); beginEditCP(ExampleScrollPanel, ScrollPanel::PreferredSizeFieldMask | ScrollPanel::HorizontalResizePolicyFieldMask | ScrollPanel::BackgroundFieldMask); ExampleScrollPanel->setPreferredSize(Vec2f(200,100)); ExampleScrollPanel->setBackgrounds(MainInternalWindowBackground); ExampleScrollPanel->setHorizontalResizePolicy(ScrollPanel::RESIZE_TO_VIEW); //ExampleScrollPanel->setVerticalResizePolicy(ScrollPanel::RESIZE_TO_VIEW); endEditCP(ExampleScrollPanel, ScrollPanel::PreferredSizeFieldMask | ScrollPanel::HorizontalResizePolicyFieldMask | ScrollPanel::BackgroundFieldMask); ExampleScrollPanel->setViewComponent(ExampleList); // Create MainFramelayout FlowLayoutPtr MainInternalWindowLayout = osg::FlowLayout::create(); beginEditCP(MainInternalWindowLayout, FlowLayout::OrientationFieldMask | FlowLayout::MajorAxisAlignmentFieldMask | FlowLayout::MinorAxisAlignmentFieldMask); MainInternalWindowLayout->setOrientation(FlowLayout::HORIZONTAL_ORIENTATION); MainInternalWindowLayout->setMajorAxisAlignment(0.5f); MainInternalWindowLayout->setMinorAxisAlignment(0.5f); endEditCP(MainInternalWindowLayout, FlowLayout::OrientationFieldMask | FlowLayout::MajorAxisAlignmentFieldMask | FlowLayout::MinorAxisAlignmentFieldMask); DetailsWindow = osg::TextArea::create(); beginEditCP(DetailsWindow, TextArea::PreferredSizeFieldMask); DetailsWindow->setPreferredSize(Pnt2f(200,100)); DetailsWindow->setMinSize(Vec2f(200,100)); endEditCP(DetailsWindow, TextArea::PreferredSizeFieldMask); InternalWindowPtr MainInternalWindow = osg::InternalWindow::create(); beginEditCP(MainInternalWindow, InternalWindow::ChildrenFieldMask | InternalWindow::LayoutFieldMask | InternalWindow::BackgroundsFieldMask | InternalWindow::AlignmentInDrawingSurfaceFieldMask | InternalWindow::ScalingInDrawingSurfaceFieldMask | InternalWindow::DrawTitlebarFieldMask | InternalWindow::ResizableFieldMask); MainInternalWindow->getChildren().push_back(ExampleScrollPanel); MainInternalWindow->getChildren().push_back(DetailsWindow); 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); endEditCP(MainInternalWindow, InternalWindow::ChildrenFieldMask | InternalWindow::LayoutFieldMask | InternalWindow::BackgroundsFieldMask | InternalWindow::AlignmentInDrawingSurfaceFieldMask | InternalWindow::ScalingInDrawingSurfaceFieldMask | InternalWindow::DrawTitlebarFieldMask | InternalWindow::ResizableFieldMask); // Create the Drawing Surface UIDrawingSurfacePtr TutorialDrawingSurface = UIDrawingSurface::create(); beginEditCP(TutorialDrawingSurface, UIDrawingSurface::GraphicsFieldMask | UIDrawingSurface::EventProducerFieldMask); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindowEventProducer); endEditCP(TutorialDrawingSurface, UIDrawingSurface::GraphicsFieldMask | UIDrawingSurface::EventProducerFieldMask); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundPtr TutorialUIForeground = osg::UIForeground::create(); beginEditCP(TutorialUIForeground, UIForeground::DrawingSurfaceFieldMask); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); endEditCP(TutorialUIForeground, UIForeground::DrawingSurfaceFieldMask); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(MainWindow); mgr->setRoot(scene); // Add the UI Foreground Object to the Scene ViewportPtr TutorialViewport = mgr->getWindow()->getPort(0); beginEditCP(TutorialViewport, Viewport::ForegroundsFieldMask); TutorialViewport->getForegrounds().push_back(TutorialUIForeground); beginEditCP(TutorialViewport, Viewport::ForegroundsFieldMask); // Show the whole Scene mgr->showAll(); Vec2f WinSize(TutorialWindowEventProducer->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindowEventProducer->getDesktopSize() - WinSize) *0.5); TutorialWindowEventProducer->openWindow(WinPos, WinSize, "09Inventory"); //Enter main Loop TutorialWindowEventProducer->mainLoop(); osgExit(); return 0; }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); // Set up Window TutorialWindowEventProducer = createDefaultWindowEventProducer(); WindowPtr MainWindow = TutorialWindowEventProducer->initWindow(); TutorialWindowEventProducer->setDisplayCallback(display); TutorialWindowEventProducer->setReshapeCallback(reshape); TutorialUpdateListener TheTutorialUpdateListener; TutorialWindowEventProducer->addUpdateListener(&TheTutorialUpdateListener); //Add Window Listener TutorialKeyListener TheKeyListener; TutorialWindowEventProducer->addKeyListener(&TheKeyListener); TutorialMouseListener TheTutorialMouseListener; TutorialMouseMotionListener TheTutorialMouseMotionListener; TutorialWindowEventProducer->addMouseListener(&TheTutorialMouseListener); TutorialWindowEventProducer->addMouseMotionListener(&TheTutorialMouseMotionListener); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(MainWindow); //Print key command info std::cout << "\n\nKEY COMMANDS:" << std::endl; std::cout << "space Play/Pause the animation" << std::endl; std::cout << "G Show/Hide the grid" << std::endl; std::cout << "A Show/Hide the axes" << std::endl; std::cout << "B Show/Hide the bind pose skeleton" << std::endl; std::cout << "SHIFT-B Show/Hide the bind pose mesh" << std::endl; std::cout << "P Show/Hide the current pose skeleton" << std::endl; std::cout << "SHIFT-P Show/Hide the current pose mesh" << std::endl; std::cout << "CTRL-Q Exit\n\n" << std::endl; //Setup axes LineChunkPtr AxesLineChunk = LineChunk::create(); beginEditCP(AxesLineChunk); AxesLineChunk->setWidth(0.0f); AxesLineChunk->setSmooth(true); endEditCP(AxesLineChunk); //Axes material ChunkMaterialPtr AxesMaterial = ChunkMaterial::create(); beginEditCP(AxesMaterial, ChunkMaterial::ChunksFieldMask); AxesMaterial->addChunk(AxesLineChunk); endEditCP(AxesMaterial, ChunkMaterial::ChunksFieldMask); //Grid material ChunkMaterialPtr gridMaterial = ChunkMaterial::create(); beginEditCP(gridMaterial, ChunkMaterial::ChunksFieldMask); gridMaterial->addChunk(AxesLineChunk); endEditCP(gridMaterial, ChunkMaterial::ChunksFieldMask); //Axes should render as lines GeoPTypesPtr axesType = GeoPTypesUI8::create(); beginEditCP(axesType, GeoPTypesUI8::GeoPropDataFieldMask); { axesType->addValue(GL_LINES); } endEditCP (axesType, GeoPTypesUI8::GeoPropDataFieldMask); //Grid type GeoPTypesPtr gridType = GeoPTypesUI8::create(); beginEditCP(gridType, GeoPTypesUI8::GeoPropDataFieldMask); { gridType->addValue(GL_LINES); } endEditCP (gridType, GeoPTypesUI8::GeoPropDataFieldMask); //Axes lens GeoPLengthsPtr axesLens = GeoPLengthsUI32::create(); beginEditCP(axesLens, GeoPLengthsUI32::GeoPropDataFieldMask); { axesLens->addValue(6); } endEditCP (axesLens, GeoPLengthsUI32::GeoPropDataFieldMask); //Grid lens GeoPLengthsPtr gridLens = GeoPLengthsUI32::create(); beginEditCP(gridLens, GeoPLengthsUI32::GeoPropDataFieldMask); { gridLens->addValue(84); } endEditCP (gridLens, GeoPLengthsUI32::GeoPropDataFieldMask); //Axes points GeoPositions3fPtr axesPnts = GeoPositions3f::create(); beginEditCP(axesPnts, GeoPositions3f::GeoPropDataFieldMask); { // X-Axis axesPnts->addValue(Pnt3f(0, 0, 0)); axesPnts->addValue(Pnt3f(15, 0, 0)); // Y-Axis axesPnts->addValue(Pnt3f(0, 0, 0)); axesPnts->addValue(Pnt3f(0, 15, 0)); // Z-Axis axesPnts->addValue(Pnt3f(0, 0, 0)); axesPnts->addValue(Pnt3f(0, 0, 15)); } endEditCP (axesPnts, GeoPositions3f::GeoPropDataFieldMask); //Grid points GeoPositions3fPtr gridPnts = GeoPositions3f::create(); beginEditCP(gridPnts, GeoPositions3f::GeoPropDataFieldMask); { float height = 0; gridPnts->addValue(Pnt3f(-10, height, 0)); if(height == 0) gridPnts->addValue(Pnt3f(0, height, 0)); else gridPnts->addValue(Pnt3f(10, height, 0)); gridPnts->addValue(Pnt3f(-10, height, 1)); gridPnts->addValue(Pnt3f(10, height, 1)); gridPnts->addValue(Pnt3f(-10, height, 2)); gridPnts->addValue(Pnt3f(10, height, 2)); gridPnts->addValue(Pnt3f(-10, height, 3)); gridPnts->addValue(Pnt3f(10, height, 3)); gridPnts->addValue(Pnt3f(-10, height, 4)); gridPnts->addValue(Pnt3f(10, height, 4)); gridPnts->addValue(Pnt3f(-10, height, 5)); gridPnts->addValue(Pnt3f(10, height, 5)); gridPnts->addValue(Pnt3f(-10, height, 6)); gridPnts->addValue(Pnt3f(10, height, 6)); gridPnts->addValue(Pnt3f(-10, height, 7)); gridPnts->addValue(Pnt3f(10, height, 7)); gridPnts->addValue(Pnt3f(-10, height, 8)); gridPnts->addValue(Pnt3f(10, height, 8)); gridPnts->addValue(Pnt3f(-10, height, 9)); gridPnts->addValue(Pnt3f(10, height, 9)); gridPnts->addValue(Pnt3f(-10, height, 10)); gridPnts->addValue(Pnt3f(10, height, 10)); gridPnts->addValue(Pnt3f(-10, height, -1)); gridPnts->addValue(Pnt3f(10, height, -1)); gridPnts->addValue(Pnt3f(-10, height, -2)); gridPnts->addValue(Pnt3f(10, height, -2)); gridPnts->addValue(Pnt3f(-10, height, -3)); gridPnts->addValue(Pnt3f(10, height, -3)); gridPnts->addValue(Pnt3f(-10, height, -4)); gridPnts->addValue(Pnt3f(10, height, -4)); gridPnts->addValue(Pnt3f(-10, height, -5)); gridPnts->addValue(Pnt3f(10, height, -5)); gridPnts->addValue(Pnt3f(-10, height, -6)); gridPnts->addValue(Pnt3f(10, height, -6)); gridPnts->addValue(Pnt3f(-10, height, -7)); gridPnts->addValue(Pnt3f(10, height, -7)); gridPnts->addValue(Pnt3f(-10, height, -8)); gridPnts->addValue(Pnt3f(10, height, -8)); gridPnts->addValue(Pnt3f(-10, height, -9)); gridPnts->addValue(Pnt3f(10, height, -9)); gridPnts->addValue(Pnt3f(-10, height, -10)); gridPnts->addValue(Pnt3f(10, height, -10)); gridPnts->addValue(Pnt3f(0, height, -10)); if(height == 0) gridPnts->addValue(Pnt3f(0, height, 0)); else gridPnts->addValue(Pnt3f(0, height, 10)); gridPnts->addValue(Pnt3f(1, height, -10)); gridPnts->addValue(Pnt3f(1, height, 10)); gridPnts->addValue(Pnt3f(2, height, -10)); gridPnts->addValue(Pnt3f(2, height, 10)); gridPnts->addValue(Pnt3f(3, height, -10)); gridPnts->addValue(Pnt3f(3, height, 10)); gridPnts->addValue(Pnt3f(4, height, -10)); gridPnts->addValue(Pnt3f(4, height, 10)); gridPnts->addValue(Pnt3f(5, height, -10)); gridPnts->addValue(Pnt3f(5, height, 10)); gridPnts->addValue(Pnt3f(6, height, -10)); gridPnts->addValue(Pnt3f(6, height, 10)); gridPnts->addValue(Pnt3f(7, height, -10)); gridPnts->addValue(Pnt3f(7, height, 10)); gridPnts->addValue(Pnt3f(8, height, -10)); gridPnts->addValue(Pnt3f(8, height, 10)); gridPnts->addValue(Pnt3f(9, height, -10)); gridPnts->addValue(Pnt3f(9, height, 10)); gridPnts->addValue(Pnt3f(10, height, -10)); gridPnts->addValue(Pnt3f(10, height, 10)); gridPnts->addValue(Pnt3f(-1, height, -10)); gridPnts->addValue(Pnt3f(-1, height, 10)); gridPnts->addValue(Pnt3f(-2, height, -10)); gridPnts->addValue(Pnt3f(-2, height, 10)); gridPnts->addValue(Pnt3f(-3, height, -10)); gridPnts->addValue(Pnt3f(-3, height, 10)); gridPnts->addValue(Pnt3f(-4, height, -10)); gridPnts->addValue(Pnt3f(-4, height, 10)); gridPnts->addValue(Pnt3f(-5, height, -10)); gridPnts->addValue(Pnt3f(-5, height, 10)); gridPnts->addValue(Pnt3f(-6, height, -10)); gridPnts->addValue(Pnt3f(-6, height, 10)); gridPnts->addValue(Pnt3f(-7, height, -10)); gridPnts->addValue(Pnt3f(-7, height, 10)); gridPnts->addValue(Pnt3f(-8, height, -10)); gridPnts->addValue(Pnt3f(-8, height, 10)); gridPnts->addValue(Pnt3f(-9, height, -10)); gridPnts->addValue(Pnt3f(-9, height, 10)); gridPnts->addValue(Pnt3f(-10, height, -10)); gridPnts->addValue(Pnt3f(-10, height, 10)); } endEditCP (gridPnts, GeoPositions3f::GeoPropDataFieldMask); //Axes normals GeoNormals3fPtr axesNorms = GeoNormals3f::create(); beginEditCP(axesNorms, GeoNormals3f::GeoPropDataFieldMask); axesNorms->addValue(Vec3f( 0.0,0.0,1.0)); axesNorms->addValue(Vec3f( 0.0,0.0,1.0)); axesNorms->addValue(Vec3f( 0.0,0.0,1.0)); axesNorms->addValue(Vec3f( 0.0,0.0,1.0)); axesNorms->addValue(Vec3f( 1.0,0.0,0.0)); axesNorms->addValue(Vec3f( 1.0,0.0,0.0)); endEditCP(axesNorms, GeoNormals3f::GeoPropDataFieldMask); //Grid normals GeoNormals3fPtr gridNorms = GeoNormals3f::create(); beginEditCP(gridNorms, GeoNormals3f::GeoPropDataFieldMask); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); gridNorms->addValue(Vec3f( 0.0,0.0,1.0)); endEditCP(gridNorms, GeoNormals3f::GeoPropDataFieldMask); //Axes colors GeoColors3fPtr axesColors = GeoColors3f::create(); beginEditCP(axesColors, GeoColors3f::GeoPropDataFieldMask); //X-Axis = Red axesColors->addValue(Color3f( 1.0,0.0,0.0)); axesColors->addValue(Color3f( 1.0,0.0,0.0)); //Y-Axis = Green axesColors->addValue(Color3f( 0.0,1.0,0.0)); axesColors->addValue(Color3f( 0.0,1.0,0.0)); //Z-Axis = Blue axesColors->addValue(Color3f( 0.0,0.0,1.0)); axesColors->addValue(Color3f( 0.0,0.0,1.0)); endEditCP(axesColors, GeoColors3f::GeoPropDataFieldMask); //Grid gridColors GeoColors3fPtr gridColors = GeoColors3f::create(); beginEditCP(gridColors, GeoColors3f::GeoPropDataFieldMask); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); gridColors->addValue(Color3f( 0.5,0.5,0.5)); endEditCP(gridColors, GeoColors3f::GeoPropDataFieldMask); //Create axes geometry GeometryPtr axesGeo = Geometry::create(); beginEditCP(axesGeo, Geometry::TypesFieldMask | Geometry::LengthsFieldMask | Geometry::PositionsFieldMask | Geometry::NormalsFieldMask | Geometry::MaterialFieldMask | Geometry::ColorsFieldMask); { axesGeo->setTypes (axesType); axesGeo->setLengths (axesLens); axesGeo->setPositions(axesPnts); axesGeo->setNormals(axesNorms); axesGeo->setColors(axesColors); // assign a material to the geometry to make it visible. The details // of materials are defined later. axesGeo->setMaterial(AxesMaterial); } endEditCP (axesGeo, Geometry::TypesFieldMask | Geometry::LengthsFieldMask | Geometry::PositionsFieldMask | Geometry::NormalsFieldMask | Geometry::MaterialFieldMask | Geometry::ColorsFieldMask ); //Create grid geometry GeometryPtr gridGeo = Geometry::create(); beginEditCP(gridGeo, Geometry::TypesFieldMask | Geometry::LengthsFieldMask | Geometry::PositionsFieldMask | Geometry::NormalsFieldMask | Geometry::MaterialFieldMask | Geometry::ColorsFieldMask); { gridGeo->setTypes (gridType); gridGeo->setLengths (gridLens); gridGeo->setPositions(gridPnts); gridGeo->setNormals(gridNorms); gridGeo->setColors(gridColors); // assign a material to the geometry to make it visible. The details // of materials are defined later. gridGeo->setMaterial(AxesMaterial); } endEditCP (gridGeo, Geometry::TypesFieldMask | Geometry::LengthsFieldMask | Geometry::PositionsFieldMask | Geometry::NormalsFieldMask | Geometry::MaterialFieldMask | Geometry::ColorsFieldMask ); //Create unbound geometry Node Axes = osg::Node::create(); beginEditCP(Axes, Node::CoreFieldMask); Axes->setCore(axesGeo); endEditCP(Axes, Node::CoreFieldMask); //Create unbound geometry Node Grid = osg::Node::create(); beginEditCP(Grid, Node::CoreFieldMask); Grid->setCore(gridGeo); endEditCP(Grid, Node::CoreFieldMask); //Import scene from an XML file ChunkMaterialPtr ExampleMaterial; std::vector<SkeletonPtr> SkeletonPtrs; std::vector<SkeletonBlendedGeometryPtr> SkeletonBlendedGeometryPtrs; std::vector<GeometryPtr> GeometryPtrs; FCFileType::FCPtrStore NewContainers; NewContainers = FCFileHandler::the()->read(Path("./Data/21SceneFromMaya.xml")); FCFileType::FCPtrStore::iterator Itor; for(Itor = NewContainers.begin() ; Itor != NewContainers.end() ; ++Itor) { if( (*Itor)->getType() == (ChunkMaterial::getClassType())) { //Set ExampleMaterial to the ChunkMaterial we just read in ExampleMaterial = (ChunkMaterial::Ptr::dcast(*Itor)); } if( (*Itor)->getType() == (Skeleton::getClassType())) { //Add the skeleton we just read in to SkeletonPtrs SkeletonPtrs.push_back(Skeleton::Ptr::dcast(*Itor)); } if( (*Itor)->getType() == (SkeletonBlendedGeometry::getClassType())) { //Add the SkeletonBlendedGeometry we just read in to SkeletonBlendedGeometryPtrs SkeletonBlendedGeometryPtrs.push_back(SkeletonBlendedGeometry::Ptr::dcast(*Itor)); } if( (*Itor)->getType().isDerivedFrom(SkeletonAnimation::getClassType())) { //Set TheSkeletonAnimation to the Animation we just read in TheSkeletonAnimation = (Animation::Ptr::dcast(*Itor)); } if( (*Itor)->getType() == (Geometry::getClassType())) { //Add the Geometry we just read in to GeometryPtrs GeometryPtrs.push_back(Geometry::Ptr::dcast(*Itor)); } } //Create unbound geometry Node (to show the mesh in its bind pose) for (int i(0); i < GeometryPtrs.size(); ++i) { NodePtr UnboundGeometry = Node::create(); beginEditCP(UnboundGeometry, Node::CoreFieldMask | Node::TravMaskFieldMask); UnboundGeometry->setCore(GeometryPtrs[i]); UnboundGeometry->setTravMask(0); endEditCP(UnboundGeometry, Node::CoreFieldMask | Node::TravMaskFieldMask); UnboundGeometries.push_back(UnboundGeometry); } //Create skeleton nodes for (int i(0); i < SkeletonPtrs.size(); ++i) { //SkeletonDrawer SkeletonDrawablePtr ExampleSkeletonDrawable = osg::SkeletonDrawable::create(); beginEditCP(ExampleSkeletonDrawable, SkeletonDrawable::SkeletonFieldMask | SkeletonDrawable::MaterialFieldMask | SkeletonDrawable::DrawPoseFieldMask | SkeletonDrawable::PoseColorFieldMask | SkeletonDrawable::DrawBindPoseFieldMask | SkeletonDrawable::BindPoseColorFieldMask); ExampleSkeletonDrawable->setSkeleton(SkeletonPtrs[i]); ExampleSkeletonDrawable->setMaterial(AxesMaterial); ExampleSkeletonDrawable->setDrawPose(true); //By default we draw the current skeleton ExampleSkeletonDrawable->setPoseColor(Color4f(1.0, 0.0, 1.0, 1.0)); //Set color of current skeleton ExampleSkeletonDrawable->setDrawBindPose(false); //By default we don't draw the bind pose skeleton ExampleSkeletonDrawable->setBindPoseColor(Color4f(1.0, 1.0, 0.0, 1.0)); //Set color of bind pose skeleton endEditCP(ExampleSkeletonDrawable, SkeletonDrawable::SkeletonFieldMask | SkeletonDrawable::MaterialFieldMask | SkeletonDrawable::DrawPoseFieldMask | SkeletonDrawable::PoseColorFieldMask | SkeletonDrawable::DrawBindPoseFieldMask | SkeletonDrawable::BindPoseColorFieldMask); //Skeleton Node NodePtr SkeletonNode = osg::Node::create(); beginEditCP(SkeletonNode, Node::CoreFieldMask); SkeletonNode->setCore(ExampleSkeletonDrawable); endEditCP(SkeletonNode, Node::CoreFieldMask); SkeletonNodes.push_back(SkeletonNode); } //Create skeleton blended geometry nodes for (int i(0); i < SkeletonBlendedGeometryPtrs.size(); ++i) { NodePtr MeshNode = osg::Node::create(); beginEditCP(MeshNode, Node::CoreFieldMask); MeshNode->setCore(SkeletonBlendedGeometryPtrs[i]); endEditCP(MeshNode, Node::CoreFieldMask); MeshNodes.push_back(MeshNode); } //Create Animation Advancer TheAnimationAdvancer = osg::ElapsedTimeAnimationAdvancer::create(); osg::beginEditCP(TheAnimationAdvancer); osg::ElapsedTimeAnimationAdvancer::Ptr::dcast(TheAnimationAdvancer)->setStartTime( 0.0 ); osg::beginEditCP(TheAnimationAdvancer); //Add nodes to scene NodePtr scene = osg::Node::create(); beginEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask); scene->setCore(osg::Group::create()); scene->addChild(Axes); scene->addChild(Grid); //Add all imported skeletons to scene for (int i(0); i < SkeletonNodes.size(); ++i) { scene->addChild(SkeletonNodes[i]); } //Add all imported geometries to scene for (int i(0); i < UnboundGeometries.size(); ++i) { scene->addChild(UnboundGeometries[i]); } //Add all imported SkeletonBlendedGeometries to scene for (int i(0); i < MeshNodes.size(); ++i) { scene->addChild(MeshNodes[i]); } endEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask); mgr->setRoot(scene); //By default the animation is not paused animationPaused = false; // Show the whole Scene mgr->showAll(); TheAnimationAdvancer->start(); //Show window Vec2f WinSize(TutorialWindowEventProducer->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindowEventProducer->getDesktopSize() - WinSize) *0.5); TutorialWindowEventProducer->openWindow(WinPos, WinSize, "21LoadXMLSceneFromMaya"); //Enter main Loop TutorialWindowEventProducer->mainLoop(); osgExit(); return 0; }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); // Set up Window TutorialWindowEventProducer = createDefaultWindowEventProducer(); WindowPtr MainWindow = TutorialWindowEventProducer->initWindow(); TutorialWindowEventProducer->setDisplayCallback(display); TutorialWindowEventProducer->setReshapeCallback(reshape); TutorialKeyListener TheKeyListener; TutorialWindowEventProducer->addKeyListener(&TheKeyListener); TutorialUpdateListener TheUpdateListener; TutorialWindowEventProducer->addUpdateListener(&TheUpdateListener); // Create the SceneManager mgr = new SceneManager; // Tell the Manager what to manage mgr->setWindow(MainWindow); // Make Torus Node (creates Torus in background of scene) NodePtr TorusGeometryNode = makeTorus(.5, 2, 16, 16); // Make Torus Node (creates Torus in background of scene) NodePtr BoxGeometryNode = makeBox(0.5,0.5,0.5,50,2,2); //Set the Camera Beacon Node Matrix Offset; //Offset.setTranslate(0.0f,2.5f,6.0f); Offset.setTranslate(0.0f,0.0,6.0f); CameraBeaconTransform = Transform::create(); beginEditCP(CameraBeaconTransform, Transform::MatrixFieldMask); CameraBeaconTransform->setMatrix(Offset); endEditCP(CameraBeaconTransform, Transform::MatrixFieldMask); NodePtr CameraBeaconNode = Node::create(); beginEditCP(CameraBeaconNode, Node::CoreFieldMask | Node::ChildrenFieldMask); CameraBeaconNode->setCore(CameraBeaconTransform); endEditCP(CameraBeaconNode, Node::CoreFieldMask | Node::ChildrenFieldMask); //Set the Box Transform Node BoxTransform = Transform::create(); NodePtr BoxNode = Node::create(); beginEditCP(BoxNode, Node::CoreFieldMask | Node::ChildrenFieldMask); BoxNode->setCore(BoxTransform); BoxNode->addChild(BoxGeometryNode); BoxNode->addChild(CameraBeaconNode); endEditCP(BoxNode, Node::CoreFieldMask | Node::ChildrenFieldMask); // Make Main Scene Node and add the Torus NodePtr scene = osg::Node::create(); beginEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask); scene->setCore(osg::Group::create()); scene->addChild(TorusGeometryNode); scene->addChild(BoxNode); endEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask); //Set the Root node to the Scene Manager mgr->setRoot(scene); //The perspective decoratee camera CameraPtr PCamera = PerspectiveCamera::create(); beginEditCP(PerspectiveCameraPtr::dcast(PCamera)); PerspectiveCameraPtr::dcast(PCamera)->setBeacon(CameraBeaconNode); PerspectiveCameraPtr::dcast(PCamera)->setFov (deg2rad(60.f)); PerspectiveCameraPtr::dcast(PCamera)->setNear (0.1f); PerspectiveCameraPtr::dcast(PCamera)->setFar (10000.f); endEditCP(PerspectiveCameraPtr::dcast(PCamera)); //Create the Rubber band Camera Vec3f PositionCoefficients(0.1,1.5,1.5); Vec3f OrientationCoefficients(0.1,2.5,2.5); RubberCamera = RubberBandCamera::create(); beginEditCP(RubberCamera, RubberBandCamera::DecorateeFieldMask | RubberBandCamera::BeaconFieldMask | RubberBandCamera::PositionCoefficientsFieldMask | RubberBandCamera::OrientationCoefficientsFieldMask); RubberCamera->setDecoratee(PCamera); RubberCamera->setBeacon(CameraBeaconNode); RubberCamera->setPositionCoefficients(PositionCoefficients); RubberCamera->setOrientationCoefficients(OrientationCoefficients); endEditCP(RubberCamera, RubberBandCamera::DecorateeFieldMask | RubberBandCamera::BeaconFieldMask | RubberBandCamera::PositionCoefficientsFieldMask | RubberBandCamera::OrientationCoefficientsFieldMask); RubberCamera->setToBeacon(); mgr->setCamera(RubberCamera); // Show the whole Scene //mgr->showAll(); //Open Window Vec2f WinSize(TutorialWindowEventProducer->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindowEventProducer->getDesktopSize() - WinSize) *0.5); TutorialWindowEventProducer->openWindow(WinPos, WinSize, "01RubberBandCamera"); //Enter main Loop TutorialWindowEventProducer->mainLoop(); osgExit(); return 0; }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); // Set up Window TutorialWindowEventProducer = createDefaultWindowEventProducer(); WindowPtr MainWindow = TutorialWindowEventProducer->initWindow(); TutorialWindowEventProducer->setDisplayCallback(display); TutorialWindowEventProducer->setReshapeCallback(reshape); TutorialKeyListener TheKeyListener; TutorialWindowEventProducer->addKeyListener(&TheKeyListener); TutorialUpdateListener TheTutorialUpdateListener; TutorialWindowEventProducer->addUpdateListener(&TheTutorialUpdateListener); //Create Start and stop buttons for the caption ButtonPtr StartButton = osg::Button::create(); ButtonPtr StopButton = osg::Button::create(); ButtonPtr PauseButton = osg::Button::create(); UIFontPtr ButtonFont = osg::UIFont::create(); beginEditCP(ButtonFont, UIFont::SizeFieldMask); ButtonFont->setSize(16); endEditCP(ButtonFont, UIFont::SizeFieldMask); beginEditCP(StartButton, Button::MinSizeFieldMask | Button::MaxSizeFieldMask | Button::PreferredSizeFieldMask | Button::ToolTipTextFieldMask | Button::TextFieldMask | Button::FontFieldMask | Button::TextColorFieldMask | Button::RolloverTextColorFieldMask | Button::ActiveTextColorFieldMask | Button::AlignmentFieldMask); StartButton->setMinSize(Vec2f(50, 25)); StartButton->setMaxSize(Vec2f(200, 100)); StartButton->setPreferredSize(Vec2f(100, 50)); StartButton->setToolTipText("This will start playing the caption!"); StartButton->setText("START"); StartButton->setFont(ButtonFont); StartButton->setTextColor(Color4f(1.0, 0.0, 0.0, 1.0)); StartButton->setRolloverTextColor(Color4f(1.0, 0.0, 1.0, 1.0)); StartButton->setActiveTextColor(Color4f(1.0, 0.0, 0.0, 1.0)); StartButton->setAlignment(Vec2f(0.25,0.5)); endEditCP(StartButton, Button::MinSizeFieldMask | Button::MaxSizeFieldMask | Button::PreferredSizeFieldMask | Button::ToolTipTextFieldMask | Button::TextFieldMask | Button::FontFieldMask | Button::TextColorFieldMask | Button::RolloverTextColorFieldMask | Button::ActiveTextColorFieldMask | Button::AlignmentFieldMask); beginEditCP(StopButton, Button::MinSizeFieldMask | Button::MaxSizeFieldMask | Button::PreferredSizeFieldMask | Button::ToolTipTextFieldMask | Button::TextFieldMask | Button::FontFieldMask | Button::TextColorFieldMask | Button::RolloverTextColorFieldMask | Button::ActiveTextColorFieldMask | Button::AlignmentFieldMask); StopButton->setMinSize(Vec2f(50, 25)); StopButton->setMaxSize(Vec2f(200, 100)); StopButton->setPreferredSize(Vec2f(100, 50)); StopButton->setToolTipText("This will stop the caption and reset it!"); StopButton->setText("STOP"); StopButton->setFont(ButtonFont); StopButton->setTextColor(Color4f(1.0, 0.0, 0.0, 1.0)); StopButton->setRolloverTextColor(Color4f(1.0, 0.0, 1.0, 1.0)); StopButton->setActiveTextColor(Color4f(1.0, 0.0, 0.0, 1.0)); StopButton->setAlignment(Vec2f(0.75,0.5)); endEditCP(StopButton, Button::MinSizeFieldMask | Button::MaxSizeFieldMask | Button::PreferredSizeFieldMask | Button::ToolTipTextFieldMask | Button::TextFieldMask | Button::FontFieldMask | Button::TextColorFieldMask | Button::RolloverTextColorFieldMask | Button::ActiveTextColorFieldMask | Button::AlignmentFieldMask); beginEditCP(PauseButton, Button::MinSizeFieldMask | Button::MaxSizeFieldMask | Button::PreferredSizeFieldMask | Button::ToolTipTextFieldMask | Button::TextFieldMask | Button::FontFieldMask | Button::TextColorFieldMask | Button::RolloverTextColorFieldMask | Button::ActiveTextColorFieldMask | Button::AlignmentFieldMask); PauseButton->setMinSize(Vec2f(50, 25)); PauseButton->setMaxSize(Vec2f(200, 100)); PauseButton->setPreferredSize(Vec2f(100, 50)); PauseButton->setToolTipText("This will Pause the caption!"); PauseButton->setText("PAUSE"); PauseButton->setFont(ButtonFont); PauseButton->setTextColor(Color4f(1.0, 0.0, 0.0, 1.0)); PauseButton->setRolloverTextColor(Color4f(1.0, 0.0, 1.0, 1.0)); PauseButton->setActiveTextColor(Color4f(1.0, 0.0, 0.0, 1.0)); PauseButton->setAlignment(Vec2f(0.5,0.5)); endEditCP(PauseButton, Button::MinSizeFieldMask | Button::MaxSizeFieldMask | Button::PreferredSizeFieldMask | Button::ToolTipTextFieldMask | Button::TextFieldMask | Button::FontFieldMask | Button::TextColorFieldMask | Button::RolloverTextColorFieldMask | Button::ActiveTextColorFieldMask | Button::AlignmentFieldMask); StartButtonActionListener TheStartButtonActionListener; StartButton->addActionListener(&TheStartButtonActionListener); StopButtonActionListener TheStopButtonActionListener; StopButton->addActionListener(&TheStopButtonActionListener); PauseButtonActionListener ThePauseButtonActionListener; PauseButton->addActionListener(&ThePauseButtonActionListener); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(MainWindow); // Make Torus Node (creates Torus in background of scene) NodePtr TorusGeometryNode = makeTorus(.5, 2, 16, 16); // Make Main Scene Node and add the Torus scene = osg::Node::create(); beginEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask); scene->setCore(osg::Group::create()); scene->addChild(TorusGeometryNode); endEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask); // Create the Graphics GraphicsPtr TutorialGraphics = osg::Graphics2D::create(); // Initialize the LookAndFeelManager to enable default settings LookAndFeelManager::the()->getLookAndFeel()->init(); LayoutPtr MainInternalWindowLayout = osg::FlowLayout::create(); PanelPtr CaptionContainer = osg::Panel::create(); beginEditCP(CaptionContainer, Panel::PreferredSizeFieldMask | Panel::LayoutFieldMask); CaptionContainer->setPreferredSize(Pnt2f(250.0,30.0)); CaptionContainer->setLayout(MainInternalWindowLayout); endEditCP(CaptionContainer, Panel::PreferredSizeFieldMask | Panel::LayoutFieldMask); //Initialize the Sound Manager SoundManager::the()->attachUpdateProducer(TutorialWindowEventProducer); TutorialSound = SoundManager::the()->createSound(); beginEditCP(TutorialSound, Sound::FileFieldMask | Sound::VolumeFieldMask | Sound::StreamingFieldMask | Sound::LoopingFieldMask); TutorialSound->setFile(Path("./Data/captionSoundFile.ogg")); TutorialSound->setVolume(1.0); TutorialSound->setStreaming(true); TutorialSound->setLooping(0); endEditCP(TutorialSound, Sound::FileFieldMask | Sound::VolumeFieldMask | Sound::StreamingFieldMask | Sound::LoopingFieldMask); // Create the Caption TutorialCaption = osg::Caption::create(); //Add the segments of text to be displayed TutorialCaption->captionSegment("Listeners can be used for a variety",1.7,3.4); TutorialCaption->captionSegment("of different applications.",3.4,4.7); TutorialCaption->captionSegment("In this tutorial we will",5.0,6.35); TutorialCaption->captionSegment("simply be changing the background though.",6.35,8.0); TutorialCaption->captionSegment("First we will change the",8.8,10.2); TutorialCaption->captionSegment("torus on screen to a sphere.",10.2,11.75); TutorialCaption->captionSegment("By timing things correctly we can make",12.7,14.6); TutorialCaption->captionSegment("the changes right as the word is spoken.",14.6,16.75); TutorialCaption->captionSegment("Such as changing the sphere to a cube",17.3,20.0); TutorialCaption->captionSegment("but personally I would prefer",20.33,21.65); TutorialCaption->captionSegment("the background to be blank.",21.65,22.8); TutorialCaption->captionSegment("Much better!",23.8,25.0); //Add the tutorial Caption Listener to the Caption that was set up for the tutorial TutorialCaptionListener TheCaptionListener; TutorialCaption->addCaptionListener(&TheCaptionListener); //Create the Caption component Generator TutorialCapGen = DefaultCaptionComponentGenerator::create(); TutorialCaption->attachWindowEventProducer(TutorialWindowEventProducer); beginEditCP(TutorialCaption, Caption::ParentContainerFieldMask | Caption::ComponentGeneratorFieldMask | Caption::CaptionDialogSoundFieldMask); TutorialCaption->setParentContainer(CaptionContainer); TutorialCaption->setComponentGenerator(TutorialCapGen); TutorialCaption->setCaptionDialogSound(TutorialSound); endEditCP(TutorialCaption, Caption::ParentContainerFieldMask | Caption::ComponentGeneratorFieldMask | Caption::CaptionDialogSoundFieldMask); //Create and modify the Label prototype that will be used for the caption LabelPtr LabelPrototype = Label::create(); LabelPrototype->setAlignment(Pnt2f(0.5f,0.5f)); LabelPrototype->setPreferredSize(Pnt2f(250.0,30.0)); //Add the prototype to the Generator for use beginEditCP(TutorialCapGen, DefaultCaptionComponentGenerator::CaptionSegmentPrototypeFieldMask); TutorialCapGen->setCaptionSegmentPrototype(LabelPrototype); endEditCP(TutorialCapGen, DefaultCaptionComponentGenerator::CaptionSegmentPrototypeFieldMask); // Create The Main InternalWindow // Create Background to be used with the Main InternalWindow ColorLayerPtr MainInternalWindowBackground = osg::ColorLayer::create(); MainInternalWindow = osg::InternalWindow::create(); beginEditCP(MainInternalWindowBackground, ColorLayer::ColorFieldMask); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); endEditCP(MainInternalWindowBackground, ColorLayer::ColorFieldMask); beginEditCP(MainInternalWindow, InternalWindow::ChildrenFieldMask | InternalWindow::LayoutFieldMask | InternalWindow::BackgroundsFieldMask | InternalWindow::AlignmentInDrawingSurfaceFieldMask | InternalWindow::ScalingInDrawingSurfaceFieldMask | InternalWindow::DrawTitlebarFieldMask | InternalWindow::ResizableFieldMask); 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); MainInternalWindow->getChildren().push_back(CaptionContainer); MainInternalWindow->getChildren().push_back(StartButton); MainInternalWindow->getChildren().push_back(StopButton); MainInternalWindow->getChildren().push_back(PauseButton); endEditCP(MainInternalWindow, InternalWindow::ChildrenFieldMask | InternalWindow::LayoutFieldMask | InternalWindow::BackgroundsFieldMask | InternalWindow::AlignmentInDrawingSurfaceFieldMask | InternalWindow::ScalingInDrawingSurfaceFieldMask | InternalWindow::DrawTitlebarFieldMask | InternalWindow::ResizableFieldMask); // Create the Drawing Surface UIDrawingSurfacePtr TutorialDrawingSurface = UIDrawingSurface::create(); beginEditCP(TutorialDrawingSurface, UIDrawingSurface::GraphicsFieldMask | UIDrawingSurface::EventProducerFieldMask); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindowEventProducer); endEditCP(TutorialDrawingSurface, UIDrawingSurface::GraphicsFieldMask | UIDrawingSurface::EventProducerFieldMask); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundPtr TutorialUIForeground = osg::UIForeground::create(); beginEditCP(TutorialUIForeground, UIForeground::DrawingSurfaceFieldMask); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); endEditCP(TutorialUIForeground, UIForeground::DrawingSurfaceFieldMask); mgr->setRoot(scene); // Add the UI Foreground Object to the Scene ViewportPtr TutorialViewport = mgr->getWindow()->getPort(0); beginEditCP(TutorialViewport, Viewport::ForegroundsFieldMask); TutorialViewport->getForegrounds().push_back(TutorialUIForeground); beginEditCP(TutorialViewport, Viewport::ForegroundsFieldMask); // Show the whole Scene mgr->showAll(); SoundManager::the()->setCamera(mgr->getCamera()); Vec2f WinSize(TutorialWindowEventProducer->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindowEventProducer->getDesktopSize() - WinSize) *0.5); TutorialWindowEventProducer->openWindow(WinPos, WinSize, "05Caption"); //Enter main Loop TutorialWindowEventProducer->mainLoop(); osgExit(); return 0; }
// Initialize OpenSG and set up the scene int main(int argc, char **argv) { // OSG init osgInit(argc,argv); // Set up Window TutorialWindowEventProducer = createDefaultWindowEventProducer(); WindowPtr MainWindow = TutorialWindowEventProducer->initWindow(); TutorialWindowEventProducer->setDisplayCallback(display); TutorialWindowEventProducer->setReshapeCallback(reshape); //Add Window Listener TutorialKeyListener TheKeyListener; TutorialWindowEventProducer->addKeyListener(&TheKeyListener); TutorialMouseListener TheTutorialMouseListener; TutorialMouseMotionListener TheTutorialMouseMotionListener; TutorialWindowEventProducer->addMouseListener(&TheTutorialMouseListener); TutorialWindowEventProducer->addMouseMotionListener(&TheTutorialMouseMotionListener); TutorialUpdateListener TheTutorialUpdateListener; TutorialWindowEventProducer->addUpdateListener(&TheTutorialUpdateListener); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(MainWindow); //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 << "SHIFT-B Show/Hide the bind pose mesh" << std::endl; std::cout << "P Show/Hide the current pose skeleton" << std::endl; std::cout << "SHIFT-P Show/Hide the current pose mesh" << std::endl; std::cout << "O Toggle override status of TheSecondAnimation" << std::endl; std::cout << "CTRL-Q Exit\n\n" << std::endl; //Import scene from XML ChunkMaterialPtr ExampleMaterial; std::vector<SkeletonPtr> SkeletonPtrs; std::vector<SkeletonBlendedGeometryPtr> SkeletonBlendedGeometryPtrs; std::vector<GeometryPtr> GeometryPtrs; //Skeleton materaial LineChunkPtr SkelLineChunk = LineChunk::create(); beginEditCP(SkelLineChunk); SkelLineChunk->setWidth(0.0f); SkelLineChunk->setSmooth(true); endEditCP(SkelLineChunk); ChunkMaterialPtr SkelMaterial = ChunkMaterial::create(); beginEditCP(SkelMaterial, ChunkMaterial::ChunksFieldMask); SkelMaterial->addChunk(SkelLineChunk); endEditCP(SkelMaterial, ChunkMaterial::ChunksFieldMask); //LOAD FIRST ANIMATION FCFileType::FCPtrStore NewContainers; NewContainers = FCFileHandler::the()->read(BoostPath("./Data/23WalkingAnimation.xml")); FCFileType::FCPtrStore::iterator Itor; for(Itor = NewContainers.begin() ; Itor != NewContainers.end() ; ++Itor) { if( (*Itor)->getType() == (ChunkMaterial::getClassType())) { //Set ExampleMaterial to the ChunkMaterial we just read in ExampleMaterial = (ChunkMaterial::Ptr::dcast(*Itor)); } if( (*Itor)->getType() == (Skeleton::getClassType())) { //Add the Skeleton we just read in to SkeletonPtrs SkeletonPtrs.push_back(Skeleton::Ptr::dcast(*Itor)); } if( (*Itor)->getType() == (SkeletonBlendedGeometry::getClassType())) { //Add the SkeletonBlendedGeometry we just read in to SkeletonBlendedGeometryPtrs SkeletonBlendedGeometryPtrs.push_back(SkeletonBlendedGeometry::Ptr::dcast(*Itor)); } if( (*Itor)->getType().isDerivedFrom(SkeletonAnimation::getClassType())) { //Set TheWalkingAnimation to the SkeletonAnimation we just read in TheWalkingAnimation = (SkeletonAnimation::Ptr::dcast(*Itor)); } if( (*Itor)->getType() == (Geometry::getClassType())) { //Add the Geometry we just read in to GeometryPtrs GeometryPtrs.push_back(Geometry::Ptr::dcast(*Itor)); } } //LOAD SECOND ANIMATION NewContainers = FCFileHandler::the()->read(BoostPath("./Data/23SamAnimation.xml")); for(Itor = NewContainers.begin() ; Itor != NewContainers.end() ; ++Itor) { //Import only the skeletonAnimation from the second XML file; we've already imported the skeleton and the geometry if( (*Itor)->getType().isDerivedFrom(SkeletonAnimation::getClassType())) { TheSecondAnimation = (SkeletonAnimation::Ptr::dcast(*Itor)); } } //Blend the two animations TheSkeletonBlendedAnimation = SkeletonBlendedAnimation::create(); beginEditCP(TheSkeletonBlendedAnimation); TheSkeletonBlendedAnimation->addAnimationBlending(TheWalkingAnimation, BlendWalking, false); TheSkeletonBlendedAnimation->addAnimationBlending(TheSecondAnimation, BlendTouchScreen, false); endEditCP(TheSkeletonBlendedAnimation); //Create unbound geometry Node (to show the mesh in its bind pose) for (int i(0); i < GeometryPtrs.size(); ++i) { NodePtr UnboundGeometry = Node::create(); beginEditCP(UnboundGeometry, Node::CoreFieldMask | Node::TravMaskFieldMask); UnboundGeometry->setCore(GeometryPtrs[i]); UnboundGeometry->setTravMask(0); //By default, we don't show the mesh in its bind pose. endEditCP(UnboundGeometry, Node::CoreFieldMask | Node::TravMaskFieldMask); UnboundGeometries.push_back(UnboundGeometry); } //Create skeleton nodes for (int i(0); i < SkeletonPtrs.size(); ++i) { //SkeletonDrawer SkeletonDrawablePtr ExampleSkeletonDrawable = osg::SkeletonDrawable::create(); beginEditCP(ExampleSkeletonDrawable, SkeletonDrawable::SkeletonFieldMask | SkeletonDrawable::MaterialFieldMask | SkeletonDrawable::DrawPoseFieldMask | SkeletonDrawable::PoseColorFieldMask | SkeletonDrawable::DrawBindPoseFieldMask | SkeletonDrawable::BindPoseColorFieldMask); ExampleSkeletonDrawable->setSkeleton(SkeletonPtrs[i]); ExampleSkeletonDrawable->setMaterial(SkelMaterial); ExampleSkeletonDrawable->setDrawPose(true); //By default we draw the current skeleton ExampleSkeletonDrawable->setPoseColor(Color4f(1.0, 0.0, 1.0, 1.0)); //Set color of current skeleton ExampleSkeletonDrawable->setDrawBindPose(false); //By default we don't draw the bind pose skeleton ExampleSkeletonDrawable->setBindPoseColor(Color4f(1.0, 1.0, 0.0, 1.0)); //Set color of bind pose skeleton endEditCP(ExampleSkeletonDrawable, SkeletonDrawable::SkeletonFieldMask | SkeletonDrawable::MaterialFieldMask | SkeletonDrawable::DrawPoseFieldMask | SkeletonDrawable::PoseColorFieldMask | SkeletonDrawable::DrawBindPoseFieldMask | SkeletonDrawable::BindPoseColorFieldMask); //Skeleton Node NodePtr SkeletonNode = osg::Node::create(); beginEditCP(SkeletonNode, Node::CoreFieldMask); SkeletonNode->setCore(ExampleSkeletonDrawable); endEditCP(SkeletonNode, Node::CoreFieldMask); SkeletonNodes.push_back(SkeletonNode); } //Create skeleton blended geometry nodes for (int i(0); i < SkeletonBlendedGeometryPtrs.size(); ++i) { NodePtr MeshNode = osg::Node::create(); beginEditCP(MeshNode, Node::CoreFieldMask); MeshNode->setCore(SkeletonBlendedGeometryPtrs[i]); endEditCP(MeshNode, Node::CoreFieldMask); MeshNodes.push_back(MeshNode); } //Setup scene NodePtr EmptyScene = osg::Node::create(); beginEditCP(EmptyScene, Node::CoreFieldMask); EmptyScene->setCore(Group::create()); endEditCP (EmptyScene, Node::CoreFieldMask); mgr->setRoot(EmptyScene); //User Interface // Create the Graphics GraphicsPtr TutorialGraphics = osg::Graphics2D::create(); // Initialize the LookAndFeelManager to enable default settings LookAndFeelManager::the()->getLookAndFeel()->init(); // Create the DefaultBoundedRangeModelPtr and // set its values DefaultBoundedRangeModelPtr UpperAnimationSliderRangeModel = DefaultBoundedRangeModel::create(); UpperAnimationSliderRangeModel->setMinimum(0); UpperAnimationSliderRangeModel->setMaximum(100); UpperAnimationSliderRangeModel->setValue(BlendWalking * 100); UpperAnimationSliderRangeModel->setExtent(0); //Create the upper animation blend amount slider LabelPtr TempLabel; SliderPtr UpperAnimationSlider = Slider::create(); beginEditCP(UpperAnimationSlider, Slider::LabelMapFieldMask | Slider::PreferredSizeFieldMask | Slider::MajorTickSpacingFieldMask | Slider::MinorTickSpacingFieldMask | Slider::SnapToTicksFieldMask | Slider::DrawLabelsFieldMask | Slider::RangeModelFieldMask); //Label the slider TempLabel = Label::Ptr::dcast(UpperAnimationSlider->getLabelPrototype()->shallowCopy()); beginEditCP(TempLabel, Label::TextFieldMask); TempLabel->setText("0.0"); endEditCP(TempLabel, Label::TextFieldMask); UpperAnimationSlider->getLabelMap()[0] = TempLabel; TempLabel = Label::Ptr::dcast(UpperAnimationSlider->getLabelPrototype()->shallowCopy()); beginEditCP(TempLabel, Label::TextFieldMask); TempLabel->setText("1.0"); endEditCP(TempLabel, Label::TextFieldMask); UpperAnimationSlider->getLabelMap()[100] = TempLabel; //Customize the slider UpperAnimationSlider->setPreferredSize(Vec2f(100, 300)); UpperAnimationSlider->setSnapToTicks(false); UpperAnimationSlider->setMajorTickSpacing(10); UpperAnimationSlider->setMinorTickSpacing(5); UpperAnimationSlider->setOrientation(Slider::VERTICAL_ORIENTATION); UpperAnimationSlider->setInverted(true); UpperAnimationSlider->setDrawLabels(true); UpperAnimationSlider->setRangeModel(UpperAnimationSliderRangeModel); endEditCP(UpperAnimationSlider, Slider::LabelMapFieldMask | Slider::PreferredSizeFieldMask | Slider::MajorTickSpacingFieldMask | Slider::MinorTickSpacingFieldMask | Slider::SnapToTicksFieldMask | Slider::DrawLabelsFieldMask | Slider::RangeModelFieldMask); DefaultBoundedRangeModelPtr LowerAnimationSliderRangeModel = DefaultBoundedRangeModel::create(); LowerAnimationSliderRangeModel->setMinimum(0); LowerAnimationSliderRangeModel->setMaximum(100); LowerAnimationSliderRangeModel->setValue(BlendTouchScreen * 100); LowerAnimationSliderRangeModel->setExtent(0); //Create the lower animation blend amount slider SliderPtr LowerAnimationSlider = Slider::create(); beginEditCP(LowerAnimationSlider, Slider::LabelMapFieldMask | Slider::PreferredSizeFieldMask | Slider::MajorTickSpacingFieldMask | Slider::MinorTickSpacingFieldMask | Slider::SnapToTicksFieldMask | Slider::DrawLabelsFieldMask | Slider::RangeModelFieldMask); //Label the slider TempLabel = Label::Ptr::dcast(LowerAnimationSlider->getLabelPrototype()->shallowCopy()); beginEditCP(TempLabel, Label::TextFieldMask); TempLabel->setText("0.0"); endEditCP(TempLabel, Label::TextFieldMask); LowerAnimationSlider->getLabelMap()[0] = TempLabel; TempLabel = Label::Ptr::dcast(LowerAnimationSlider->getLabelPrototype()->shallowCopy()); beginEditCP(TempLabel, Label::TextFieldMask); TempLabel->setText("1.0"); endEditCP(TempLabel, Label::TextFieldMask); LowerAnimationSlider->getLabelMap()[100] = TempLabel; //Customize the slider LowerAnimationSlider->setPreferredSize(Vec2f(100, 300)); LowerAnimationSlider->setSnapToTicks(false); LowerAnimationSlider->setMajorTickSpacing(10); LowerAnimationSlider->setMinorTickSpacing(5); LowerAnimationSlider->setOrientation(Slider::VERTICAL_ORIENTATION); LowerAnimationSlider->setInverted(true); LowerAnimationSlider->setDrawLabels(true); LowerAnimationSlider->setRangeModel(LowerAnimationSliderRangeModel); endEditCP(LowerAnimationSlider, Slider::LabelMapFieldMask | Slider::PreferredSizeFieldMask | Slider::MajorTickSpacingFieldMask | Slider::MinorTickSpacingFieldMask | Slider::SnapToTicksFieldMask | Slider::DrawLabelsFieldMask | Slider::RangeModelFieldMask); // Create Background to be used with the MainFrame ColorLayerPtr MainFrameBackground = osg::ColorLayer::create(); beginEditCP(MainFrameBackground, ColorLayer::ColorFieldMask); MainFrameBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); endEditCP(MainFrameBackground, ColorLayer::ColorFieldMask); // Create The Main InternalWindow // Create Background to be used with the Main InternalWindow ColorLayerPtr MainInternalWindowBackground = osg::ColorLayer::create(); beginEditCP(MainInternalWindowBackground, ColorLayer::ColorFieldMask); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); endEditCP(MainInternalWindowBackground, ColorLayer::ColorFieldMask); LayoutPtr MainInternalWindowLayout = osg::FlowLayout::create(); //GL Viewport ComponentPtr TheGLViewport = createGLPanel(); InternalWindowPtr MainInternalWindow = osg::InternalWindow::create(); beginEditCP(MainInternalWindow, InternalWindow::ChildrenFieldMask | InternalWindow::LayoutFieldMask | InternalWindow::BackgroundsFieldMask | InternalWindow::AlignmentInDrawingSurfaceFieldMask | InternalWindow::ScalingInDrawingSurfaceFieldMask | InternalWindow::DrawTitlebarFieldMask | InternalWindow::ResizableFieldMask); MainInternalWindow->getChildren().push_back(UpperAnimationSlider); MainInternalWindow->getChildren().push_back(LowerAnimationSlider); MainInternalWindow->getChildren().push_back(TheGLViewport); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(1.0f,1.0f)); MainInternalWindow->setDrawTitlebar(false); MainInternalWindow->setResizable(false); endEditCP(MainInternalWindow, InternalWindow::ChildrenFieldMask | InternalWindow::LayoutFieldMask | InternalWindow::BackgroundsFieldMask | InternalWindow::AlignmentInDrawingSurfaceFieldMask | InternalWindow::ScalingInDrawingSurfaceFieldMask | InternalWindow::DrawTitlebarFieldMask | InternalWindow::ResizableFieldMask); // Create the Drawing Surface UIDrawingSurfacePtr TutorialDrawingSurface = UIDrawingSurface::create(); beginEditCP(TutorialDrawingSurface, UIDrawingSurface::GraphicsFieldMask | UIDrawingSurface::EventProducerFieldMask); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindowEventProducer); endEditCP(TutorialDrawingSurface, UIDrawingSurface::GraphicsFieldMask | UIDrawingSurface::EventProducerFieldMask); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundPtr TutorialUIForeground = osg::UIForeground::create(); beginEditCP(TutorialUIForeground, UIForeground::DrawingSurfaceFieldMask); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); endEditCP(TutorialUIForeground, UIForeground::DrawingSurfaceFieldMask); ViewportPtr TutorialViewport = mgr->getWindow()->getPort(0); beginEditCP(TutorialViewport, Viewport::ForegroundsFieldMask); TutorialViewport->getForegrounds().push_back(TutorialUIForeground); beginEditCP(TutorialViewport, Viewport::ForegroundsFieldMask); //Attach the Slider Listeners BlendAmountSliderChangeListener UpperAnimationSliderListener(TheSkeletonBlendedAnimation, 0, UpperAnimationSlider); UpperAnimationSlider->addChangeListener(&UpperAnimationSliderListener); BlendAmountSliderChangeListener LowerAnimationSliderListener(TheSkeletonBlendedAnimation, 1, LowerAnimationSlider); LowerAnimationSlider->addChangeListener(&LowerAnimationSliderListener); //Animation Advancer TheAnimationAdvancer = ElapsedTimeAnimationAdvancer::create(); beginEditCP(TheAnimationAdvancer); ElapsedTimeAnimationAdvancer::Ptr::dcast(TheAnimationAdvancer)->setStartTime( 0.0 ); beginEditCP(TheAnimationAdvancer); //Create the Documentation SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow); // Show the whole Scene mgr->showAll(); TheAnimationAdvancer->start(); //Show window Vec2f WinSize(TutorialWindowEventProducer->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindowEventProducer->getDesktopSize() - WinSize) *0.5); TutorialWindowEventProducer->openWindow(WinPos, WinSize, "23BlendXMLAnimations"); //Enter main Loop TutorialWindowEventProducer->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 TutorialWindowEventProducer = createDefaultWindowEventProducer(); WindowPtr MainWindow = TutorialWindowEventProducer->initWindow(); TutorialWindowEventProducer->setDisplayCallback(display); TutorialWindowEventProducer->setReshapeCallback(reshape); //Add Window Listener TutorialKeyListener TheKeyListener; TutorialWindowEventProducer->addKeyListener(&TheKeyListener); TutorialMouseListener TheTutorialMouseListener; TutorialMouseMotionListener TheTutorialMouseMotionListener; TutorialWindowEventProducer->addMouseListener(&TheTutorialMouseListener); TutorialWindowEventProducer->addMouseMotionListener(&TheTutorialMouseMotionListener); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(TutorialWindowEventProducer->getWindow()); Path FBOFilePath; if(argc < 2) { FWARNING(("No FBO file given!\n")); FBOFilePath = Path("./Data/01LoadFBO.xml"); } else { FBOFilePath = Path(std::string(argv[1])); } std::cout << "Loading xml File: " << FBOFilePath << std::endl; FCFileType::FCPtrStore NewContainers; NewContainers = FCFileHandler::the()->read(FBOFilePath); FCFileType::FCPtrStore::iterator Itor; for(Itor = NewContainers.begin() ; Itor != NewContainers.end() ; ++Itor) { if( (*Itor)->getType() == FBOViewport::getClassType()) { TheFBOViewport = FBOViewport::Ptr::dcast(*Itor); } } ChunkMaterialPtr BoxMaterial = ChunkMaterial::create(); GeometryPtr BoxGeoCore = makeBoxGeo(1.0,1.0,1.0,2,2,2); beginEditCP(BoxGeoCore, Geometry::MaterialFieldMask); BoxGeoCore->setMaterial(BoxMaterial); endEditCP(BoxGeoCore, Geometry::MaterialFieldMask); NodePtr BoxGeoNode = Node::create(); beginEditCP(BoxGeoNode, Node::CoreFieldMask); BoxGeoNode->setCore(BoxGeoCore); endEditCP(BoxGeoNode, Node::CoreFieldMask); NodePtr SceneNode = Node::create(); beginEditCP(SceneNode, Node::CoreFieldMask | Node::ChildrenFieldMask); SceneNode->setCore(Group::create()); SceneNode->addChild(BoxGeoNode); endEditCP(SceneNode, Node::CoreFieldMask | Node::ChildrenFieldMask); // tell the manager what to manage mgr->setRoot (SceneNode); // show the whole scene mgr->showAll(); if(TheFBOViewport != NullFC) { //Add the texture chunk of the FBO to the Material for the box beginEditCP(BoxMaterial, ChunkMaterial::ChunksFieldMask); BoxMaterial->addChunk(TheFBOViewport->editTextures(0)); endEditCP(BoxMaterial, ChunkMaterial::ChunksFieldMask); //Add The FBO Viewport the the Window beginEditCP(TheFBOViewport, FBOViewport::ParentFieldMask); TheFBOViewport->setParent(TutorialWindowEventProducer->getWindow()); endEditCP(TheFBOViewport, FBOViewport::ParentFieldMask); beginEditCP(TutorialWindowEventProducer->getWindow()); ViewportPtr vp = TutorialWindowEventProducer->getWindow()->getPort(0); addRefCP(vp); TutorialWindowEventProducer->getWindow()->subPort(0); //Put the FBO Vieport in front, so it is rendered first TutorialWindowEventProducer->getWindow()->addPort(TheFBOViewport); TutorialWindowEventProducer->getWindow()->addPort(vp ); endEditCP (TutorialWindowEventProducer->getWindow()); } Vec2f WinSize(TutorialWindowEventProducer->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindowEventProducer->getDesktopSize() - WinSize) *0.5); TutorialWindowEventProducer->openWindow(WinPos, WinSize, "07LoadFBO"); //Main Loop TutorialWindowEventProducer->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 TutorialWindowEventProducer = createDefaultWindowEventProducer(); WindowPtr MainWindow = TutorialWindowEventProducer->initWindow(); TutorialWindowEventProducer->setDisplayCallback(display); TutorialWindowEventProducer->setReshapeCallback(reshape); //Add Window Listener TutorialKeyListener TheKeyListener; TutorialWindowEventProducer->addKeyListener(&TheKeyListener); TutorialMouseListener TheTutorialMouseListener; TutorialMouseMotionListener TheTutorialMouseMotionListener; TutorialWindowEventProducer->addMouseListener(&TheTutorialMouseListener); TutorialWindowEventProducer->addMouseMotionListener(&TheTutorialMouseMotionListener); TutorialUpdateListener TheTutorialUpdateListener; TutorialWindowEventProducer->addUpdateListener(&TheTutorialUpdateListener); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(TutorialWindowEventProducer->getWindow()); //////////////// // Create the Graphics GraphicsPtr TutorialGraphics = osg::Graphics2D::create(); // Initialize the LookAndFeelManager to enable default settings LookAndFeelManager::the()->getLookAndFeel()->init(); /****************************************************** Create an Button Component and a simple Font. See 17Label_Font for more information about Fonts. ******************************************************/ ButtonPtr ExampleButton = osg::Button::create(); UIFontPtr ExampleFont = osg::UIFont::create(); beginEditCP(ExampleButton, Button::MinSizeFieldMask | Button::MaxSizeFieldMask | Button::PreferredSizeFieldMask | Button::ToolTipTextFieldMask | Button::TextFieldMask | Button::FontFieldMask | Button::TextColorFieldMask | Button::RolloverTextColorFieldMask | Button::ActiveTextColorFieldMask | Button::AlignmentFieldMask); ExampleButton->setMinSize(Vec2f(50, 25)); ExampleButton->setMaxSize(Vec2f(200, 100)); ExampleButton->setPreferredSize(Vec2f(100, 50)); ExampleButton->setToolTipText("Click to start/pause"); ExampleButton->setText("start/pause"); ExampleButton->setFont(ExampleFont); ExampleButton->setTextColor(Color4f(1.0, 0.0, 0.0, 1.0)); ExampleButton->setRolloverTextColor(Color4f(1.0, 0.0, 1.0, 1.0)); ExampleButton->setActiveTextColor(Color4f(1.0, 0.0, 0.0, 1.0)); ExampleButton->setAlignment(Vec2f(.5,0.5)); endEditCP(ExampleButton, Button::MinSizeFieldMask | Button::MaxSizeFieldMask | Button::PreferredSizeFieldMask | Button::ToolTipTextFieldMask | Button::TextFieldMask | Button::FontFieldMask | Button::TextColorFieldMask | Button::RolloverTextColorFieldMask | Button::ActiveTextColorFieldMask | Button::AlignmentFieldMask); // Create an ActionListener and assign it to ExampleButton // This Class is defined above, and will cause the output // window to display "Button 1 Action" when pressed ExampleButtonActionListener TheExampleButtonActionListener; ExampleButton->addActionListener(&TheExampleButtonActionListener); ////////////////// //Torus Material TheTorusMaterial = SimpleMaterial::create(); beginEditCP(TheTorusMaterial); SimpleMaterialPtr::dcast(TheTorusMaterial)->setAmbient(Color3f(0.3,0.3,0.3)); SimpleMaterialPtr::dcast(TheTorusMaterial)->setDiffuse(Color3f(0.7,0.7,0.7)); SimpleMaterialPtr::dcast(TheTorusMaterial)->setSpecular(Color3f(1.0,1.0,1.0)); endEditCP(TheTorusMaterial); //Torus Geometry GeometryPtr TorusGeometry = makeTorusGeo(.5, 2, 32, 32); beginEditCP(TorusGeometry); TorusGeometry->setMaterial(TheTorusMaterial); endEditCP (TorusGeometry); NodePtr TorusGeometryNode = Node::create(); beginEditCP(TorusGeometryNode, Node::CoreFieldMask); TorusGeometryNode->setCore(TorusGeometry); endEditCP (TorusGeometryNode, Node::CoreFieldMask); //Make Torus Node NodePtr TorusNode = Node::create(); TransformPtr TorusNodeTrans; TorusNodeTrans = Transform::create(); setName(TorusNodeTrans, std::string("TorusNodeTransformationCore")); beginEditCP(TorusNode, Node::CoreFieldMask | Node::ChildrenFieldMask); TorusNode->setCore(TorusNodeTrans); TorusNode->addChild(TorusGeometryNode); endEditCP (TorusNode, Node::CoreFieldMask | Node::ChildrenFieldMask); //Make Main Scene Node NodePtr scene = Node::create(); ComponentTransformPtr Trans; Trans = ComponentTransform::create(); setName(Trans, std::string("MainTransformationCore")); beginEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask); { scene->setCore(Trans); // add the torus as a child scene->addChild(TorusNode); } endEditCP (scene, Node::CoreFieldMask | Node::ChildrenFieldMask); setupAnimation(); // Create Background to be used with the Main InternalWindow ColorLayerPtr MainInternalWindowBackground = osg::ColorLayer::create(); beginEditCP(MainInternalWindowBackground, ColorLayer::ColorFieldMask); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); endEditCP(MainInternalWindowBackground, ColorLayer::ColorFieldMask); InternalWindowPtr MainInternalWindow = osg::InternalWindow::create(); LayoutPtr MainInternalWindowLayout = osg::FlowLayout::create(); beginEditCP(MainInternalWindow, InternalWindow::ChildrenFieldMask | InternalWindow::LayoutFieldMask | InternalWindow::BackgroundsFieldMask | InternalWindow::AlignmentInDrawingSurfaceFieldMask | InternalWindow::ScalingInDrawingSurfaceFieldMask | InternalWindow::DrawTitlebarFieldMask | InternalWindow::ResizableFieldMask); MainInternalWindow->getChildren().push_back(ExampleButton); 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); endEditCP(MainInternalWindow, InternalWindow::ChildrenFieldMask | InternalWindow::LayoutFieldMask | InternalWindow::BackgroundsFieldMask | InternalWindow::AlignmentInDrawingSurfaceFieldMask | InternalWindow::ScalingInDrawingSurfaceFieldMask | InternalWindow::DrawTitlebarFieldMask | InternalWindow::ResizableFieldMask); // Create the Drawing Surface UIDrawingSurfacePtr TutorialDrawingSurface = UIDrawingSurface::create(); beginEditCP(TutorialDrawingSurface, UIDrawingSurface::GraphicsFieldMask | UIDrawingSurface::EventProducerFieldMask); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindowEventProducer); endEditCP(TutorialDrawingSurface, UIDrawingSurface::GraphicsFieldMask | UIDrawingSurface::EventProducerFieldMask); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundPtr TutorialUIForeground = osg::UIForeground::create(); beginEditCP(TutorialUIForeground, UIForeground::DrawingSurfaceFieldMask); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); endEditCP(TutorialUIForeground, UIForeground::DrawingSurfaceFieldMask); mgr->setRoot(scene); // Add the UI Foreground Object to the Scene ViewportPtr TutorialViewport = mgr->getWindow()->getPort(0); beginEditCP(TutorialViewport, Viewport::ForegroundsFieldMask); TutorialViewport->getForegrounds().push_back(TutorialUIForeground); beginEditCP(TutorialViewport, Viewport::ForegroundsFieldMask); // show the whole scene mgr->showAll(); TheAnimationAdvancer->start(); Vec2f WinSize(TutorialWindowEventProducer->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindowEventProducer->getDesktopSize() - WinSize) *0.5); TutorialWindowEventProducer->openWindow(WinPos, WinSize, "24AnimationAction"); //Enter main Loop TutorialWindowEventProducer->mainLoop(); osgExit(); return 0; }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); // Set up Window TutorialWindowEventProducer = createDefaultWindowEventProducer(); WindowPtr MainWindow = TutorialWindowEventProducer->initWindow(); TutorialWindowEventProducer->setDisplayCallback(display); TutorialWindowEventProducer->setReshapeCallback(reshape); TutorialUpdateListener TheUpdateListener; TutorialWindowEventProducer->addUpdateListener(&TheUpdateListener); TutorialKeyListener TheKeyListener; TutorialWindowEventProducer->addKeyListener(&TheKeyListener); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(MainWindow); // Make Main Scene Node and add the Torus NodePtr scene = osg::Node::create(); beginEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask); scene->setCore(osg::Group::create()); endEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask); //Create a FBO Source FBOSourceTextureFilterPtr TutorialFBOSourceTextureFilter = FBOSourceTextureFilter::create(); beginEditCP(TutorialFBOSourceTextureFilter, FBOSourceTextureFilter::FBOFieldMask | FBOSourceTextureFilter::FBOSizeFieldMask); TutorialFBOSourceTextureFilter->setFBO(createSceneFBO()); TutorialFBOSourceTextureFilter->setFBOSize(Vec2f(-1.0,-1.0)); endEditCP(TutorialFBOSourceTextureFilter, FBOSourceTextureFilter::FBOFieldMask | FBOSourceTextureFilter::FBOSizeFieldMask); //Create a HDR filter std::string HDRFragProg = ""; HDRFragProg += "uniform sampler2D Slot0Texture;" "uniform float Exposure;" "uniform float MaxLuminance;" "uniform float Gamma;" "void main()" "{" " vec3 Color = texture2D(Slot0Texture,gl_TexCoord[0].st).rgb;" //" float Intensity = dot(vec3(0.3,0.59,0.11),Color);" " float TonePercent = Exposure * ((Exposure/MaxLuminance + 1.0)/(Exposure + 1.0));" //Apply Tone Mapping And Gamma Correction " Color = pow(Color * TonePercent, vec3(Gamma));" " gl_FragColor = vec4(Color, 1.0);" "}"; //Create a shader Filter HDRTextureFilter = ShaderTextureFilter::create(); HDRTextureFilter->attachSource(TutorialFBOSourceTextureFilter, 0, 0); HDRTextureFilter->setFragmentSource(HDRFragProg); HDRTextureFilter->setUniformParameter("Exposure", Exposure); HDRTextureFilter->setUniformParameter("MaxLuminance", MaxLuminance); HDRTextureFilter->setUniformParameter("Gamma", Gamma); // Create the ImageProcessed Foreground Object ImageProcessedForegroundPtr TutorialImageProcessedForeground = ImageProcessedForeground::create(); beginEditCP(TutorialImageProcessedForeground, ImageProcessedForeground::FilterFieldMask | ImageProcessedForeground::OutputSlotFieldMask); TutorialImageProcessedForeground->setFilter(HDRTextureFilter); TutorialImageProcessedForeground->setOutputSlot(0); endEditCP(TutorialImageProcessedForeground, ImageProcessedForeground::FilterFieldMask | ImageProcessedForeground::OutputSlotFieldMask); mgr->setRoot(scene); // Add the ImageProcessed Foreground Object to the Scene ViewportPtr TutorialViewport = mgr->getWindow()->getPort(0); beginEditCP(TutorialViewport, Viewport::ForegroundsFieldMask); TutorialViewport->getForegrounds().push_back(TutorialImageProcessedForeground); beginEditCP(TutorialViewport, Viewport::ForegroundsFieldMask); // Show the whole Scene mgr->showAll(); //Open Window Vec2f WinSize(TutorialWindowEventProducer->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindowEventProducer->getDesktopSize() - WinSize) *0.5); TutorialWindowEventProducer->openWindow(WinPos, WinSize, "03ScenePostProcessing"); //Enter main Loop TutorialWindowEventProducer->mainLoop(); osgExit(); return 0; }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); // Set up Window TutorialWindowEventProducer = createDefaultWindowEventProducer(); WindowPtr MainWindow = TutorialWindowEventProducer->initWindow(); TutorialWindowEventProducer->setDisplayCallback(display); TutorialWindowEventProducer->setReshapeCallback(reshape); TutorialUpdateListener TheTutorialUpdateListener; TutorialWindowEventProducer->addUpdateListener(&TheTutorialUpdateListener); //Add Window Listener TutorialKeyListener TheKeyListener; TutorialWindowEventProducer->addKeyListener(&TheKeyListener); TutorialMouseListener TheTutorialMouseListener; TutorialMouseMotionListener TheTutorialMouseMotionListener; TutorialWindowEventProducer->addMouseListener(&TheTutorialMouseListener); TutorialWindowEventProducer->addMouseMotionListener(&TheTutorialMouseMotionListener); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(MainWindow); //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 << "SHIFT-B Show/Hide the bind pose mesh" << std::endl; std::cout << "P Show/Hide the current pose skeleton" << std::endl; std::cout << "SHIFT-P Show/Hide the current pose mesh" << std::endl; std::cout << "CTRL-Q Exit\n\n" << std::endl; //Import scene from XML ChunkMaterialPtr ExampleMaterial; SkeletonPtr ExampleSkeleton; SkeletonBlendedGeometryPtr TheNewSkeletonGeometry; GeometryPtr ExampleGeometry; FCFileType::FCPtrStore NewContainers; NewContainers = FCFileHandler::the()->read(Path("./Data/20BlendedGeometry.xml")); FCFileType::FCPtrStore::iterator Itor; for(Itor = NewContainers.begin() ; Itor != NewContainers.end() ; ++Itor) { if( (*Itor)->getType() == (ChunkMaterial::getClassType())) { //Set ExampleMaterial to the ChunkMaterial we just read in ExampleMaterial = (ChunkMaterial::Ptr::dcast(*Itor)); } if( (*Itor)->getType() == (Skeleton::getClassType())) { //Set ExampleSkeleton to the Skeleton we just read in ExampleSkeleton = (Skeleton::Ptr::dcast(*Itor)); } if( (*Itor)->getType() == (Geometry::getClassType())) { //Set ExampleGeometry to the geometry we just read in ExampleGeometry = (Geometry::Ptr::dcast(*Itor)); } if( (*Itor)->getType() == (SkeletonBlendedGeometry::getClassType())) { //Set TheNewSkeletonGeometry to the SkeletonBlendedGeometry we just read in TheNewSkeletonGeometry = (SkeletonBlendedGeometry::Ptr::dcast(*Itor)); } if( (*Itor)->getType().isDerivedFrom(Animation::getClassType())) { //Set TheSkeletonAnimation to the Animation we just read in TheSkeletonAnimation = (Animation::Ptr::dcast(*Itor)); } } //UnboundGeometry UnboundGeometry = Node::create(); beginEditCP(UnboundGeometry, Node::CoreFieldMask | Node::TravMaskFieldMask); UnboundGeometry->setCore(ExampleGeometry); UnboundGeometry->setTravMask(0); endEditCP(UnboundGeometry, Node::CoreFieldMask | Node::TravMaskFieldMask); //SkeletonDrawer SkeletonDrawablePtr ExampleSkeletonDrawable = osg::SkeletonDrawable::create(); beginEditCP(ExampleSkeletonDrawable, SkeletonDrawable::SkeletonFieldMask | SkeletonDrawable::MaterialFieldMask | SkeletonDrawable::DrawBindPoseFieldMask | SkeletonDrawable::BindPoseColorFieldMask | SkeletonDrawable::DrawPoseFieldMask | SkeletonDrawable::PoseColorFieldMask); ExampleSkeletonDrawable->setSkeleton(ExampleSkeleton); ExampleSkeletonDrawable->setMaterial(ExampleMaterial); ExampleSkeletonDrawable->setDrawBindPose(false); //By default, we don't draw the skeleton's bind pose ExampleSkeletonDrawable->setBindPoseColor(Color4f(0.0, 1.0, 0.0, 1.0)); //When drawn, the skeleton's bind pose renders in 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 renders in blue endEditCP(ExampleSkeletonDrawable, SkeletonDrawable::SkeletonFieldMask | SkeletonDrawable::MaterialFieldMask | SkeletonDrawable::DrawBindPoseFieldMask | SkeletonDrawable::BindPoseColorFieldMask | SkeletonDrawable::DrawPoseFieldMask | SkeletonDrawable::PoseColorFieldMask); //Skeleton Node SkeletonNode = osg::Node::create(); beginEditCP(SkeletonNode, Node::CoreFieldMask); SkeletonNode->setCore(ExampleSkeletonDrawable); endEditCP(SkeletonNode, Node::CoreFieldMask); //Skeleton Blended Geometry Node MeshNode = osg::Node::create(); beginEditCP(MeshNode, Node::CoreFieldMask); MeshNode->setCore(TheNewSkeletonGeometry); endEditCP(MeshNode, Node::CoreFieldMask); //Animation Advancer TheAnimationAdvancer = osg::ElapsedTimeAnimationAdvancer::create(); osg::beginEditCP(TheAnimationAdvancer); osg::ElapsedTimeAnimationAdvancer::Ptr::dcast(TheAnimationAdvancer)->setStartTime( 0.0 ); osg::beginEditCP(TheAnimationAdvancer); //Create scene NodePtr scene = osg::Node::create(); beginEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask); scene->setCore(osg::Group::create()); scene->addChild(UnboundGeometry); scene->addChild(SkeletonNode); scene->addChild(MeshNode); endEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask); mgr->setRoot(scene); // Show the whole Scene mgr->showAll(); TheAnimationAdvancer->start(); //Show window Vec2f WinSize(TutorialWindowEventProducer->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindowEventProducer->getDesktopSize() - WinSize) *0.5); TutorialWindowEventProducer->openWindow(WinPos, WinSize, "20LoadXMLBlendedGeometry"); //Enter main Loop TutorialWindowEventProducer->mainLoop(); osgExit(); return 0; }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); // Set up Window TutorialWindowEventProducer = createDefaultWindowEventProducer(); WindowPtr MainWindow = TutorialWindowEventProducer->initWindow(); TutorialWindowEventProducer->setDisplayCallback(display); TutorialWindowEventProducer->setReshapeCallback(reshape); TutorialKeyListener TheKeyListener; TutorialWindowEventProducer->addKeyListener(&TheKeyListener); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(MainWindow); // Make Torus Node (creates Torus in background of scene) NodePtr TorusGeometryNode = makeTorus(.5, 2, 16, 16); // Make Main Scene Node and add the Torus NodePtr scene = osg::Node::create(); beginEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask); scene->setCore(osg::Group::create()); scene->addChild(TorusGeometryNode); endEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask); // Create the Graphics GraphicsPtr TutorialGraphics = osg::Graphics2D::create(); // Initialize the LookAndFeelManager to enable default settings LookAndFeelManager::the()->getLookAndFeel()->init(); /****************************************************** Create an Button Component and a simple Font. See 17Label_Font for more information about Fonts. ******************************************************/ ButtonPtr ExampleButton = osg::Button::create(); UIFontPtr ExampleFont = osg::UIFont::create(); beginEditCP(ExampleFont, UIFont::SizeFieldMask); ExampleFont->setSize(16); endEditCP(ExampleFont, UIFont::SizeFieldMask); /****************************************************** Edit the Button's characteristics. Note: the first 4 functions can be used with any Component and are not specific to Button. -setMinSize(Vec2f): Determine the Minimum Size of the Component. Some Layouts will automatically resize Components; this prevents the Size from going below a certain value. -setMaxSize(Vec2f): Determine the Maximum Size of the Component. -setPreferredSize(Vec2f): Determine the Preferred Size of the Component. This is what the Component will be displayed at unless changed by another Component (such as a Layout). -setToolTipText("Text"): Determine what text is displayed while Mouse is hovering above Component. The word Text will be displayed in this case. Functions specfic to Button: -setText("DesiredText"): Determine the Button's text. It will read DesiredText in this case. -setFont(FontName): Determine the Font to be used on the Button. -setTextColor(Color4f): Determine the Color for the text. -setRolloverTextColor(Color4f): Determine what the text Color will be when the Mouse Cursor is above the Button. -setActiveTextColor(Color4f): Determine what the text Color will be when the Button is pressed (denoted by Active). -setAlignment(Vec2f): Determine the Vertical Alignment of the text. The value is in [0.0, 1.0]. ******************************************************/ beginEditCP(ExampleButton, Button::MinSizeFieldMask | Button::MaxSizeFieldMask | Button::PreferredSizeFieldMask | Button::ToolTipTextFieldMask | Button::TextFieldMask | Button::FontFieldMask | Button::TextColorFieldMask | Button::RolloverTextColorFieldMask | Button::ActiveTextColorFieldMask | Button::AlignmentFieldMask); ExampleButton->setMinSize(Vec2f(50, 25)); ExampleButton->setMaxSize(Vec2f(200, 100)); ExampleButton->setPreferredSize(Vec2f(100, 50)); ExampleButton->setToolTipText("Button 1 ToolTip"); ExampleButton->setText("Button 1"); ExampleButton->setFont(ExampleFont); ExampleButton->setTextColor(Color4f(1.0, 0.0, 0.0, 1.0)); ExampleButton->setRolloverTextColor(Color4f(1.0, 0.0, 1.0, 1.0)); ExampleButton->setActiveTextColor(Color4f(1.0, 0.0, 0.0, 1.0)); ExampleButton->setAlignment(Vec2f(1.0,0.0)); endEditCP(ExampleButton, Button::MinSizeFieldMask | Button::MaxSizeFieldMask | Button::PreferredSizeFieldMask | Button::ToolTipTextFieldMask | Button::TextFieldMask | Button::FontFieldMask | Button::TextColorFieldMask | Button::RolloverTextColorFieldMask | Button::ActiveTextColorFieldMask | Button::AlignmentFieldMask); // Create an ActionListener and assign it to ExampleButton // This Class is defined above, and will cause the output // window to display "Button 1 Action" when pressed ExampleButtonActionListener TheExampleButtonActionListener; ExampleButton->addActionListener(&TheExampleButtonActionListener); /****************************************************** Create a ToggleButton and determine its characteristics. ToggleButton inherits off of Button, so all characteristsics used above can be used with ToggleButtons as well. The only difference is that when pressed, ToggleButton remains pressed until pressed again. -setSelected(bool): Determine whether the ToggleButton is Selected (true) or deselected (false). ******************************************************/ ToggleButtonPtr ExampleToggleButton = osg::ToggleButton::create(); beginEditCP(ExampleToggleButton, ToggleButton::SelectedFieldMask | ToggleButton::TextFieldMask | ToggleButton::ToolTipTextFieldMask); ExampleToggleButton->setSelected(false); ExampleToggleButton->setText("ToggleMe"); ExampleToggleButton->setToolTipText("Toggle Button ToolTip"); endEditCP(ExampleToggleButton, ToggleButton::SelectedFieldMask | ToggleButton::TextFieldMask | ToggleButton::ToolTipTextFieldMask); //Button with Image ButtonPtr ExampleDrawObjectButton = osg::Button::create(); beginEditCP(ExampleDrawObjectButton, Button::DrawObjectToTextAlignmentFieldMask | Button::TextFieldMask); ExampleDrawObjectButton->setDrawObjectToTextAlignment(Button::ALIGN_DRAW_OBJECT_RIGHT_OF_TEXT); ExampleDrawObjectButton->setText("Icon"); endEditCP(ExampleDrawObjectButton, Button::DrawObjectToTextAlignmentFieldMask | Button::TextFieldMask); ExampleDrawObjectButton->setImage(std::string("Data/Icon.png")); ExampleDrawObjectButton->setActiveImage(std::string("Data/Icon.png")); ExampleDrawObjectButton->setFocusedImage(std::string("Data/Icon.png")); ExampleDrawObjectButton->setRolloverImage(std::string("Data/Icon.png")); ExampleDrawObjectButton->setDisabledImage(std::string("Data/Icon.png")); // Create The Main InternalWindow // Create Background to be used with the Main InternalWindow ColorLayerPtr MainInternalWindowBackground = osg::ColorLayer::create(); beginEditCP(MainInternalWindowBackground, ColorLayer::ColorFieldMask); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); endEditCP(MainInternalWindowBackground, ColorLayer::ColorFieldMask); InternalWindowPtr MainInternalWindow = osg::InternalWindow::create(); LayoutPtr MainInternalWindowLayout = osg::FlowLayout::create(); beginEditCP(MainInternalWindow, InternalWindow::ChildrenFieldMask | InternalWindow::LayoutFieldMask | InternalWindow::BackgroundsFieldMask | InternalWindow::AlignmentInDrawingSurfaceFieldMask | InternalWindow::ScalingInDrawingSurfaceFieldMask | InternalWindow::DrawTitlebarFieldMask | InternalWindow::ResizableFieldMask); MainInternalWindow->getChildren().push_back(ExampleButton); MainInternalWindow->getChildren().push_back(ExampleToggleButton); MainInternalWindow->getChildren().push_back(ExampleDrawObjectButton); 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); endEditCP(MainInternalWindow, InternalWindow::ChildrenFieldMask | InternalWindow::LayoutFieldMask | InternalWindow::BackgroundsFieldMask | InternalWindow::AlignmentInDrawingSurfaceFieldMask | InternalWindow::ScalingInDrawingSurfaceFieldMask | InternalWindow::DrawTitlebarFieldMask | InternalWindow::ResizableFieldMask); // Create the Drawing Surface UIDrawingSurfacePtr TutorialDrawingSurface = UIDrawingSurface::create(); beginEditCP(TutorialDrawingSurface, UIDrawingSurface::GraphicsFieldMask | UIDrawingSurface::EventProducerFieldMask); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindowEventProducer); endEditCP(TutorialDrawingSurface, UIDrawingSurface::GraphicsFieldMask | UIDrawingSurface::EventProducerFieldMask); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundPtr TutorialUIForeground = osg::UIForeground::create(); beginEditCP(TutorialUIForeground, UIForeground::DrawingSurfaceFieldMask); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); endEditCP(TutorialUIForeground, UIForeground::DrawingSurfaceFieldMask); mgr->setRoot(scene); // Add the UI Foreground Object to the Scene ViewportPtr TutorialViewport = mgr->getWindow()->getPort(0); beginEditCP(TutorialViewport, Viewport::ForegroundsFieldMask); TutorialViewport->getForegrounds().push_back(TutorialUIForeground); beginEditCP(TutorialViewport, Viewport::ForegroundsFieldMask); // Show the whole Scene mgr->showAll(); //Open Window Vec2f WinSize(TutorialWindowEventProducer->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindowEventProducer->getDesktopSize() - WinSize) *0.5); TutorialWindowEventProducer->openWindow(WinPos, WinSize, "01RubberBandCamera"); //Enter main Loop TutorialWindowEventProducer->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 TutorialWindowEventProducer = createDefaultWindowEventProducer(); WindowPtr MainWindow = TutorialWindowEventProducer->initWindow(); TutorialWindowEventProducer->setDisplayCallback(display); TutorialWindowEventProducer->setReshapeCallback(reshape); TutorialKeyListener TheKeyListener; TutorialWindowEventProducer->addKeyListener(&TheKeyListener); TutorialMouseListener TheTutorialMouseListener; TutorialMouseMotionListener TheTutorialMouseMotionListener; TutorialWindowEventProducer->addMouseListener(&TheTutorialMouseListener); TutorialWindowEventProducer->addMouseMotionListener(&TheTutorialMouseMotionListener); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(TutorialWindowEventProducer->getWindow()); //Make Torus Node TriGeometryBase = makeTorus(.55, 1.5, 16, 16); //Make Main Scene Node NodePtr scene = makeCoredNode<Group>(); setName(scene, "scene"); rootNode = Node::create(); setName(rootNode, "rootNode"); ComponentTransformPtr Trans; Trans = ComponentTransform::create(); beginEditCP(rootNode, Node::CoreFieldMask | Node::ChildrenFieldMask); rootNode->setCore(Trans); // add the torus as a child rootNode->addChild(scene); endEditCP (rootNode, Node::CoreFieldMask | Node::ChildrenFieldMask); //Setup Physics Scene physicsWorld = PhysicsWorld::create(); beginEditCP(physicsWorld, PhysicsWorld::WorldContactSurfaceLayerFieldMask | PhysicsWorld::AutoDisableFlagFieldMask | PhysicsWorld::AutoDisableTimeFieldMask | PhysicsWorld::WorldContactMaxCorrectingVelFieldMask | PhysicsWorld::GravityFieldMask); physicsWorld->setWorldContactSurfaceLayer(0.005); physicsWorld->setAutoDisableFlag(1); physicsWorld->setAutoDisableTime(0.75); physicsWorld->setWorldContactMaxCorrectingVel(100.0); physicsWorld->setGravity(Vec3f(0.0, 0.0, -9.81)); endEditCP(physicsWorld, PhysicsWorld::WorldContactSurfaceLayerFieldMask | PhysicsWorld::AutoDisableFlagFieldMask | PhysicsWorld::AutoDisableTimeFieldMask | PhysicsWorld::WorldContactMaxCorrectingVelFieldMask | PhysicsWorld::GravityFieldMask); //Create the Collision Space physicsSpace = PhysicsHashSpace::create(); //Setup the default collision parameters CollisionContactParametersPtr DefaultCollisionParams = CollisionContactParameters::createEmpty(); beginEditCP(DefaultCollisionParams); DefaultCollisionParams->setMode(dContactApprox1); DefaultCollisionParams->setMu(0.3); DefaultCollisionParams->setMu2(0.0); DefaultCollisionParams->setBounce(0.0); DefaultCollisionParams->setBounceSpeedThreshold(0.0); DefaultCollisionParams->setSoftCFM(0.1); DefaultCollisionParams->setSoftERP(0.2); DefaultCollisionParams->setMotion1(0.0); DefaultCollisionParams->setMotion2(0.0); DefaultCollisionParams->setMotionN(0.0); DefaultCollisionParams->setSlip1(0.0); DefaultCollisionParams->setSlip2(0.0); endEditCP(DefaultCollisionParams); beginEditCP(physicsSpace, PhysicsSpace::DefaultCollisionParametersFieldMask); physicsSpace->setDefaultCollisionParameters(DefaultCollisionParams); endEditCP(physicsSpace, PhysicsSpace::DefaultCollisionParametersFieldMask); //Bouncy Sphere collision parameters CollisionContactParametersPtr BouncySphereCollisionParams = CollisionContactParameters::createEmpty(); beginEditCP(BouncySphereCollisionParams); BouncySphereCollisionParams->setMode(dContactApprox1 | dContactBounce); BouncySphereCollisionParams->setMu(0.3); BouncySphereCollisionParams->setMu2(0.0); BouncySphereCollisionParams->setBounce(0.8); BouncySphereCollisionParams->setBounceSpeedThreshold(0.1); BouncySphereCollisionParams->setSoftCFM(0.1); BouncySphereCollisionParams->setSoftERP(0.2); BouncySphereCollisionParams->setMotion1(0.0); BouncySphereCollisionParams->setMotion2(0.0); BouncySphereCollisionParams->setMotionN(0.0); BouncySphereCollisionParams->setSlip1(0.0); BouncySphereCollisionParams->setSlip2(0.0); endEditCP(BouncySphereCollisionParams); physicsSpace->addCollisionContactCategory(SphereCategory, TerrainCategory, BouncySphereCollisionParams); physicsSpace->addCollisionContactCategory(SphereCategory, BoxCategory, BouncySphereCollisionParams); physicsSpace->addCollisionContactCategory(SphereCategory, SphereCategory, BouncySphereCollisionParams); physicsSpace->addCollisionContactCategory(SphereCategory, TriCategory, BouncySphereCollisionParams); //Soft Box collision parameters CollisionContactParametersPtr SlickBoxParams = CollisionContactParameters::createEmpty(); beginEditCP(SlickBoxParams); SlickBoxParams->setMode(dContactApprox1); SlickBoxParams->setMu(0.01); SlickBoxParams->setMu2(0.0); SlickBoxParams->setBounce(0.0); SlickBoxParams->setBounceSpeedThreshold(0.0); SlickBoxParams->setSoftCFM(0.0); SlickBoxParams->setSoftERP(0.2); SlickBoxParams->setMotion1(0.0); SlickBoxParams->setMotion2(0.0); SlickBoxParams->setMotionN(0.0); SlickBoxParams->setSlip1(0.0); SlickBoxParams->setSlip2(0.0); endEditCP(SlickBoxParams); physicsSpace->addCollisionContactCategory(BoxCategory, TerrainCategory, SlickBoxParams); physicsSpace->addCollisionContactCategory(BoxCategory, BoxCategory, SlickBoxParams); //physicsSpace->addCollisionContactCategory(BoxCategory, SphereCategory, SlickBoxParams); physicsSpace->addCollisionContactCategory(BoxCategory, TriCategory, SlickBoxParams); TutorialCollisionListener BoxColListener(Path("./Data/click.wav")); physicsSpace->addCollisionListener(&BoxColListener,BoxCategory, 2.0); TutorialCollisionListener SphereColListener(Path("./Data/pop.wav")); physicsSpace->addCollisionListener(&SphereColListener,SphereCategory, 2.0); physHandler = PhysicsHandler::create(); beginEditCP(physHandler, PhysicsHandler::WorldFieldMask | PhysicsHandler::SpacesFieldMask | PhysicsHandler::StepSizeFieldMask | PhysicsHandler::UpdateNodeFieldMask); physHandler->setWorld(physicsWorld); physHandler->getSpaces().push_back(physicsSpace); physHandler->setStepSize(0.001); physHandler->setUpdateNode(rootNode); endEditCP(physHandler, PhysicsHandler::WorldFieldMask | PhysicsHandler::SpacesFieldMask | PhysicsHandler::StepSizeFieldMask | PhysicsHandler::UpdateNodeFieldMask); physHandler->attachUpdateProducer(TutorialWindowEventProducer); beginEditCP(rootNode, Node::AttachmentsFieldMask); rootNode->addAttachment(physHandler); rootNode->addAttachment(physicsWorld); rootNode->addAttachment(physicsSpace); endEditCP(rootNode, Node::AttachmentsFieldMask); /************************************************************************/ /* create spaces, geoms and bodys */ /************************************************************************/ //create a group for our space GroupPtr spaceGroup; spaceGroupNode = makeCoredNode<Group>(&spaceGroup); //create the ground plane GeometryPtr plane; NodePtr planeNode = makeBox(30.0, 30.0, 1.0, 1, 1, 1); plane = GeometryPtr::dcast(planeNode->getCore()); //and its Material SimpleMaterialPtr plane_mat = SimpleMaterial::create(); beginEditCP(plane_mat); plane_mat->setAmbient(Color3f(0.7,0.7,0.7)); plane_mat->setDiffuse(Color3f(0.9,0.6,1.0)); endEditCP(plane_mat); beginEditCP(plane, Geometry::MaterialFieldMask); plane->setMaterial(plane_mat); endEditCP(plane); //create Physical Attachments PhysicsBoxGeomPtr planeGeom = PhysicsBoxGeom::create(); beginEditCP(planeGeom, PhysicsBoxGeom::LengthsFieldMask | PhysicsBoxGeom::SpaceFieldMask | PhysicsBoxGeom::CategoryBitsFieldMask); planeGeom->setLengths(Vec3f(30.0, 30.0, 1.0)); //add geoms to space for collision planeGeom->setSpace(physicsSpace); //Set the Geoms Category - this will be used by the collision space //for determining if collision tests should occur //and for selecting the collision contact parameters when a collision does occur planeGeom->setCategoryBits(TerrainCategory); endEditCP(planeGeom, PhysicsBoxGeom::LengthsFieldMask | PhysicsBoxGeom::SpaceFieldMask | PhysicsBoxGeom::CategoryBitsFieldMask); //add Attachments to nodes... beginEditCP(spaceGroupNode, Node::AttachmentsFieldMask | Node::ChildrenFieldMask); spaceGroupNode->addAttachment(physicsSpace); spaceGroupNode->addChild(planeNode); endEditCP(spaceGroupNode, Node::AttachmentsFieldMask | Node::ChildrenFieldMask); beginEditCP(planeNode, Node::AttachmentsFieldMask); planeNode->addAttachment(planeGeom); endEditCP(planeNode, Node::AttachmentsFieldMask); beginEditCP(scene, Node::ChildrenFieldMask); scene->addChild(spaceGroupNode); endEditCP(scene, Node::ChildrenFieldMask); //Create Statistics Foreground SimpleStatisticsForegroundPtr PhysicsStatForeground = SimpleStatisticsForeground::create(); beginEditCP(PhysicsStatForeground); 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"); endEditCP(PhysicsStatForeground); // tell the manager what to manage mgr->setRoot (rootNode); beginEditCP(mgr->getWindow()->getPort(0), Viewport::ForegroundsFieldMask); mgr->getWindow()->getPort(0)->getForegrounds().push_back(PhysicsStatForeground); endEditCP(mgr->getWindow()->getPort(0), Viewport::ForegroundsFieldMask); physHandler->setStatistics(&PhysicsStatForeground->getCollector()); // show the whole rootNode mgr->showAll(); //Attach the Sound Manager to the update and the camera SoundManager::the()->attachUpdateProducer(TutorialWindowEventProducer); SoundManager::the()->setCamera(mgr->getCamera()); Vec2f WinSize(TutorialWindowEventProducer->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindowEventProducer->getDesktopSize() - WinSize) *0.5); TutorialWindowEventProducer->openWindow(WinPos, WinSize, "21Collisions"); //Enter main Loop TutorialWindowEventProducer->mainLoop(); osgExit(); return 0; }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); // Set up Window TutorialWindowEventProducer = createDefaultWindowEventProducer(); WindowPtr MainWindow = TutorialWindowEventProducer->initWindow(); TutorialWindowEventProducer->setDisplayCallback(display); TutorialWindowEventProducer->setReshapeCallback(reshape); TutorialKeyListener TheKeyListener; TutorialWindowEventProducer->addKeyListener(&TheKeyListener); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(MainWindow); // Make Torus Node (creates Torus in background of scene) NodePtr TorusGeometryNode = makeTorus(.5, 2, 16, 16); // Make Main Scene Node and add the Torus NodePtr scene = osg::Node::create(); beginEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask); scene->setCore(osg::Group::create()); scene->addChild(TorusGeometryNode); endEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask); //Create the Image Path ImagePath("./Data/TutorialImage.jpg"); ImagePtr TheImage = ImageFileHandler::the().read(ImagePath.string().c_str()); //Create the texture TextureChunkPtr TheTextureChunk = TextureChunk::create(); beginEditCP(TheTextureChunk); TheTextureChunk->setImage(TheImage); TheTextureChunk->setMinFilter(GL_NEAREST); TheTextureChunk->setMagFilter(GL_NEAREST); TheTextureChunk->setWrapS(GL_CLAMP_TO_EDGE); TheTextureChunk->setWrapR(GL_CLAMP_TO_EDGE); TheTextureChunk->setScale(false); TheTextureChunk->setNPOTMatrixScale(true); TheTextureChunk->setEnvMode(GL_REPLACE); endEditCP(TheTextureChunk); //Create a Texture Source TextureSourceTextureFilterPtr TutorialTextureSourceTextureFilter = TextureSourceTextureFilter::create(); beginEditCP(TutorialTextureSourceTextureFilter, TextureSourceTextureFilter::TextureFieldMask); TutorialTextureSourceTextureFilter->setTexture(TheTextureChunk); endEditCP(TutorialTextureSourceTextureFilter, TextureSourceTextureFilter::TextureFieldMask); //Create a Grayscale filter std::string GrayScaleFragProg = "uniform sampler2D Slot0Texture; void main() { gl_FragColor = vec4(vec3( dot(vec3(0.3,0.59,0.11), texture2D(Slot0Texture,gl_TexCoord[0].st).rgb)), 1.0); }"; //Create a shader Filter ShaderTextureFilterPtr GrayscaleTextureFilter = ShaderTextureFilter::create(); GrayscaleTextureFilter->attachSource(TutorialTextureSourceTextureFilter, 0, 0); GrayscaleTextureFilter->setFragmentSource(GrayScaleFragProg); //Create a Color Mult filter std::string ColorMultFragProg = "uniform sampler2D Slot0Texture; void main() { gl_FragColor = vec4(vec3(1.0,0.0,0.0) * texture2D(Slot0Texture,gl_TexCoord[0].st).rgb, 1.0); }"; //Create a shader Filter ShaderTextureFilterPtr ColorMultTextureFilter = ShaderTextureFilter::create(); ColorMultTextureFilter->attachSource(GrayscaleTextureFilter,0,0); ColorMultTextureFilter->setFragmentSource(ColorMultFragProg); ////Create a Blur filter //std::string BlurFragProg = ""; //BlurFragProg += //"uniform sampler2D Slot0Texture;" //"void main()" //"{" //" vec2 offsets[9];" //" offsets[0] = vec2(-0.000625,0.00111111111);" //" offsets[1] = vec2(0.0,0.00111111111);" //" offsets[2] = vec2(0.000625,0.00111111111);" //" offsets[3] = vec2(-0.000625,0.0);" //" offsets[4] = vec2(0.0,0.0);" //" offsets[5] = vec2(0.0,0.0);" //" offsets[6] = vec2(-0.000625,-0.00111111111);" //" offsets[7] = vec2(0.0,-0.00111111111);" //" offsets[8] = vec2(0.000625,-0.00111111111);" //" vec4 kernel[9];" ////" kernel[0] = vec4(0.0);" ////" kernel[1] = vec4(0.0);" ////" kernel[2] = vec4(0.0);" ////" kernel[3] = vec4(0.0);" ////" kernel[4] = vec4(1.0);" ////" kernel[5] = vec4(0.0);" ////" kernel[6] = vec4(0.0);" ////" kernel[7] = vec4(0.0);" ////" kernel[8] = vec4(0.0);" //" kernel[0] = vec4(0.0);" //" kernel[1] = vec4(0.15);" //" kernel[2] = vec4(0.0);" //" kernel[3] = vec4(0.15);" //" kernel[4] = vec4(0.4);" //" kernel[5] = vec4(0.15);" //" kernel[6] = vec4(0.0);" //" kernel[7] = vec4(0.15);" //" kernel[8] = vec4(0.0);" //" vec4 sum = vec4(0.0);" //" int i;" //" for(i = 0 ; i < 9 ; i++)" //" {" //" sum += kernel[i] * texture2D(Slot0Texture,gl_TexCoord[0].st + offsets[i]);" //" }" //" gl_FragColor = sum;" //"}"; ////Create a shader Filter //ShaderTextureFilterPtr BlurTextureFilter = ShaderTextureFilter::create(); //BlurTextureFilter->attachSource(ColorMultTextureFilter); //BlurTextureFilter->setFragmentSource(BlurFragProg); // Create the ImageProcessed Foreground Object ImageProcessedForegroundPtr TutorialImageProcessedForeground = ImageProcessedForeground::create(); beginEditCP(TutorialImageProcessedForeground, ImageProcessedForeground::FilterFieldMask | ImageProcessedForeground::OutputSlotFieldMask); TutorialImageProcessedForeground->setFilter(ColorMultTextureFilter); TutorialImageProcessedForeground->setOutputSlot(0); endEditCP(TutorialImageProcessedForeground, ImageProcessedForeground::FilterFieldMask | ImageProcessedForeground::OutputSlotFieldMask); mgr->setRoot(scene); // Add the ImageProcessed Foreground Object to the Scene ViewportPtr TutorialViewport = mgr->getWindow()->getPort(0); beginEditCP(TutorialViewport, Viewport::ForegroundsFieldMask); TutorialViewport->getForegrounds().push_back(TutorialImageProcessedForeground); beginEditCP(TutorialViewport, Viewport::ForegroundsFieldMask); // Show the whole Scene mgr->showAll(); //Open Window Vec2f WinSize(TutorialWindowEventProducer->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindowEventProducer->getDesktopSize() - WinSize) *0.5); TutorialWindowEventProducer->openWindow(WinPos, WinSize, "02SimpleImagePipeline"); //Enter main Loop TutorialWindowEventProducer->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 TutorialWindowEventProducer = createDefaultWindowEventProducer(); WindowPtr MainWindow = TutorialWindowEventProducer->initWindow(); TutorialWindowEventProducer->setDisplayCallback(display); TutorialWindowEventProducer->setReshapeCallback(reshape); //Add Window Listener TutorialKeyListener TheKeyListener; TutorialWindowEventProducer->addKeyListener(&TheKeyListener); TutorialMouseListener TheTutorialMouseListener; TutorialMouseMotionListener TheTutorialMouseMotionListener; TutorialWindowEventProducer->addMouseListener(&TheTutorialMouseListener); TutorialWindowEventProducer->addMouseMotionListener(&TheTutorialMouseMotionListener); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(TutorialWindowEventProducer->getWindow()); //Make a SphereNode for the point light LambertMaterialPtr TheLightMat = LambertMaterial::create(); beginEditCP(TheLightMat, LambertMaterial::IncandescenceFieldMask); TheLightMat->setIncandescence(Color3f(1.0,1.0,1.0)); endEditCP(TheLightMat, LambertMaterial::IncandescenceFieldMask); GeometryPtr LightSphereGeo = makeSphereGeo(2,2.0); beginEditCP(LightSphereGeo, Geometry::MaterialFieldMask); LightSphereGeo->setMaterial(TheLightMat); endEditCP (LightSphereGeo, Geometry::MaterialFieldMask); NodePtr LightSphereNode = Node::create(); beginEditCP(LightSphereNode, Node::CoreFieldMask); LightSphereNode->setCore(LightSphereGeo); endEditCP (LightSphereNode, Node::CoreFieldMask); //Create the beacon for the Point Light Matrix ThePointLightMat; ThePointLightMat.setTranslate(Vec3f(0.0,100.0,0.0)); ThePointLightBeaconTransform = Transform::create(); beginEditCP(ThePointLightBeaconTransform); ThePointLightBeaconTransform->setMatrix(ThePointLightMat); endEditCP(ThePointLightBeaconTransform); NodePtr ThePointLightBeaconNode = Node::create(); beginEditCP(ThePointLightBeaconNode); ThePointLightBeaconNode->setCore(ThePointLightBeaconTransform); ThePointLightBeaconNode->addChild(LightSphereNode); endEditCP(ThePointLightBeaconNode); //Set the light properties desired PointLightPtr ThePointLight = PointLight::create(); beginEditCP(ThePointLight); ThePointLight->setAmbient(0.3,0.3,0.3,0.3); ThePointLight->setDiffuse(1.0,1.0,1.0,1.0); ThePointLight->setSpecular(1.0,1.0,1.0,1.0); ThePointLight->setBeacon(ThePointLightBeaconNode); endEditCP(ThePointLight); NodePtr ThePointLightNode = Node::create(); beginEditCP(ThePointLightNode); ThePointLightNode->setCore(ThePointLight); endEditCP(ThePointLightNode); //Set the light properties desired SpotLightPtr TheSpotLight = SpotLight::create(); beginEditCP(TheSpotLight); TheSpotLight->setAmbient(0.3,0.3,0.3,0.3); TheSpotLight->setDiffuse(1.0,1.0,1.0,1.0); TheSpotLight->setSpecular(1.0,1.0,1.0,1.0); TheSpotLight->setBeacon(ThePointLightBeaconNode); TheSpotLight->setDirection(Vec3f(0.0,-1.0,0.0)); TheSpotLight->setSpotExponent(5.0); TheSpotLight->setSpotCutOff(1.1); endEditCP(TheSpotLight); NodePtr TheSpotLightNode = Node::create(); beginEditCP(TheSpotLightNode); TheSpotLightNode->setCore(TheSpotLight); endEditCP(TheSpotLightNode); //Load in the Heightmap Image ImagePtr PerlinNoiseImage = createPerlinImage(Vec2s(256,256), Vec2f(10.0f,10.0f),0.5f,1.0f,Vec2f(0.0f,0.0f),0.25f,6,PERLIN_INTERPOLATE_COSINE,false,Image::OSG_L_PF, Image::OSG_UINT8_IMAGEDATA); TextureChunkPtr TheTextureChunk = TextureChunk::create(); beginEditCP(TheTextureChunk); TheTextureChunk->setImage(PerlinNoiseImage); endEditCP(TheTextureChunk); //Lambert Material LambertMaterialPtr TheLambertMat = LambertMaterial::create(); beginEditCP(TheLambertMat, LambertMaterial::ColorFieldMask | LambertMaterial::AmbientColorFieldMask | LambertMaterial::DiffuseFieldMask | LambertMaterial::NumLightsFieldMask | LambertMaterial::DiffuseTextureFieldMask); TheLambertMat->setColor(Color3f(0.0,1.0,0.0)); TheLambertMat->setAmbientColor(Color3f(1.0,0.0,0.0)); TheLambertMat->setDiffuse(0.5); TheLambertMat->setNumLights(1); endEditCP(TheLambertMat, LambertMaterial::ColorFieldMask | LambertMaterial::AmbientColorFieldMask | LambertMaterial::DiffuseFieldMask | LambertMaterial::NumLightsFieldMask | LambertMaterial::DiffuseTextureFieldMask); //Blinn Material TheBlinnMat = BlinnMaterial::create(); beginEditCP(TheBlinnMat, BlinnMaterial::ColorFieldMask | BlinnMaterial::AmbientColorFieldMask | BlinnMaterial::DiffuseFieldMask | BlinnMaterial::SpecularColorFieldMask | BlinnMaterial::SpecularEccentricityFieldMask | BlinnMaterial::SpecularRolloffFieldMask | BlinnMaterial::DiffuseTextureFieldMask); TheBlinnMat->setColor(Color3f(1.0,0.0,0.0)); TheBlinnMat->setAmbientColor(Color3f(0.0,0.0,0.0)); TheBlinnMat->setSpecularColor(Color3f(0.0,0.0,1.0)); TheBlinnMat->setSpecularEccentricity(0.35); TheBlinnMat->setSpecularRolloff(0.85); TheBlinnMat->setDiffuse(0.65); TheBlinnMat->setDiffuseTexture(TheTextureChunk); endEditCP(TheBlinnMat, BlinnMaterial::ColorFieldMask | BlinnMaterial::AmbientColorFieldMask | BlinnMaterial::DiffuseFieldMask | BlinnMaterial::SpecularColorFieldMask | BlinnMaterial::SpecularEccentricityFieldMask | BlinnMaterial::SpecularRolloffFieldMask | BlinnMaterial::DiffuseTextureFieldMask); //Phong Material Phong2MaterialPtr ThePhongMat = Phong2Material::create(); beginEditCP(ThePhongMat, Phong2Material::ColorFieldMask | Phong2Material::AmbientColorFieldMask | Phong2Material::DiffuseFieldMask | Phong2Material::SpecularColorFieldMask | Phong2Material::SpecularCosinePowerFieldMask); ThePhongMat->setColor(Color3f(1.0,0.0,0.0)); ThePhongMat->setAmbientColor(Color3f(0.0,0.0,0.0)); ThePhongMat->setSpecularColor(Color3f(0.0,0.0,1.0)); ThePhongMat->setSpecularCosinePower(50.0); ThePhongMat->setDiffuse(0.65); endEditCP(ThePhongMat, Phong2Material::ColorFieldMask | Phong2Material::AmbientColorFieldMask | Phong2Material::DiffuseFieldMask | Phong2Material::SpecularColorFieldMask | Phong2Material::SpecularCosinePowerFieldMask); //Anisotropic Material AnisotropicMaterialPtr TheAnisotropicMat = AnisotropicMaterial::create(); beginEditCP(TheAnisotropicMat, AnisotropicMaterial::ColorFieldMask | AnisotropicMaterial::AmbientColorFieldMask | AnisotropicMaterial::DiffuseFieldMask | AnisotropicMaterial::SpecularColorFieldMask | AnisotropicMaterial::SpecularRoughnessFieldMask | AnisotropicMaterial::SpecularFresnelIndexFieldMask | AnisotropicMaterial::SpecularSpreadXFieldMask | AnisotropicMaterial::SpecularSpreadYFieldMask); TheAnisotropicMat->setColor(Color3f(1.0,0.0,0.0)); TheAnisotropicMat->setAmbientColor(Color3f(0.0,0.0,0.0)); TheAnisotropicMat->setDiffuse(0.65); TheAnisotropicMat->setSpecularColor(Color3f(0.0,0.0,1.0)); TheAnisotropicMat->setSpecularRoughness(32.0); TheAnisotropicMat->setSpecularFresnelIndex(0.85); TheAnisotropicMat->setSpecularSpreadX(1.0); TheAnisotropicMat->setSpecularSpreadY(1.0); endEditCP(TheAnisotropicMat, AnisotropicMaterial::ColorFieldMask | AnisotropicMaterial::AmbientColorFieldMask | AnisotropicMaterial::DiffuseFieldMask | AnisotropicMaterial::SpecularColorFieldMask | AnisotropicMaterial::SpecularRoughnessFieldMask | AnisotropicMaterial::SpecularFresnelIndexFieldMask | AnisotropicMaterial::SpecularSpreadXFieldMask | AnisotropicMaterial::SpecularSpreadYFieldMask); PointChunkPtr TempChunk = PointChunk::create(); //addRefCP(TempChunk); //Anisotropic Material TheRampMat = RampMaterial::create(); beginEditCP(TheRampMat); //Color TheRampMat->setRampSource(RampMaterial::RAMP_SOURCE_FACING_ANGLE); TheRampMat->getColors().push_back(Color3f(1.0,0.0,0.0)); TheRampMat->getColorPositions().push_back(0.4); TheRampMat->getColorInterpolations().push_back(RampMaterial::RAMP_INTERPOLATION_SMOOTH); TheRampMat->getColors().push_back(Color3f(0.0,1.0,0.0)); TheRampMat->getColorPositions().push_back(1.0); //Transparency TheRampMat->getTransparencies().push_back(Color3f(0.0,0.0,0.0)); TheRampMat->getTransparencyPositions().push_back(0.83); TheRampMat->getTransparencyInterpolations().push_back(RampMaterial::RAMP_INTERPOLATION_SMOOTH); TheRampMat->getTransparencies().push_back(Color3f(1.0,1.0,1.0)); TheRampMat->getTransparencyPositions().push_back(1.0); TheRampMat->setAmbientColor(Color3f(0.0,0.0,0.0)); TheRampMat->setSpecularity(1.0); TheRampMat->setSpecularEccentricity(0.8); TheRampMat->getSpecularColors().push_back(Color3f(1.0,1.0,1.0)); TheRampMat->getSpecularColorPositions().push_back(0.95); TheRampMat->getSpecularColorInterpolations().push_back(RampMaterial::RAMP_INTERPOLATION_SMOOTH); TheRampMat->getSpecularColors().push_back(Color3f(0.0,0.0,1.0)); TheRampMat->getSpecularColorPositions().push_back(1.0); TheRampMat->getSpecularRolloffs().push_back(1.0); TheRampMat->getExtraChunks().push_back(TempChunk); endEditCP(TheRampMat); //Make the Heightmap Geometry HeightmapGeometryPtr TutorialHeightmapGeo = HeightmapGeometry::create(); beginEditCP(TutorialHeightmapGeo, HeightmapGeometry::HeightImageFieldMask | HeightmapGeometry::DimensionsFieldMask | HeightmapGeometry::SegmentsFieldMask | HeightmapGeometry::ScaleFieldMask | HeightmapGeometry::OffsetFieldMask | HeightmapGeometry::MaterialFieldMask); TutorialHeightmapGeo->setHeightImage(PerlinNoiseImage); TutorialHeightmapGeo->setDimensions(Vec2f(200.0,200.0)); TutorialHeightmapGeo->setSegments(Vec2f(150.0,150.0)); TutorialHeightmapGeo->setScale(30.0); TutorialHeightmapGeo->setOffset(0.0); TutorialHeightmapGeo->setMaterial( TheBlinnMat ); endEditCP(TutorialHeightmapGeo, HeightmapGeometry::HeightImageFieldMask | HeightmapGeometry::DimensionsFieldMask | HeightmapGeometry::SegmentsFieldMask | HeightmapGeometry::ScaleFieldMask | HeightmapGeometry::OffsetFieldMask | HeightmapGeometry::MaterialFieldMask); calcVertexNormals(TutorialHeightmapGeo); calcVertexTangents(TutorialHeightmapGeo,0,Geometry::TexCoords7FieldId, Geometry::TexCoords6FieldId); //Make the Heightmap Node NodePtr TutorialHeightmapNode = Node::create(); beginEditCP(TutorialHeightmapNode, Node::CoreFieldMask); TutorialHeightmapNode->setCore(TutorialHeightmapGeo); endEditCP (TutorialHeightmapNode, Node::CoreFieldMask); //Make a SphereNode GeometryPtr SphereGeo = makeSphereGeo(2,50.0); //GeometryPtr SphereGeo = makeCylinderGeo(50,20.0, 16,true,true,true); beginEditCP(SphereGeo, Geometry::MaterialFieldMask); SphereGeo->setMaterial(TheLambertMat); endEditCP (SphereGeo, Geometry::MaterialFieldMask); calcVertexNormals(SphereGeo); calcVertexTangents(SphereGeo,0,Geometry::TexCoords7FieldId, Geometry::TexCoords6FieldId); NodePtr SphereNode = Node::create(); beginEditCP(SphereNode, Node::CoreFieldMask); SphereNode->setCore(SphereGeo); endEditCP (SphereNode, Node::CoreFieldMask); //Make Main Scene Node NodePtr scene = Node::create(); beginEditCP(scene, Node::CoreFieldMask | Node::ChildrenFieldMask); scene->setCore(Group::create()); // add the torus as a child scene->addChild(TutorialHeightmapNode); //scene->addChild(SphereNode); scene->addChild(ThePointLightBeaconNode); endEditCP (scene, Node::CoreFieldMask | Node::ChildrenFieldMask); //Add the scene to the Light Nodes //beginEditCP(ThePointLightNode, Node::ChildrenFieldMask); //ThePointLightNode->addChild(scene); //endEditCP(ThePointLightNode, Node::ChildrenFieldMask); //// tell the manager what to manage //mgr->setRoot (ThePointLightNode); beginEditCP(TheSpotLightNode, Node::ChildrenFieldMask); TheSpotLightNode->addChild(scene); endEditCP(TheSpotLightNode, Node::ChildrenFieldMask); // tell the manager what to manage mgr->setRoot (TheSpotLightNode); mgr->turnHeadlightOff(); // show the whole scene mgr->showAll(); //Open Window Vec2f WinSize(TutorialWindowEventProducer->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindowEventProducer->getDesktopSize() - WinSize) *0.5); TutorialWindowEventProducer->openWindow(WinPos, WinSize, "06Heightmap"); //Main Loop TutorialWindowEventProducer->mainLoop(); osgExit(); return 0; }