This DtDistributedDraw driver owns a DtExampleDrawObject, and is responsible for keeping track of the draw object's state and creating or destroying it when the driver is started or stopped.
DtExampleDrawObject is the implementation of the distributed draw object. When a DtExampleDrawObjectAgent is created on the master, an exampleDrawObject is created locally on each display engine.
Building the Example
VR-Vantage includes pre-built versions of the example plug-in. To build it yourself, follow the instructions at Building VR-Vantage Examples, Applications, and Plug-ins.
Running the Example
This example is a plug-in. You can run it by running ./bin64/exampleDistributedDraw_stealth.bat and ./bin64/exampleDistributedDraw_slave.bat (on Windows) or ./bin64/exampleDistributedDraw_stealth.sh and ./bin64/exampleDistributedDraw_slave.sh (on Linux). For more information about running examples, please see Running Applications and Examples.
Press the "F" key to create a sphere.
Example Source Files
DtExampleModel.cxx
#ifndef DtDistributedDrawDriver_H_
#define DtDistributedDrawDriver_H_
using namespace makVrv;
{
public:
virtual void drawRandomSphere();
protected:
virtual bool onStart();
virtual bool onStop();
virtual void slot_displayEngineAdded(
const DtDeRecord& igRecord );
virtual bool onTick();
virtual void updateSphere();
double mySphereX, mySphereY, mySphereZ;
bool mySphereInScene;
};
#endif
DtExampleModel.h
#ifndef DtExampleDrawObject_H_
#define DtExampleDrawObject_H_
#include <osg/Node>
#include <string>
namespace makVrv
{
class DtExampleDrawObject
{
public:
void drawSphere(
double x,
double y,
double z,
double r);
protected:
osg::ref_ptr<osg::Node>
myNode;
};
}
#endif
DtExampleModelInstance.cxx
DtExampleModelInstance.h
#include <boost/bind.hpp>
using namespace makVrv;
{
{
}
}
{
return true;
}
{
if ( obsFrame )
{
}
}
DtExampleModelManager.cxx
#include <osg/Group>
#include <osg/Node>
#include <osg/Geode>
#include <osg/ShapeDrawable>
#include <osg/Material>
namespace makVrv
{
: myDe(de)
, myNode()
{
}
DtExampleDrawObject::~DtExampleDrawObject()
{
if (myNode.valid())
{
removeChildFromAllRoots();
}
}
void DtExampleDrawObject::removeChildFromAllRoots()
{
const DtModelSetRealizationManager& manager = myDe.sharedState().modelSetRealizationManager();
DtModelSetRealizationManager::ModelSetRealizations::const_iterator iter = manager.modelSetRealizations().begin();
DtModelSetRealizationManager::ModelSetRealizations::const_iterator
end = manager.modelSetRealizations().end();
while (iter != end)
{
if (iter->second)
{
((DtOsgRenderer&)myDe.renderer()).removeNodeFromRoot( myNode.get(),
DtOsgRenderer::visualizerTypeRoot( iter->first, 0 ) );
}
++iter;
}
myNode = 0;
}
void DtExampleDrawObject::drawSphere(
double x,
double y,
double z,
double r)
{
if (myNode.valid())
{
removeChildFromAllRoots();
myNode = 0;
}
osg::Geode* geode = new osg::Geode;
geode->addDrawable(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(x,y,z), r)));
myNode = geode;
osg::Material* mat = new osg::Material();
mat->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(0.25, 0.40, 0.55, 1.0));
mat->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4(0.5, 0.8, 0.35, 1.0));
geode->getOrCreateStateSet()->setAttributeAndModes(mat);
const DtModelSetRealizationManager& manager = myDe.sharedState().modelSetRealizationManager();
DtModelSetRealizationManager::ModelSetRealizations::const_iterator iter = manager.modelSetRealizations().begin();
DtModelSetRealizationManager::ModelSetRealizations::const_iterator end = manager.modelSetRealizations().end();
while (iter != end)
{
if (iter->second)
{
((DtOsgRenderer&)myDe.renderer()).addNodeToRoot( myNode.get(),
DtOsgRenderer::visualizerTypeRoot( iter->first, 0 ) );
}
++iter;
}
}
}
DtExampleModelManager.h
#include <stdlib.h>
: DtDriver(agentManager, instanceName)
, myDrawAgent(0)
, mySphereInScene(false)
, mySphereX(0.0)
, mySphereY(0.0)
, mySphereZ(0.0)
{
setAutoStart(true);
myUserControllableFlag = false;
}
{
}
{
}
{
{
}
return true;
}
{
{
}
return true;
}
{
return true;
}
{
if (DtDriver::myStartedFlag)
{
}
}
{
}
{
}