Overview
This example shows how to load an OpenFlight geometry file into a DtModelInstance and then add it to the scene. Of particular interest in this example is how to create and initialize a model instance.
Expected Result
Model Instance Result
Example details
To create a basic VR-Vantage application, first instantiate the application, initialize it and finally call run.
DtVrvApplication igApp;
igApp.preInitialize( argc, argv );
igApp.initialize();
... add some content to the application ...
The content that this example application displays is geometry in a DtModelInstance. This application implements a helper function to create and load a DtModelInstance and add the geometry to the scene-graph.
DtModelInstance* loadModelInstanceToTheSceneGraph(DtDe& de)
The function accepts a reference to a display engine (DtDe) where the scene renderer can be found. The display engine passed to this function is retrieved directly from the application.
DtModelInstance* mi = loadModelInstanceToTheSceneGraph( igApp.de() );
To load a geometry file into a DtModelInstance, the model-instance must first be created, then 'realized' with a model-definition. This example uses a DtOsgSimpleModelInstance (derived from DtModelInstance) to load the geometry. The DtModelDefinition holds information on how to load and initialize the geometry. This example only use the DtModelDefinition to specify the geometry file to load.
DtModelDefinition md("theModel");
md.setParameter("filename", sharedDataPath + "/ModelData/Vehicles/FixedWing/DC-10_RED_V7.0/DB_DC10_RED_V7.0.medf" );
DtOsgSimpleModelInstance* mi = new DtOsgSimpleModelInstance(de);
if (! mi->realize(md))
{
delete mi;
return NULL;
This example places the DtModelInstance geometry under a transform node so the model can be moved in the scene.
osg::ref_ptr<osg::PositionAttitudeTransform> pat =
new osg::PositionAttitudeTransform();
pat->addChild(mi->rootNode());
To add the geometry into the VR-Vantage scene, the renderer is retrieved from the display engine and the transform is added to a root of the scene.
DtOsgRenderer& renderer = (DtOsgRenderer&)de.renderer();
renderer.addNodeToRoot(pat, renderer.propRoot());
This example chose to place the geometry under the 'propRoot' of the renderer. Depending on the purpose of the model it could have been placed under one of the other root domains; Environment, Terrain, ModelSets, etc.
Building the Example
VR-Vantage includes pre-built versions of the example application. To build it yourself, follow the instructions at Building VR-Vantage Examples, Applications, and Plug-ins.
Running the Example
This example is an application. You can run it by running ./bin64/exampleModelInstance.exe (on Windows) or ./bin64/exampleModelInstance (on Linux). For more information about running examples, please see Running Applications and Examples.
Learn More
Example Source Files
exampleModelInstance.cxx
#include <osg/PositionAttitudeTransform>
{
md.setParameter("filename", sharedDataPath + "/ModelData/Vehicles/FixedWing/DC-10_RED_V7.0/DB_DC10_RED_V7.0.medf" );
{
delete mi;
return NULL;
}
osg::ref_ptr<osg::PositionAttitudeTransform> pat =
new osg::PositionAttitudeTransform();
pat->setPosition(osg::Vec3(0,100,0));
pat->setAttitude(osg::Quat(
osg::DegreesToRadians(-10.0f), osg::Vec3(1.0f, 0.0f, 0.0f),
osg::DegreesToRadians(-30.0f), osg::Vec3(0.0f, 1.0f, 0.0f),
osg::DegreesToRadians(150.0f), osg::Vec3(0.0f, 0.0f, 1.0f)));
return mi;
}
int main( int argc, char** argv )
{
if( !mi )
return 1;
return 0;
}
Contains makVrv::DtDe class.
Interaction makVrv::DtModelDefinition class.
Contains makVrv::DtOsgEmptySceneLogo class.
Contains makVrv::DtOsgRenderer class.
Contains makVrv::DtOsgSimpleModelInstance class.
Contains makVrv::DtVrvApplication implementation.
The DtDe is the core component of any VR-Vantage application. It owns a DtRenderer,...
Definition DtDe.h:77
virtual const DtDePathConfiguration & dePathConfiguration() const
Return the DtDePathConfiguration.
virtual DtRenderer & renderer() const
Get the renderer.
virtual std::string sharedDataPath() const
A model definition Interaction any number of named parameters, and also can be used to store cached d...
Definition DtModelDefinition.h:45
The base class for all model instances.
Definition DtModelInstance.h:44
static void setEnabled(bool enabled)
This global method will enable or disable the use of an empty scene overlay for all uses of this clas...
virtual osg::Node * rootNode()
Get the model instance's root node.
The DtOsgRenderer is the component responsible for rendering 3D images onto the screen via OpenSceneG...
Definition DtOsgRenderer.h:93
virtual void addNodeToRoot(osg::Node *node, const DtSceneRoot &sr, bool createOnAccess=true)
Add a node to the specified SceneRoot.
static DtSceneRoot propRoot()
A simple OSG model instance.
Definition DtOsgSimpleModelInstance.h:29
virtual bool realize(const DtModelDefinition &definition)
Attempt to realize a definition. If the model instance can't realize the definition it should return ...
The Root IG Application object. To run the IG simply create one, initialize it and call run.
Definition DtVrvApplication.h:58
DtDe & de()
DtDe accessor.
virtual void initialize()
Create the GUI, initialize the DtDe. Call before calling run(). Call preInitialize before this.
virtual void run()
Kick off the IG event loop. This function will block until the application is done running....
virtual void preInitialize(int argc, char **argv)
Pre-initialize Call before calling initialize().
Contains DtCreateSensorFieldOfViewCommand and DtCreateSensorFieldOfViewCommandCreator class declarati...
Definition DtGridLinesSettingsRecord.h:16