OpenFrames Wiki
Real-time interactive 3D graphics API for scientific simulations
Status: Beta
Brought to you by:
ravidavi
/*********************************** Copyright 2018 Ravishankar Mathur Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ***********************************/ #include <OpenFrames/FrameManager.hpp> #include <OpenFrames/Model.hpp> #include <OpenFrames/WindowProxy.hpp> #include <osg/ArgumentParser> #include <osgDB/FileNameUtils> /////////////////////////////////////////////////////////// // // Tutorial 2 - Load and display models with OpenFrames. // /////////////////////////////////////////////////////////// int main( int argc, char** argv ) { // Create the window interface. unsigned int x = 30, y = 30; unsigned int winWidth = 800, winHeight = 600; unsigned int numRows = 1, numCols = 1; osg::ref_ptr<OpenFrames::WindowProxy> myWindow = new OpenFrames::WindowProxy( x, y, winWidth, winHeight, numRows, numCols ); // Create the root reference frame that will hold all specified models. osg::ref_ptr<OpenFrames::ReferenceFrame> rootFrame = new OpenFrames::ReferenceFrame( "Root" ); rootFrame->showAxes( OpenFrames::ReferenceFrame::NO_AXES ); rootFrame->showAxesLabels( OpenFrames::ReferenceFrame::NO_AXES ); rootFrame->showNameLabel( false ); // Create a frame manager for the scene. osg::ref_ptr<OpenFrames::FrameManager> myFrmMgr = new OpenFrames::FrameManager; myFrmMgr->setFrame( rootFrame ); // Now place the scene contained in myFrmMgr at the given location. myWindow->setScene( myFrmMgr, 0, 0 ); // Set up the window title. std::string windowName = "OpenFrames Viewer:"; // // Try to load user-specified files/models. for ( int i=1; i<argc; ++i ) { OpenFrames::Model *theModel = new OpenFrames::Model( "Model", 0.5, 0.5, 0.5, 0.9 ); if ( !theModel->setModel( argv[i] ) ) { continue; } // Add the model's name, sans any extension, to the window's title/name. std::string fname = osgDB::getSimpleFileName( argv[i] ); std::string fname_noext = osgDB::getNameLessAllExtensions( fname ); theModel->setName( fname_noext ); windowName += " " + fname_noext; // Reset model pivot so that its origin coincides with the root scene origin. theModel->setModelPivot( 0.0, 0.0, 0.0 ); // Add the model to the scene. rootFrame->addChild( theModel ); // Create a view for the model. OpenFrames::View *modelView = new OpenFrames::View( rootFrame, theModel ); myWindow->getGridPosition(0, 0)->addView( modelView ); } if ( 0 == rootFrame->getNumChildren() ) { OSG_WARN << std::endl << "No models loaded, exiting." << std::endl; return 1; } myWindow->setWindowName( windowName ); myWindow->startThread(); // Start window animation. myWindow->join(); // Wait for window animation to finish. return 0; }