Overview
This example demonstrates how to add a new kind of visualizer to VR-Vantage. To demonstrate, we'll add the ability to draw bullet detonations as bullet hole decals on the terrain.
Expected Result
Bullet Hole Result
Example details
To draw the bullet hole decals we can use a distributed polygon model. Since the simulation often doesn't correlate perfectly with the terrain loaded in VR-Vantage, we'll also need a scene object updater to set the position of the model so that it lines up perfectly with the terrain. The visualizer itself will read the simulated detonation's state and construct the decal and updater to visualize it.
In the plugin's initialization function, we can register the new visualizer and:
DtStateVisualizerFactory::instance(de).addStateVisualizerCreator(de,
new DtBulletHoleVisualizerCreator);
DtAgentFactory::instance(de).registerAgentCreator(
"DtPolygonModel", new DtMovablePolygonModelClassesCreator);
const int bulletHoleVisualTypeId = 976;
DtQtMenuAssembler::instance(de).registerMenu(new DtObserverSettingItem(
de, "BulletHoleItem", bulletHoleVisualTypeId));
DtVisualTypeManager::instance(de).registerVisualType(
DtVisualTypeManager::VisualType("bullet_holes", bulletHoleVisualTypeId,
"../examples/exampleBulletHole/BulletHole.png",
DtVisualTypeManager::ModelSetAll));
if(app)
{
DtMenuPath::menu("DtObserverMenu").item("BulletHoleItem"));
DtToolbarPath::toolbar("DtObserverSettingsToolbar").item("BulletHoleItem"));
}
The Root IG Application object. To run the IG simply create one, initialize it and call run.
Definition DtVrvApplication.h:58
DtMenuConfiguration & masterModeMenuConfiguration()
Get the menu configuration which may be altered by plugins.
static DtVrvApplication * findFromDe(DtDe &)
DtToolbarConfiguration & masterModeToolbarConfiguration()
Get the toolbar configuration which may be altered by plugins.
In the GUI, we can create a new visual definition and map bullet detonations to the bullet hole visualizer. For more information see the comment in DtBulletHoleVisualizer.h. Once this is done, the visualizer will be created whenever the simulation reports a bullet detonation interaction. In turn, the visualizer will create its model and updater according to its visual definition:
DtBulletHoleVisualizer::DtBulletHoleVisualizer( DtBaseConnection& simulation,
DtStateListener& listener, DtSceneObjectAgent* sceneObject, DtModelSetId modelSet )
: DtStateVisualizer( simulation, listener, sceneObject, modelSet )
, myPolygonAgent( 0 )
, myDetonationSceneObjectAgent( nullptr )
, myRadius( 1 )
{
}
DtBulletHoleVisualizer::~DtBulletHoleVisualizer()
{
destroyModelAgents();
}
void DtBulletHoleVisualizer::createModelAgents()
{
if (((DtVrlinkDetonationInteractionStateListener*)&myListener)->detonationResult()
== DtDetResGroundImpact)
{
createBulletHole();
}
}
void DtBulletHoleVisualizer::destroyModelAgents()
{
if ( myDetonationSceneObjectAgent )
{
mySimulation.temporaryEffects().takeAgent( myDetonationSceneObjectAgent, 60, 0);
myDetonationSceneObjectAgent = nullptr;
}
if (myPolygonAgent)
{
mySimulation.temporaryEffects().takeAgent(myPolygonAgent, 60, 0);
myPolygonAgent = nullptr;
}
}
void DtBulletHoleVisualizer::setInitialValuesFromVisualizerDefinition()
{
if( myVisualizerDefinition )
{
const DtVisualizerAttributeFilename* texFile = dynamic_cast<const DtVisualizerAttributeFilename*>(
myVisualizerDefinition->findAttribute( "texture" ));
if( texFile )
{
myTexture = texFile->value().toAscii();
}
const DtVisualizerAttributeFloat* radius = dynamic_cast<const DtVisualizerAttributeFloat*>(
myVisualizerDefinition->findAttribute( "radius" ));
if( radius )
{
myRadius = radius->value();
}
else
{
myRadius = 1;
}
}
DtStateVisualizer::setInitialValuesFromVisualizerDefinition();
}
void DtBulletHoleVisualizer::setModelDefinitionForAgents()
{
}
void DtBulletHoleVisualizer::setParent(DtStateVisualizer*)
{
}
void DtBulletHoleVisualizer::createBulletHole()
{
DtVrlinkDetonationInteractionStateListener* detStateListener =
(DtVrlinkDetonationInteractionStateListener*)&myListener;
if(!myDetonationSceneObjectAgent)
{
myDetonationSceneObjectAgent = DtSceneObjectAgent::create(mySimulation.sceneInterface(), myDistributeFlag);
myDetonationSceneObjectAgent->setModelSet(myModelSet);
}
myPolygonAgent = DtPolygonModelAgent::create(mySimulation.sceneInterface(), myDistributeFlag);
myDetonationSceneObjectAgent->addModel(myPolygonAgent, myVisualizerType);
myDetonationSceneObjectAgent->setPosition(1, DtVector(-myRadius, -myRadius, 0.1));
myDetonationSceneObjectAgent->setPosition(2, DtVector(myRadius , -myRadius, 0.1));
myDetonationSceneObjectAgent->setPosition(3, DtVector(myRadius , myRadius, 0.1));
myDetonationSceneObjectAgent->setPosition(4, DtVector(-myRadius , myRadius, 0.1));
DtBulletHoleUpdaterAgent* updater = DtBulletHoleUpdaterAgent::create(mySimulation.sceneInterface(), myDistributeFlag);
updater->setSceneObject( myDetonationSceneObjectAgent );
updater->setBulletSource(detStateListener->sourceId());
updater->setBulletEnd(detStateListener->location());
myPolygonAgent->setNumTextureTiles(1);
myPolygonAgent->setTexturePath(myTexture);
}
const DtStateVisualizer::TypeInfo& DtBulletHoleVisualizer::typeInfo() const
{
return theTypeInfo();
}
const DtStateVisualizer::TypeInfo& DtBulletHoleVisualizer::theTypeInfo()
{
static DtVisualizerSchema* schema = 0;
if (!schema)
{
schema = new DtVisualizerSchema("DtBulletHoleVisualizer",
DtUnicode::tr("Detonation Bullet Holes"));
DtVisualizerSchema::Parameter param;
param.myName = "texture";
param.myScreenName = DtUnicode::tr("Texture");
param.myDescription = DtUnicode::tr("Texture file for the bullet hole decals");
param.myRequired = true;
param.myVisualizerAttributeTypeInfoName = DtVisualizerAttributeFilename::theTypeInfo().className;
schema->addParameter(param);
param.myName = "radius";
param.myScreenName = DtUnicode::tr("Radius");
param.myDescription = DtUnicode::tr("Radius in meters of the bullet hole decals");
param.myRequired = false;
param.myVisualizerAttributeTypeInfoName = DtVisualizerAttributeFloat::theTypeInfo().className;
schema->addParameter(param);
}
static DtStateVisualizer::TypeInfo thisTypeInfo(
"DtBulletHoleVisualizer",
DtUnicode::tr("Bullet Hole Visualizer"),
InteractionVisualizerType,
*schema);
return thisTypeInfo;
}
To place the bullet hole decal, we will make a vector from the shooter to the detonation and intersect it with the terrain. The bullet hole decal will be placed at the location of that intersection and rotated to have the same normal vector. Since intersections require access to the current scene graph, we use an updater to do the calculation:
void DtBulletHoleUpdater::update( double simTime )
{
if (myDirty)
{
DtVector bulletSource;
DtAgentUpdateResolverInterface* resolver =
myDe.agentManager().findUpdater( mySource );
if( resolver )
{
DtSceneObject* sceneObject = resolver->
castObjectTypeFromUpdater<DtSceneObject>( "DtSceneObject" );
if ( sceneObject )
{
sceneObject->getPosition(0, bulletSource);
}
}
DtSceneObject* bulletSceneObject = findActiveSceneObject();
if( !bulletSceneObject )
{
return;
}
if ( myIntersector == nullptr )
{
myIntersector = DtIntersectorCreator::instance(myDe).create(myDe, bulletSceneObject->modelSet());
}
DtVector trajectory = myEnd - bulletSource;
DtVector segStart = bulletSource + DtVector(trajectory.x()*0.5, trajectory.y()*0.5, trajectory.z()*0.5);
DtVector segmentEnd = segStart + trajectory;
DtIntersectorResult isectResult;
bool hit = myIntersector->findFirstIntersectWithLineSegment(
segStart.x(), segStart.y(), segStart.z(),
segmentEnd.x(), segmentEnd.y(), segmentEnd.z(),
isectResult, DtIntersector::SupportNodes);
if (hit)
{
bulletSceneObject->setVisible(true);
bulletSceneObject->setPosition(0, DtVector(isectResult.x, isectResult.y, isectResult.z));
DtTaitBryan orientation;
DtVector localDown;
DtVecNeg( DtVector(isectResult.normalX, isectResult.normalY, isectResult.normalZ), localDown );
DtDcm localOriDcm( orientation );
DtVector frontVec;
frontVec[0] = localOriDcm[1][0];
frontVec[1] = localOriDcm[0][0];
frontVec[2] = -localOriDcm[2][0];
DtVector rightVec = localDown.crossProduct( frontVec );
DtVecNormalize( rightVec, rightVec );
frontVec = rightVec.crossProduct( localDown );
DtVecNormalize( frontVec, frontVec );
DtDcm resultDcm;
register double* resDcmPtr = &resultDcm[0][0];
*resDcmPtr++ = frontVec[1];
*resDcmPtr++ = rightVec[1];
*resDcmPtr++ = localDown[1];
*resDcmPtr++ = frontVec[0];
*resDcmPtr++ = rightVec[0];
*resDcmPtr++ = localDown[0];
*resDcmPtr++ = -frontVec[2];
*resDcmPtr++ = -rightVec[2];
*resDcmPtr = -localDown[2];
DtTaitBryan result;
DtBodyToRef_to_Euler( resultDcm, &result );
bulletSceneObject->setOrientation(0, result);
}
else
{
bulletSceneObject->setVisible(false);
}
myDirty = false;
}
}
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/exampleBulletHole_stealth.bat (on Windows) or ./bin64/exampleBulletHole_stealth.sh (on Linux). In Vantage go to menu "Settings->Visual Model Editors..", in "Interaction Definition Editor" select "BulletDetonation". With the "+" sign on the right panel, add a new "Detonation Bullet Holes" for the "Model Sets=3D Models" visualizer. After that, add the following "Visualizer Definition Attributes"; "type=DtBulletHoleVisualizer", "texture=(path to your VRV installation)/examples/exampleBulletHole/BulletHole.png", "radius=0.4". Load ground_DB II Terrain in Vantage. Connect Vantage with DIS. Open VRForce with a empty scenario (connect with DIS), load ground_DB II. Add a "Chilian M16" Character near a building in VRForce. Hit play, select the "Chilian M16" right click on him and select "Task->Engagement->Provide Suppresive Fire at Location...", Click on the building and click the ok button on the popup menu. You should then see the bullet detonation in Vantage on the building. For more information about running examples, please see Running Applications and Examples.
Example Source Files
DtBulletHoleUpdater.cxx
#include <boost/lexical_cast.hpp>
#include <matrix/vlMath.h>
{
: DtSceneObjectUpdater(de, id)
, mySource(0)
, myEnd(0, 0, 0)
, myDirty(false)
{
}
DtBulletHoleUpdater::~DtBulletHoleUpdater()
{
}
void DtBulletHoleUpdater::setEnabled( bool enabled )
{
}
void DtBulletHoleUpdater::update( double simTime )
{
if (myDirty)
{
DtVector bulletSource;
DtAgentUpdateResolverInterface* resolver =
myDe.agentManager().findUpdater( mySource );
if( resolver )
{
DtSceneObject* sceneObject = resolver->
castObjectTypeFromUpdater<DtSceneObject>( "DtSceneObject" );
if ( sceneObject )
{
sceneObject->getPosition(0, bulletSource);
}
}
DtSceneObject* bulletSceneObject = findActiveSceneObject();
if( !bulletSceneObject )
{
return;
}
if ( myIntersector == nullptr )
{
myIntersector = DtIntersectorCreator::instance(myDe).create(myDe, bulletSceneObject->modelSet());
}
DtVector trajectory = myEnd - bulletSource;
DtVector segStart = bulletSource + DtVector(trajectory.x()*0.5, trajectory.y()*0.5, trajectory.z()*0.5);
DtVector segmentEnd = segStart + trajectory;
DtIntersectorResult isectResult;
bool hit = myIntersector->findFirstIntersectWithLineSegment(
segStart.x(), segStart.y(), segStart.z(),
segmentEnd.x(), segmentEnd.y(), segmentEnd.z(),
isectResult, DtIntersector::SupportNodes);
if (hit)
{
bulletSceneObject->setVisible(true);
bulletSceneObject->setPosition(0, DtVector(isectResult.x, isectResult.y, isectResult.z));
DtTaitBryan orientation;
DtVector localDown;
DtVecNeg( DtVector(isectResult.normalX, isectResult.normalY, isectResult.normalZ), localDown );
DtDcm localOriDcm( orientation );
DtVector frontVec;
frontVec[0] = localOriDcm[1][0];
frontVec[1] = localOriDcm[0][0];
frontVec[2] = -localOriDcm[2][0];
DtVector rightVec = localDown.crossProduct( frontVec );
DtVecNormalize( rightVec, rightVec );
frontVec = rightVec.crossProduct( localDown );
DtVecNormalize( frontVec, frontVec );
DtDcm resultDcm;
register double* resDcmPtr = &resultDcm[0][0];
*resDcmPtr++ = frontVec[1];
*resDcmPtr++ = rightVec[1];
*resDcmPtr++ = localDown[1];
*resDcmPtr++ = frontVec[0];
*resDcmPtr++ = rightVec[0];
*resDcmPtr++ = localDown[0];
*resDcmPtr++ = -frontVec[2];
*resDcmPtr++ = -rightVec[2];
*resDcmPtr = -localDown[2];
DtTaitBryan result;
DtBodyToRef_to_Euler( resultDcm, &result );
bulletSceneObject->setOrientation(0, result);
}
else
{
bulletSceneObject->setVisible(false);
}
myDirty = false;
}
}
void DtBulletHoleUpdater::setBulletEnd( const DtVector& end)
{
myEnd = end;
myDirty = true;
}
void DtBulletHoleUpdater::setBulletSource( DtUniqueID sourceId )
{
mySource = sourceId;
myDirty = true;
}
}
Contains makVrv:DtAgentManager class.
Contains makVrv::DtBulletHoleUpdater class.
Contains makVrv::DtDe class.
Contains makVrv::DtDeSharedState class.
Contains makVrv:DtDisplay class.
Contains makVrv:DtIntersector class.
Contains makVrv::DtSceneObject class.
Contains the declaration for makVrv::DtTickableManagerInterface.
DtBulletHoleUpdater(DtDe &de, DtUniqueID id)
CTOR.
Contains DtCreateSensorFieldOfViewCommand and DtCreateSensorFieldOfViewCommandCreator class declarati...
Definition DtGridLinesSettingsRecord.h:16
DtBulletHoleUpdater.h
#pragma once
#include <string>
#include <matrix/vlVector.h>
#include <matrix/vlTaitBryan.h>
{
class DtIntersector;
{
public:
DtBulletHoleUpdater(DtDe& de, DtUniqueID id);
virtual ~DtBulletHoleUpdater();
virtual void update( double simTime );
virtual void setEnabled(bool enabled);
virtual void setBulletEnd(const DtVector& end);
virtual void setBulletSource(DtUniqueID sourceId);
protected:
DtUniqueID mySource;
DtVector myEnd;
bool myDirty;
DtIntersector* myIntersector = nullptr;
};
}
Contains the declaration for makVrv::DtSceneObjectUpdater.
Contains DLL export macros.
#define DT_DLL_EXAMPLEBULLETHOLE
Definition exampleBulletHole.h:18
DtBulletHoleUpdaterAgent.cpp
#include <../examples/exampleBulletHole/DtBulletHoleUpdaterAgent.hpp>
{
{
}
{
if(!castedAgent)
{
delete agent;
}
return castedAgent;
}
{
}
{
}
{
}
}
DtAgentManagerInterface & sceneInterface()
Definition DtAgent.inl:18
The abstract interface necessary for agents.
Definition DtAgentManagerInterface.h:34
virtual DtAgent * createNewObject(const std::string &objectClass, bool bDistribute)
Create a new object, and return a driver to that object. Deleting the driver will automatically destr...
virtual ~DtBulletHoleUpdaterAgent()
DTOR.
DtBulletHoleUpdater * findObject()
Attempt to find the actual object the agent is controlling. warning Any modifications to the actual o...
virtual DtBulletHoleUpdater * findObjectAsDtBulletHoleUpdater()=0
DtBulletHoleUpdaterAgent()
CTOR.
static DtBulletHoleUpdaterAgent * create(makVrv::DtAgentManagerInterface &sceneInterface, bool bDistribute=true)
Static helper creator.
Definition DtBulletHoleUpdater.h:31
DtBulletHoleUpdaterAgent.hpp
#pragma once
class DtTaitBryan;
{
class DtBulletHoleUpdater;
{
public:
DtBulletHoleUpdaterAgent();
virtual ~DtBulletHoleUpdaterAgent();
DtBulletHoleUpdater* findObject();
const DtBulletHoleUpdater* findObject() const;
virtual void setBulletSource(DtUniqueID sourceId) = 0;
virtual void setBulletEnd(const DtVector64& end) = 0;
protected:
virtual DtBulletHoleUpdater* findObjectAsDtBulletHoleUpdater() = 0;
};
}
DtBulletHoleUpdaterClasses.cpp
#include <../examples/exampleBulletHole/DtBulletHoleUpdaterAgent.hpp>
{
class DT_DLL_EXAMPLEBULLETHOLE DtBulletHoleUpdaterAgentImplementation :
public virtual DtBulletHoleUpdaterAgent ,
public DtSceneObjectUpdaterAgentImplementation
{
public:
DtBulletHoleUpdaterAgentImplementation();
virtual ~DtBulletHoleUpdaterAgentImplementation();
virtual void setBulletSource(DtUniqueID sourceId);
virtual void setBulletEnd(const DtVector64& end);
protected:
virtual DtSceneObjectUpdater* findObjectAsDtSceneObjectUpdater();
virtual DtBulletHoleUpdater* findObjectAsDtBulletHoleUpdater();
};
}
{
{
public:
DtBulletHoleUpdaterClassDefinition(const std::string& className = "DtBulletHoleUpdater");
virtual ~DtBulletHoleUpdaterClassDefinition();
enum FunctionIds
{
function_setBulletSource = DtSceneObjectUpdaterClassDefinition::end_FunctionIds,
function_setBulletEnd,
end_FunctionIds
};
};
}
{
{
public:
DtBulletHoleUpdaterClassesCreator();
virtual ~DtBulletHoleUpdaterClassesCreator();
static makVrv::DtAgentCreator* create();
virtual makVrv::DtAgent* createAgent(makVrv::DtAgentManagerInterface& sceneInterface);
virtual makVrv::DtAgentUpdateResolverInterface* createResolver(makVrv::DtDe& de,
makVrv::DtUniqueID id);
protected:
DtBulletHoleUpdaterClassDefinition* myDefinition;
static bool theRegisteredFlag;
static makVrv::DtAgentFactory::DtAutoUnregistrar theAutoUnregistrar;
};
}
#include <matrix/vlVector.h>
#include <matrix/vlTaitBryan.h>
{
{
}
{
}
{
}
{
makVrv::DtAgentManager* agentManager =
dynamic_cast<makVrv::DtAgentManager*
>(
mySceneInterface);
if(agentManager)
{
makVrv::DtAgentUpdateResolver<DtBulletHoleUpdater>* actualUpdater = dynamic_cast<makVrv::DtAgentUpdateResolver<DtBulletHoleUpdater>*>(updater);
if(actualUpdater)
{
return actualUpdater->
object();
}
}
return 0;
}
{
}
{
}
}
{
{
myClassName = "DtBulletHoleUpdater";
bindFunction(function_setBulletSource,
makVrv::bindMember((
void (DtBulletHoleUpdater::*)(DtUniqueID))&DtBulletHoleUpdater::setBulletSource));
bindFunction(function_setBulletEnd,
makVrv::bindMember((
void (DtBulletHoleUpdater::*)(
const DtVector64&))&DtBulletHoleUpdater::setBulletEnd));
}
DtBulletHoleUpdaterClassDefinition::~DtBulletHoleUpdaterClassDefinition()
{
}
}
#include <exception>
{
{
}
DtBulletHoleUpdaterClassesCreator::~DtBulletHoleUpdaterClassesCreator()
{
delete myDefinition;
}
{
return new DtBulletHoleUpdaterClassesCreator();
}
{
return new DtBulletHoleUpdaterAgentImplementation();
}
{
}
}
Contains makVrv::DtAgentCreator class.
Contains makVrv::DtAgentFactory class.
Contains makVrv::DtAgentUpdateResolver class.
Abstract base class for the scene object creators. SceneObject creators do not actually create scene ...
Definition DtAgentCreator.h:28
static bool autoRegister(const std::string &className, AutoRegisterFunction function)
Auto-Register.
void queueOperationCall(unsigned int state_function, void(C::*m)())
Definition DtAgent.inl:109
std::string myClassName
Definition DtAgent.h:146
DtUniqueID myUniqueId
Definition DtAgent.h:145
DtAgentManagerInterface * mySceneInterface
Definition DtAgent.h:144
virtual DtAgentUpdateResolverInterface * findUpdater(DtUniqueID id)
Find the update handler for a particular object id.
DtAgentUpdateResolver updates an instance of an object using is definition.
Definition DtAgentUpdateResolver.h:24
ObjectType * object()
Get a pointer to the actual object this updater updates.
Definition DtAgentUpdateResolver.inl:42
Abstract base class for object updaters.
Definition DtAgentUpdateResolverInterface.h:21
virtual void setBulletSource(DtUniqueID sourceId)
DtBulletHoleUpdaterAgentImplementation()
CTOR.
virtual ~DtBulletHoleUpdaterAgentImplementation()
DTOR.
virtual DtSceneObjectUpdater * findObjectAsDtSceneObjectUpdater()
virtual DtBulletHoleUpdater * findObjectAsDtBulletHoleUpdater()
virtual void setBulletEnd(const DtVector64 &end)
Definition class for the scene object class: DtBulletHoleUpdater.
Definition DtBulletHoleUpdaterClasses.hpp:59
@ function_setBulletSource
Definition DtBulletHoleUpdaterClasses.hpp:70
@ function_setBulletEnd
Definition DtBulletHoleUpdaterClasses.hpp:71
DtBulletHoleUpdaterClassDefinition(const std::string &className="DtBulletHoleUpdater")
CTOR- all functions pointers are binded in the CTOR.
Creator class for the scene object class: DtBulletHoleUpdater.
Definition DtBulletHoleUpdaterClasses.hpp:92
DtBulletHoleUpdaterClassesCreator()
CTOR.
static makVrv::DtAgentFactory::DtAutoUnregistrar theAutoUnregistrar
Definition DtBulletHoleUpdaterClasses.hpp:113
static bool theRegisteredFlag
Definition DtBulletHoleUpdaterClasses.hpp:112
static makVrv::DtAgentCreator * create()
virtual void setBulletSource(DtUniqueID sourceId)
Set the unique ID of the entity that fired the bullet.
virtual void setBulletEnd(const DtVector &end)
Set the bullet's trajectory, relative to the shot's origin.
The DtDe is the core component of any VR-Vantage application. It owns a DtRenderer,...
Definition DtDe.h:77
Definition DtAgentDefinition.h:86
Definition class for the scene object class: DtSceneObjectUpdater.
Definition DtSceneObjectUpdaterClasses.hpp:89
Scene Object Updater.
Definition DtSceneObjectUpdater.h:41
Contains additional type to message encoding functions.
DtMessageMemberCall< C > * bindMember(void(C::*m)())
Definition DtMessageMemberCall.h:121
unsigned long long DtUniqueID
Definition DtUniqueID.h:19
DtBulletHoleUpdaterClasses.hpp
#pragma once
#include <../examples/exampleBulletHole/DtBulletHoleUpdaterAgent.hpp>
{
class DT_DLL_EXAMPLEBULLETHOLE DtBulletHoleUpdaterAgentImplementation :
public virtual DtBulletHoleUpdaterAgent ,
public DtSceneObjectUpdaterAgentImplementation
{
public:
DtBulletHoleUpdaterAgentImplementation();
virtual ~DtBulletHoleUpdaterAgentImplementation();
virtual void setBulletSource(DtUniqueID sourceId);
virtual void setBulletEnd(const DtVector64& end);
protected:
virtual DtSceneObjectUpdater* findObjectAsDtSceneObjectUpdater();
virtual DtBulletHoleUpdater* findObjectAsDtBulletHoleUpdater();
};
}
{
{
public:
DtBulletHoleUpdaterClassDefinition(const std::string& className = "DtBulletHoleUpdater");
virtual ~DtBulletHoleUpdaterClassDefinition();
enum FunctionIds
{
function_setBulletSource = DtSceneObjectUpdaterClassDefinition::end_FunctionIds,
function_setBulletEnd,
end_FunctionIds
};
};
}
{
{
public:
DtBulletHoleUpdaterClassesCreator();
virtual ~DtBulletHoleUpdaterClassesCreator();
static makVrv::DtAgentCreator* create();
virtual makVrv::DtAgent* createAgent(makVrv::DtAgentManagerInterface& sceneInterface);
virtual makVrv::DtAgentUpdateResolverInterface* createResolver(makVrv::DtDe& de,
makVrv::DtUniqueID id);
protected:
DtBulletHoleUpdaterClassDefinition* myDefinition;
static bool theRegisteredFlag;
static makVrv::DtAgentFactory::DtAutoUnregistrar theAutoUnregistrar;
};
}
DtBulletHoleVisualizer.inl
#ifndef DtBulletHoleVisualizer_INL_
#error This file may only be included by DtBulletHoleVisualizer.h
#endif
{
{
DtStateListener& listener, DtSceneObjectAgent* sceneObject, DtModelSetId modelSet )
: DtStateVisualizer( simulation, listener, sceneObject, modelSet )
, myPolygonAgent( 0 )
, myDetonationSceneObjectAgent( nullptr )
, myRadius( 1 )
{
}
DtBulletHoleVisualizer::~DtBulletHoleVisualizer()
{
destroyModelAgents();
}
void DtBulletHoleVisualizer::createModelAgents()
{
if (((DtVrlinkDetonationInteractionStateListener*)&myListener)->detonationResult()
== DtDetResGroundImpact)
{
createBulletHole();
}
}
void DtBulletHoleVisualizer::destroyModelAgents()
{
if ( myDetonationSceneObjectAgent )
{
mySimulation.temporaryEffects().takeAgent( myDetonationSceneObjectAgent, 60, 0);
myDetonationSceneObjectAgent = nullptr;
}
if (myPolygonAgent)
{
mySimulation.temporaryEffects().takeAgent(myPolygonAgent, 60, 0);
myPolygonAgent = nullptr;
}
}
void DtBulletHoleVisualizer::setInitialValuesFromVisualizerDefinition()
{
if( myVisualizerDefinition )
{
const DtVisualizerAttributeFilename* texFile = dynamic_cast<const DtVisualizerAttributeFilename*>(
myVisualizerDefinition->findAttribute( "texture" ));
if( texFile )
{
myTexture = texFile->value().toAscii();
}
const DtVisualizerAttributeFloat* radius = dynamic_cast<const DtVisualizerAttributeFloat*>(
myVisualizerDefinition->findAttribute( "radius" ));
if( radius )
{
myRadius = radius->value();
}
else
{
myRadius = 1;
}
}
DtStateVisualizer::setInitialValuesFromVisualizerDefinition();
}
void DtBulletHoleVisualizer::setModelDefinitionForAgents()
{
}
void DtBulletHoleVisualizer::setParent(DtStateVisualizer*)
{
}
void DtBulletHoleVisualizer::createBulletHole()
{
DtVrlinkDetonationInteractionStateListener* detStateListener =
(DtVrlinkDetonationInteractionStateListener*)&myListener;
if(!myDetonationSceneObjectAgent)
{
myDetonationSceneObjectAgent = DtSceneObjectAgent::create(mySimulation.sceneInterface(), myDistributeFlag);
myDetonationSceneObjectAgent->setModelSet(myModelSet);
}
myPolygonAgent = DtPolygonModelAgent::create(mySimulation.sceneInterface(), myDistributeFlag);
myDetonationSceneObjectAgent->addModel(myPolygonAgent, myVisualizerType);
myDetonationSceneObjectAgent->setPosition(1, DtVector(-myRadius, -myRadius, 0.1));
myDetonationSceneObjectAgent->setPosition(2, DtVector(myRadius , -myRadius, 0.1));
myDetonationSceneObjectAgent->setPosition(3, DtVector(myRadius , myRadius, 0.1));
myDetonationSceneObjectAgent->setPosition(4, DtVector(-myRadius , myRadius, 0.1));
DtBulletHoleUpdaterAgent* updater = DtBulletHoleUpdaterAgent::create(mySimulation.sceneInterface(), myDistributeFlag);
updater->setSceneObject( myDetonationSceneObjectAgent );
updater->setBulletSource(detStateListener->sourceId());
updater->setBulletEnd(detStateListener->location());
myPolygonAgent->setNumTextureTiles(1);
myPolygonAgent->setTexturePath(myTexture);
}
const DtStateVisualizer::TypeInfo& DtBulletHoleVisualizer::typeInfo() const
{
return theTypeInfo();
}
const DtStateVisualizer::TypeInfo& DtBulletHoleVisualizer::theTypeInfo()
{
static DtVisualizerSchema* schema = 0;
if (!schema)
{
schema = new DtVisualizerSchema("DtBulletHoleVisualizer",
DtUnicode::tr("Detonation Bullet Holes"));
DtVisualizerSchema::Parameter param;
param.myName = "texture";
param.myScreenName = DtUnicode::tr("Texture");
param.myDescription = DtUnicode::tr("Texture file for the bullet hole decals");
param.myRequired = true;
param.myVisualizerAttributeTypeInfoName = DtVisualizerAttributeFilename::theTypeInfo().className;
schema->addParameter(param);
param.myName = "radius";
param.myScreenName = DtUnicode::tr("Radius");
param.myDescription = DtUnicode::tr("Radius in meters of the bullet hole decals");
param.myRequired = false;
param.myVisualizerAttributeTypeInfoName = DtVisualizerAttributeFloat::theTypeInfo().className;
schema->addParameter(param);
}
static DtStateVisualizer::TypeInfo thisTypeInfo(
"DtBulletHoleVisualizer",
DtUnicode::tr("Bullet Hole Visualizer"),
InteractionVisualizerType,
*schema);
return thisTypeInfo;
}
}
}
Contains makVrv:DtBaseConnection class.
Contains the DtDetonationElementProcessor class declaration.
Contains makVrv::DtForceManager class.
Contains makVrv::DtTemporaryAgentManager class.
Contains the DtVrlinkDetonationInteractionStateListener class declaration.
DtBulletHoleVisualizer(DtBaseConnection &simulation, DtStateListener &listener, DtSceneObjectAgent *sceneObject, DtModelSetId modelSet)
Definition DtBulletHoleVisualizer.inl:34
#define DT_PROTOCOL_NAMESPACE
Definition vrvAudioShared/dllExport.h:43
DtBulletHoleVisualizer.h
#pragma once
{
class DtPolygonModelAgent;
class DtSceneObjectAgent;
{
public DtStateVisualizer
{
public:
DtBulletHoleVisualizer( DtBaseConnection& simulation,
DtStateListener& listener, DtSceneObjectAgent* sceneObject, DtModelSetId modelSet );
virtual ~DtBulletHoleVisualizer();
virtual void setParent(DtStateVisualizer*);
virtual void createModelAgents();
virtual void destroyModelAgents();
virtual void setInitialValuesFromVisualizerDefinition() override;
virtual void setModelDefinitionForAgents();
virtual const DtStateVisualizer::TypeInfo& typeInfo() const;
static const DtStateVisualizer::TypeInfo& theTypeInfo();
protected:
virtual void createBulletHole();
protected:
std::string myTexture;
float myRadius;
DtPolygonModelAgent* myPolygonAgent;
DtSceneObjectAgent* myDetonationSceneObjectAgent;
};
typedef DtStateVisualizerCreatorTemplate<DtBulletHoleVisualizer>
}
}
#define DtBulletHoleVisualizer_INL_
#undef DtBulletHoleVisualizer_INL_
DetonationLine makVrv:DtBulletHoleVisualizer class. This class will create a permanant effect....
Contains makVrv:DtStateVisualizer class.
DtStateVisualizerCreatorTemplate< DtBulletHoleVisualizer > DtBulletHoleVisualizerCreator
Bullet hole visualizer creator.
Definition DtBulletHoleVisualizer.h:136
DtMovablePolygonModel.cxx
#include <osg/Geometry>
#include <osgDB/ReadFile>
#include <osg/AlphaFunc>
{
: DtOsgPolygonModel(de, id)
{
DtModelInstance* mi =
new DtMovablePolygonModelInstance(myDe);
setModelInstance(0);
setModelInstance(mi);
signal_modelInstanceCreated( mi, this );
osg::StateSet* ss = static_cast<DtOsgModelInstance*>(mi)->rootNode()->getOrCreateStateSet();
ss->setMode(GL_ALPHA_TEST, osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE);
ss->setAttributeAndModes(new osg::AlphaFunc(osg::AlphaFunc::GREATER, 0.3), osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE);
mi->enableColorBlending(true);
}
DtMovablePolygonModel::~DtMovablePolygonModel()
{
}
void DtMovablePolygonModel::setVisible(bool isVisible)
{
DtModel::setVisible(isVisible);
mySceneConnector->setVisible(isVisible);
}
void DtMovablePolygonModel::setPosition( int vtx, const DtVector& position )
{
if (vtx == 0)
{
mySceneConnector->setPosition(position);
}
else
{
DtPolygonModelInstance* mi =
dynamic_cast<DtPolygonModelInstance*>(modelInstance());
if (mi)
{
mi->setPosition(vtx - 1, position);
}
}
}
void DtMovablePolygonModel::setOrientation( int vtx, const DtTaitBryan& orientation )
{
if (vtx == 0)
{
mySceneConnector->setOrientation(orientation);
}
else
{
DtPolygonModelInstance* mi =
dynamic_cast<DtPolygonModelInstance*>(modelInstance());
if (mi)
{
mi->setOrientation(vtx - 1, orientation);
}
}
}
void DtMovablePolygonModel::DtMovablePolygonModelInstance::addToConnector( DtOsgSceneConnector* connector )
{
osg::Group* parent = connector->getOrCreateTransformRoot();
if (!parent->containsNode(myGeode.get()))
{
parent->addChild(myGeode.get());
}
}
void DtMovablePolygonModel::update()
{
bool localMyNeedsUpdate = myNeedsUpdate;
DtOsgPolygonModel::update();
if (localMyNeedsUpdate)
{
DtPolygonModelInstance* mi =
dynamic_cast<DtPolygonModelInstance*>(modelInstance());
osg::Geode* geode = static_cast<osg::Geode*>(mi->rootNode());
if (geode->getNumDrawables()>0)
{
osg::BoundingBox bb;
bb._min = osg::Vec3f(-1,-1,-1);
bb._max = osg::Vec3f(1,1,1);
geode->getDrawable(0)->setInitialBound(bb);
geode->getDrawable(0)->getBound();
}
}
}
}
Contains makVrv::DtMovablePolygonModel class.
DtMovablePolygonModel(DtDe &de, DtUniqueID &id)
DtMovablePolygonModel.h
#pragma once
{
class DtDe;
class DtOsgSceneConnector;
: public DtOsgPolygonModel
{
public:
class DtMovablePolygonModelInstance : public DtPolygonModelInstance
{
public:
DtMovablePolygonModelInstance( DtDe& de )
: DtPolygonModelInstance(de)
{
}
virtual ~DtMovablePolygonModelInstance()
{
}
virtual void addToConnector( DtOsgSceneConnector* connector );
};
DtMovablePolygonModel(DtDe& de, DtUniqueID& id);
virtual ~DtMovablePolygonModel();
virtual void setVisible(bool isVisible);
virtual void setPosition( int vtx, const DtVector& position );
virtual void setOrientation( int vtx, const DtTaitBryan& orientation );
protected:
virtual void update();
};
}
Contains makVrv::DtOsgPolygonModel class.
Contains makVrv::DtOsgSceneConnector class.
Contains makVrv::DtPolygonModelInstance class.
Contains makVrv::DtUniqueID type.
DtMovablePolygonModelAgent.cpp
#include <../examples/exampleBulletHole/DtMovablePolygonModelAgent.hpp>
{
{
}
{
if(!castedAgent)
{
delete agent;
}
return castedAgent;
}
{
}
{
}
{
}
}
virtual ~DtMovablePolygonModelAgent()
DTOR.
virtual DtMovablePolygonModel * findObjectAsDtMovablePolygonModel()=0
DtMovablePolygonModelAgent()
CTOR.
static DtMovablePolygonModelAgent * create(makVrv::DtAgentManagerInterface &sceneInterface, bool bDistribute=true)
Static helper creator.
DtMovablePolygonModel * findObject()
Attempt to find the actual object the agent is controlling. warning Any modifications to the actual o...
Polygon model modified to use vertex 0 as its center position and orientation, and positions its vert...
Definition DtMovablePolygonModel.h:27
DtMovablePolygonModelAgent.hpp
#pragma once
{
class DtMovablePolygonModel;
{
public:
DtMovablePolygonModelAgent();
virtual ~DtMovablePolygonModelAgent();
DtMovablePolygonModel* findObject();
const DtMovablePolygonModel* findObject() const;
protected:
virtual DtMovablePolygonModel* findObjectAsDtMovablePolygonModel() = 0;
};
}
DtMovablePolygonModelClasses.cpp
#include <../examples/exampleBulletHole/DtMovablePolygonModelAgent.hpp>
{
class DT_DLL_EXAMPLEBULLETHOLE DtMovablePolygonModelAgentImplementation :
public virtual DtMovablePolygonModelAgent ,
public DtOsgPolygonModelAgentImplementation
{
public:
DtMovablePolygonModelAgentImplementation();
virtual ~DtMovablePolygonModelAgentImplementation();
protected:
virtual DtOsgPolygonModel* findObjectAsDtOsgPolygonModel();
virtual DtMovablePolygonModel* findObjectAsDtMovablePolygonModel();
};
}
{
{
public:
DtMovablePolygonModelClassDefinition(const std::string& className = "DtMovablePolygonModel");
virtual ~DtMovablePolygonModelClassDefinition();
enum FunctionIds
{
end_FunctionIds = DtOsgPolygonModelClassDefinition::end_FunctionIds
};
};
}
{
{
public:
DtMovablePolygonModelClassesCreator();
virtual ~DtMovablePolygonModelClassesCreator();
static makVrv::DtAgentCreator* create();
virtual makVrv::DtAgent* createAgent(makVrv::DtAgentManagerInterface& sceneInterface);
virtual makVrv::DtAgentUpdateResolverInterface* createResolver(makVrv::DtDe& de,
makVrv::DtUniqueID id);
protected:
DtMovablePolygonModelClassDefinition* myDefinition;
static bool theRegisteredFlag;
static makVrv::DtAgentFactory::DtAutoUnregistrar theAutoUnregistrar;
};
}
{
{
}
{
}
{
}
{
makVrv::DtAgentManager* agentManager =
dynamic_cast<makVrv::DtAgentManager*
>(
mySceneInterface);
if(agentManager)
{
makVrv::DtAgentUpdateResolver<DtMovablePolygonModel>* actualUpdater = dynamic_cast<makVrv::DtAgentUpdateResolver<DtMovablePolygonModel>*>(updater);
if(actualUpdater)
{
return actualUpdater->
object();
}
}
return 0;
}
}
{
{
myClassName = "DtMovablePolygonModel";
}
DtMovablePolygonModelClassDefinition::~DtMovablePolygonModelClassDefinition()
{
}
}
#include <exception>
{
{
}
DtMovablePolygonModelClassesCreator::~DtMovablePolygonModelClassesCreator()
{
delete myDefinition;
}
{
return new DtMovablePolygonModelClassesCreator();
}
{
return new DtMovablePolygonModelAgentImplementation();
}
{
}
}
virtual DtOsgPolygonModel * findObjectAsDtOsgPolygonModel()
virtual DtMovablePolygonModel * findObjectAsDtMovablePolygonModel()
virtual ~DtMovablePolygonModelAgentImplementation()
DTOR.
DtMovablePolygonModelAgentImplementation()
CTOR.
Definition class for the scene object class: DtMovablePolygonModel.
Definition DtMovablePolygonModelClasses.hpp:53
DtMovablePolygonModelClassDefinition(const std::string &className="DtMovablePolygonModel")
CTOR- all functions pointers are binded in the CTOR.
Creator class for the scene object class: DtMovablePolygonModel.
Definition DtMovablePolygonModelClasses.hpp:84
static makVrv::DtAgentFactory::DtAutoUnregistrar theAutoUnregistrar
Definition DtMovablePolygonModelClasses.hpp:105
static makVrv::DtAgentCreator * create()
DtMovablePolygonModelClassesCreator()
CTOR.
static bool theRegisteredFlag
Definition DtMovablePolygonModelClasses.hpp:104
Definition class for the scene object class: DtOsgPolygonModel.
Definition DtOsgPolygonModelClasses.hpp:53
OSG implementation of distributed attachable polygon model.
Definition DtOsgPolygonModel.h:29
DtMovablePolygonModelClasses.hpp
#pragma once
#include <../examples/exampleBulletHole/DtMovablePolygonModelAgent.hpp>
{
class DT_DLL_EXAMPLEBULLETHOLE DtMovablePolygonModelAgentImplementation :
public virtual DtMovablePolygonModelAgent ,
public DtOsgPolygonModelAgentImplementation
{
public:
DtMovablePolygonModelAgentImplementation();
virtual ~DtMovablePolygonModelAgentImplementation();
protected:
virtual DtOsgPolygonModel* findObjectAsDtOsgPolygonModel();
virtual DtMovablePolygonModel* findObjectAsDtMovablePolygonModel();
};
}
{
{
public:
DtMovablePolygonModelClassDefinition(const std::string& className = "DtMovablePolygonModel");
virtual ~DtMovablePolygonModelClassDefinition();
enum FunctionIds
{
end_FunctionIds = DtOsgPolygonModelClassDefinition::end_FunctionIds
};
};
}
{
{
public:
DtMovablePolygonModelClassesCreator();
virtual ~DtMovablePolygonModelClassesCreator();
static makVrv::DtAgentCreator* create();
virtual makVrv::DtAgent* createAgent(makVrv::DtAgentManagerInterface& sceneInterface);
virtual makVrv::DtAgentUpdateResolverInterface* createResolver(makVrv::DtDe& de,
makVrv::DtUniqueID id);
protected:
DtMovablePolygonModelClassDefinition* myDefinition;
static bool theRegisteredFlag;
static makVrv::DtAgentFactory::DtAutoUnregistrar theAutoUnregistrar;
};
}
exampleBulletHolePlugin.cxx
#include <boost/bind/bind.hpp>
#include <iostream>
#define DL_DLL_IGCONVRLINK DT_DLL_EXAMPLEBULLETHOLE
#define DT_PROTOCOL_NAMESPACE vrvDis
#define DtDIS 1
#undef DT_PROTOCOL_NAMESPACE
#undef DtDIS
void initializeBulletHoleMenuItem(
DtDe& de,
int bulletHoleVisualTypeId)
{
QString qTemp = QObject::tr("Bullet Holes");
qTemp = QObject::tr("Show/Hide Bullet Holes");
}
{
std::cout << "Loading bullet hole plugin" << std::endl;
{
const int bulletHoleVisualTypeId = 976;
de, "BulletHoleItem", bulletHoleVisualTypeId));
"../examples/exampleBulletHole/BulletHole.png",
if(app)
{
}
}
}
{
{
return true;
}
return false;
}
#define DT_DE_INIT_ONCE(de)
This macro is called by modules in their init() function. This macro ensures that the module is only ...
Definition DtDe.h:30
Contains makVrv::DtObserverSettingsDisplayNameProvider class.
Contains classes used as menu items on the observer menu.
Contains makVrv::DtObserverSettingsManager class.
Contains makVrv::DtSharedSettingsManager class.
Contains makVrv::DtStateVisualizerFactory class.
Defines the DtVisualTypeManager class.
Contains makVrv::DtVisualizerSchema class.
Contains makVrv::DtVrvApplication implementation.
Interaction makVrv::DtWriteSettingsLock class.
static DtAgentFactory & instance(DtDe &de)
Get an instance to the DtAgentFactory.
boost::signalslib::signal< void()> signal_initializeDefaultState
Definition DtDe.h:529
virtual bool isInMasterMode() const
Returns true if the DtDe is in master mode.
virtual const DtDeInitializer & deInitializer() const
Return the DtDeInitializer.
bool featureSupported(DeFeatures feature) const
Check to see if a feature is supported.
@ Features_3D
Definition DtDeInitializer.h:58
virtual void setToolTip(int intKey, const DtUnicode &displayName)
Change the tool tip associated with a key (if it exists) or add a new tool tip to key mapping.
virtual void setDisplayName(int intKey, const DtUnicode &displayName)
Change the dislay name associated with a key (if it exists) or add a new display name to key mapping.
Definition DtObserverSettingsItems.h:300
DtObserverSettingsDisplayNameProvider is an interface for a class to provide display names for observ...
Definition DtObserverSettingsDisplayNameProvider.h:24
static DtObserverSettingsManager & instance(DtDe &de)
Get an instance used to emit, or to connect.
static DtStateVisualizerFactory & instance(DtDe &de)
Get the instance of the factory from its owner de.
static DtUnicode fromQString(QStringType qstr)
Template function for setting from Qt 4 style string.
Definition DtUnicode.h:107
@ ModelSetAll
Definition DtVisualTypeManager.h:48
static DtVisualTypeManager & instance(DtDe &de)
Static accessor. Get the instance of the manager rooted in the DtDe.
DT_DLL_EXAMPLEACCESSORY void init(makVrv::DtDe &de)
Contains declarations for plugin initialization functions.
DT_DE_PLUGIN_EXPORT_MACRO bool initDeModule(makVrv::DtDe *de)
Definition DtAudioInit.h:25
DT_DLL_VRVCOREQT void init(DtDe &de)
DT_DLL_VRVOSG void init(DtDe &anIG, bool initOpenGL=true)
Information about a visual type.
Definition DtVisualTypeManager.h:53
exampleBulletHolePlugin.h
#ifndef exampleBulletHolePlugin_h_
#define exampleBulletHolePlugin_h_
#define DT_DE_PLUGIN_EXPORT_MACRO DT_DLL_EXAMPLEBULLETHOLE
namespace makVrv {
class DtDe; }
#endif