VR-Vantage
Loading...
Searching...
No Matches
exampleViewControl

Overview

Shows how to add a new view control to the VR-Vantage Control Toolkit.

Expected Result

We use exampleSendControl to demonstrate the view control message created in this example. Using exampleSendControl, you can observe the following behavior:

Before you enter 'W'
After you enter 'W'

Note: A 3D model was added to the scene to better illustrate the change in render settings. To do this, the startup scripts for this example loads the exampleDistributedObject plugin which, among other things, places a 3D model in the scene.

Example details

The VR-Vantage Control Toolkit lets you send DIS or HLA messages that can remotely control a VR-Vantage application. It has messages for most VR-Vantage display settings. This example shows how to add new control messages by adding a viewLightScale view control message, and a custom attach observer message.

VR-Vantage does not send view controls so in order to test the receipt of this new view control a new application will need to be created to send them. We show how to send view controls in exampleSendControl but also use this example to demonstrate the view control message created in this example.

Please review the comments in the files for details.

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/exampleViewControl_stealth.bat (on Windows from cmd.exe) or ./bin64/exampleViewControl_stealth.sh (on Linux). For more information about running examples, please see Running Applications and Examples.

When using HLA1516e, it's important to configure the default connection using the RTI Assistant. In Windows, the RTI Assistant can be found under "MAK Technologies" from the Windows start menu. In Linux, the RTI Assistant can be started using the "./rtiAssitstant -N" script located in the RTI installed location bin folder. Using the RTI Assistant connection preferences tab, set the default connection to be "[machine name]'s predefined rtiexec loopback connection" rather than the default "Predefined lightweight loopback connection".

Example Source Files


MyLightScaleCommand.h

/*******************************************************************************
** Copyright (c) 2019 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
#pragma once
using namespace makVrv;
namespace MyViewControl
{
class DT_DLL_EXAMPLEVIEWCONTROL MyLightScaleCommand : public DtVrvCommand
{
public:
MyLightScaleCommand();
virtual ~MyLightScaleCommand();
virtual bool diffuseLightScaleSet() const;
virtual int diffuseLightScale() const;
// effect of setting diffuseLightScaleSet() to true
virtual void setDiffuseLightScale( int scale );
virtual bool ambientLightScaleSet() const;
virtual int ambientLightScale() const;
// effect of setting ambientLightScaleSet() to true
virtual void setAmbientLightScale( int scale );
virtual void execute(DtDe& de);
protected:
int myDiffuseLightScale;
int myAmbientLightScale;
bool myDiffuseLightScaleSet;
bool myAmbientLightScaleSet;
};
class DT_DLL_EXAMPLEVIEWCONTROL MyLightScaleCommandCreator
{
public:
MyLightScaleCommandCreator(GlobalIdConvertFunc func);
virtual ~MyLightScaleCommandCreator();
};
}
Contains makVrv::DtVrvCommand and makVrv::DtVrvCommandCreator Classes.
Contains MyControlToolkit control structures and defines.
The DtDe is the core component of any VR-Vantage application. It owns a DtRenderer,...
Definition DtDe.h:77
Definition DtVrvCommand.h:45
Definition DtVrvCommand.h:25
#define DT_DLL_EXAMPLEVIEWCONTROL
Definition exampleViewControlPlugin.h:18
Definition MyAttachObserverCommand.h:20
Contains DtCreateSensorFieldOfViewCommand and DtCreateSensorFieldOfViewCommandCreator class declarati...
Definition DtGridLinesSettingsRecord.h:16
boost::function< DtUniqueID(const std::string &)> GlobalIdConvertFunc
Definition DtVrvCommand.h:40
Definition vrvControlToolkitDataTypes.h:279

MyLightScaleCommand.cxx

/*******************************************************************************
** Copyright (c) 2019 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
#include <vrvCore/DtDe.h>
using namespace makVrv;
namespace MyViewControl
{
, myDiffuseLightScale(0)
, myAmbientLightScale(0)
, myDiffuseLightScaleSet(false)
, myAmbientLightScaleSet(false)
{
}
MyLightScaleCommand::~MyLightScaleCommand()
{
}
bool MyLightScaleCommand::diffuseLightScaleSet() const
{
return myDiffuseLightScaleSet;
}
int MyLightScaleCommand::diffuseLightScale() const
{
return myDiffuseLightScale;
}
void MyLightScaleCommand::setDiffuseLightScale( int scale )
{
myDiffuseLightScale = scale;
myDiffuseLightScaleSet = true;
}
bool MyLightScaleCommand::ambientLightScaleSet() const
{
return myAmbientLightScaleSet;
}
int MyLightScaleCommand::ambientLightScale() const
{
return myAmbientLightScale;
}
void MyLightScaleCommand::setAmbientLightScale( int scale )
{
myAmbientLightScale = scale;
myAmbientLightScaleSet = true;
}
void MyLightScaleCommand::execute(DtDe& de)
{
if ( diffuseLightScaleSet() )
{
de.sharedState().setLightingDiffuseScale(diffuseLightScale());
}
if ( ambientLightScaleSet() )
{
de.sharedState().setLightingAmbientScale(ambientLightScale());
}
}
MyLightScaleCommandCreator::MyLightScaleCommandCreator(GlobalIdConvertFunc func)
{
}
MyLightScaleCommandCreator::~MyLightScaleCommandCreator()
{
}
DtVrvCommand* MyLightScaleCommandCreator::create(
{
MyLightScaleCommand* retCmd = 0;
if ( control->myVersion == 1 )
{
if( control->mySize == sizeof( MyControlToolkit::MyLightScale_v1 ) )
{
retCmd = new MyLightScaleCommand();
MyControlToolkit::MyLightScale_v1* lightScaleControl =
if ( lightScaleControl->myValuesSetFlags &
{
retCmd->setDiffuseLightScale( lightScaleControl->myDiffuseLightScale );
}
if ( lightScaleControl->myValuesSetFlags &
{
retCmd->setAmbientLightScale( lightScaleControl->myAmbientLightScale);
}
}
}
return retCmd;
}
}
Contains makVrv::DtDe class.
Contains makVrv::DtDeSharedState class.
Contains makVrv::MyLightScaleCommand and makVrv::MyLightScaleCommandCreator Classes.
virtual DtDeSharedState & sharedState()
Returns the DtDeSharedState object.
virtual void setLightingDiffuseScale(float setting)
virtual void setLightingAmbientScale(float setting)
DtVrvControlTypeEnum
Definition vrvControlToolkitDataTypes.h:59
@ Control_LightScale
Definition MyViewControlDataTypes.h:21
Definition MyViewControlDataTypes.h:29
@ AmbientLightScaleSet
Definition MyViewControlDataTypes.h:43
@ DiffuseLightScaleSet
Definition MyViewControlDataTypes.h:42
vrvControlToolkit::DtUInt32 myDiffuseLightScale
Definition MyViewControlDataTypes.h:35
vrvControlToolkit::DtUInt8 myValuesSetFlags
Definition MyViewControlDataTypes.h:47
vrvControlToolkit::DtUInt32 myAmbientLightScale
Definition MyViewControlDataTypes.h:36
DtUInt16 mySize
Definition vrvControlToolkitDataTypes.h:286
DtUInt16 myVersion
Definition vrvControlToolkitDataTypes.h:289

MyAttachObserverCommand.h

/*******************************************************************************
** Copyright (c) 2024 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
#pragma once
using namespace makVrv;
namespace MyViewControl
{
class DT_DLL_EXAMPLEVIEWCONTROL MyAttachObserverCommand : public DtVrvCommand
{
public:
MyAttachObserverCommand();
virtual ~MyAttachObserverCommand();
virtual const DtUniqueID& entityId();
virtual void setEntityId( const DtUniqueID& entityId );
virtual const std::string& sensorName();
virtual void setSensorName( const std::string& sensorName );
virtual const std::string& observerName();
virtual void setObserverName( const std::string& observerName );
virtual bool createOverlay() const;
virtual void setCreateOverlay( bool );
virtual void execute( DtDe& de );
protected:
DtUniqueID myEntityId;
std::string mySensorName;
std::string myObserverName;
bool myCreateOverlay;
};
class DT_DLL_EXAMPLEVIEWCONTROL MyAttachObserverCommandCreator
{
public:
MyAttachObserverCommandCreator( GlobalIdConvertFunc func );
virtual ~MyAttachObserverCommandCreator();
virtual DtVrvCommand* create( vrvControlToolkit::DtVrvControl_v1* control );
};
}

MyAttachObserverCommand.cxx

/*******************************************************************************
** Copyright (c) 2024 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
#include <vrvCore/DtDe.h>
using namespace makVrv;
namespace MyViewControl
{
, myCreateOverlay( true )
, myEntityId( DtUniqueID( 0 ) )
, mySensorName( "" )
, myObserverName( "" )
{
}
MyAttachObserverCommand::~MyAttachObserverCommand()
{
}
const DtUniqueID& MyAttachObserverCommand::entityId()
{
return myEntityId;
}
void MyAttachObserverCommand::setEntityId( const DtUniqueID& u )
{
myEntityId = u;
}
const std::string& MyAttachObserverCommand::sensorName()
{
return mySensorName;
}
void MyAttachObserverCommand::setSensorName( const std::string& u )
{
mySensorName = u;
}
const std::string& MyAttachObserverCommand::observerName()
{
return myObserverName;
}
void MyAttachObserverCommand::setObserverName( const std::string& u )
{
myObserverName = u;
}
bool MyAttachObserverCommand::createOverlay() const
{
return myCreateOverlay;
}
void MyAttachObserverCommand::setCreateOverlay( bool b )
{
myCreateOverlay = b;
}
static makVrv::DtUniqueID oldId = 0;
static makVrv::DtUniqueID oldSensorId = 0;
void MyAttachObserverCommand::execute( DtDe& de )
{
if( myEntityId == 0 )
{
DtWarn << "MyAttachObserverCommand element ID == 0" << std::endl;
return;
}
if( mySensorName == "" )
{
DtWarn << "MyAttachObserverCommand mySensorName string is empty" << std::endl;
return;
}
std::string obsName = myObserverName == "" ? "Observer 1" : myObserverName;
obsName );
if( observer )
{
std::vector<DtUniqueID> idVector;
idVector.push_back( myEntityId );
observer->setPrimaryAttachment( idVector );
// This comes from VRF
const DtModelSemanticsMapper::Parts::Id* id = DtModelSemanticsMapper::instance( de ).findPartId( "gimbaled_sensor_elevation_1" );
observer->setPartAttachment( *id );
observer->setHideModelOnAttach( true );
}
DtDisplay* display = de.display();
if( display )
{
for( auto& window : display->windowManager().windows() )
{
for( auto& channel : window->channelManager().channels() )
{
if( channel.second->observerName() == obsName )
{
DtChannelConfiguration* newConfig = const_cast<DtChannelConfiguration*>(& channel.second->configuration());
if( newConfig )
{
newConfig->removeKeyword( "showCockpits" );
}
}
}
}
}
if( myCreateOverlay )
{
const DtSensorFieldOfViewManager::SensorFieldOfViewDataMap* fieldsOfView = fieldOfViewMgr.fieldsOfViewForEntity( myEntityId );
if( oldId != 0 && oldSensorId != 0 )
{
fieldOfViewMgr.removeSensorOverlay( oldId, oldSensorId );
}
if( fieldsOfView )
{
for( auto& fieldOfView : *fieldsOfView )
{
if( fieldOfView.second.sensorId() == mySensorName && !fieldOfViewMgr.hasSensorObserver( myEntityId, fieldOfView.first ) )
{
oldId = myEntityId;
oldSensorId = fieldOfView.first;
fieldOfViewMgr.addSensorObserver( obsName, myEntityId, fieldOfView.first, false );
}
}
}
}
}
MyAttachObserverCommandCreator::MyAttachObserverCommandCreator( GlobalIdConvertFunc func )
{
}
MyAttachObserverCommandCreator::~MyAttachObserverCommandCreator()
{
}
DtVrvCommand* MyAttachObserverCommandCreator::create(
{
MyAttachObserverCommand* retCmd = 0;
if( control->myVersion == 1 )
{
{
retCmd = new MyAttachObserverCommand();
retCmd->setEntityId( myConvertGlobablIdFunc( attachControl->myEntity ) );
retCmd->setCreateOverlay( attachControl->myCreateOverlay );
retCmd->setSensorName( attachControl->mySensorName );
retCmd->setObserverName( attachControl->myObserverName );
}
}
return retCmd;
}
}
Contains makVrv::DtChannel class.
Contains makVrv::DtChannelManager class.
Contains makVrv:DtDisplay class.
Contains makVrv:DtMasterScene class.
Contains makVrv::DtInputDriver class.
Contains makVrv::DtModelSemanticsMapper class.
Contains makVrv::DtObserver class.
Contains makVrv::DtObserverSettingsManager class.
Contains makVrv::DtSensorFieldOfViewManager class.
Contains makVrv::DtIgView class.
Contains makVrv::DtWindowManager class.
Contains makVrv::MyAttachObserverCommand and makVrv::MyAttachObserverCommandCreator Classes.
Configuration for a single channel Serialized and sent to remote displays as necessary to configure r...
Definition DtChannelConfiguration.h:27
virtual DtDisplay * display()
DtDisplay accessor. The returned pointer will be NULL before initialize is called,...
virtual DtDriverManager & driverManager()
The DtMasterScene accessor. The function will throw before the initialize function is called.
Component which owns how the application is displayed.
Definition DtDisplay.h:28
virtual DtWindowManager & windowManager()
DtWindowManager accessor.
DtInputDriver & inputDriver()
Return the DtInputDriver associated with the master scene.
virtual DtObserver * findObserverByName(const std::string &name)
Find an observer by its name.
virtual void removeKeyword(const std::string &keyword)
Remove a keyword.
static DtModelSemanticsMapper & instance(DtDe &)
A facade for a DtObserverObject.
Definition DtObserver.h:39
void setHideModelOnAttach(bool hide)
void setPrimaryAttachment(const ElementList &elements)
void setPartAttachment(int partId)
void setAttachType(DtObserverObject::AttachType type)
@ AttachTypeMimic
Definition DtObserverObject.h:45
The sensor field of view manager. Keeps track of sensor field of view states and any observers associ...
Definition DtSensorFieldOfViewManager.h:30
static DtSensorFieldOfViewManager & instance(DtDe &de)
Get an instance of the sensor field of view manager.
virtual bool hasSensorObserver(DtElementID hostId, DtElementID sensorId)
Returns true if this sensor already has an observer associated with it.
virtual void removeSensorOverlay(DtUniqueID entId, DtUniqueID sensorId)
Remove a sensor overlay without destroying the window it is on.
std::map< DtUniqueID, DtSensorFieldOfViewData > SensorFieldOfViewDataMap
Definition DtSensorFieldOfViewManager.h:44
virtual void addSensorObserver(const std::string &observerName, DtElementID hostId, DtElementID sensorId, bool createControls)
Adds a sensor field of view observer to be updated as state changes. createControls is unused by the ...
const SensorFieldOfViewDataMap * fieldsOfViewForEntity(DtElementID entity) const
Returns data for all sensor fields of view hosted by the specified entity.
virtual WindowList & windows()
Get the window list.
@ AttachObserverToSensor
Definition MyViewControlDataTypes.h:22
unsigned long long DtUniqueID
Definition DtUniqueID.h:19
Definition MyViewControlDataTypes.h:51
bool myCreateOverlay
Whether or not to create the overlay.
Definition MyViewControlDataTypes.h:65
vrvControlToolkit::DtInt8 mySensorName[vrvControlToolkit::DtVrvControlNameSize]
The name of the sensor gimbal to attach to.
Definition MyViewControlDataTypes.h:59
vrvControlToolkit::DtInt8 myEntity[vrvControlToolkit::DtVrvControlNameSize]
The Global ID of the entity that hosts the sensor.
Definition MyViewControlDataTypes.h:56
vrvControlToolkit::DtInt8 myObserverName[vrvControlToolkit::DtVrvControlNameSize]
The name of the observer.
Definition MyViewControlDataTypes.h:62
Id
Definition DtModelSemanticsMapper.h:172

MyViewControlDataTypes.h

/*******************************************************************************
** Copyright (c) 2024 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
#pragma once
{
// Declare the enumerants to use for you custom view control messages. This
// could be added directly to vrvControlToolkitDataTypes.h, but then you
// would need to re-merge with each new release. It makes more sense to
// manage your own packets this way.
enum class MyVrvControlTypeEnum : unsigned int
{
};
// Declare the packet(s) that will contain your view control message(s).
// This message will set a scale factor for the diffuse and/or ambient light
// values in the scene
struct MyLightScale_v1 : public vrvControlToolkit::DtVrvControl_v1
{
inline MyLightScale_v1();
inline ~MyLightScale_v1();
// Similar to VR-Link net types, the The vrvControlToolkit types will
// manage byte-swapping if needed.
// This enumeration describes bit values set in the myValuesSetFlags
// member to indicate which of the messages members should be processed
{
};
// Bit-encoded integer that indicates which values are set
};
struct MyAttachObserverToSensor_v1 : public vrvControlToolkit::DtVrvControl_v1
{
};
}
@ Control_UserStart
Definition vrvControlToolkitDataTypes.h:192
Definition MyViewControlDataTypes.h:14
MyVrvControlTypeEnum
Definition MyViewControlDataTypes.h:20
const DtUInt32 DtVrvControlNameSize
Definition vrvControlToolkitDataTypes.h:21
unsigned int DtUInt32
Definition vrvControlStructTypes.h:32
char DtInt8
Definition vrvControlStructTypes.h:27
unsigned char DtUInt8
Definition vrvControlStructTypes.h:28
MyAttachObserverToSensor_v1()
Definition MyViewControlDataTypes.inl:36
~MyAttachObserverToSensor_v1()
Definition MyViewControlDataTypes.inl:50
LightScaleSettingsUsed
Definition MyViewControlDataTypes.h:41
~MyLightScale_v1()
Definition MyViewControlDataTypes.inl:31
MyLightScale_v1()
Definition MyViewControlDataTypes.inl:17
Contains vrvControlToolkit control structures and defines.

MyViewControlDataTypes.inl

/*******************************************************************************
** Copyright (c) 2024 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
#pragma once
{
//----------------------Light Scale Command ----------------------
: vrvControlToolkit::DtVrvControl_v1()
{
// Base struct setup
myType = (vrvControlToolkit::DtVrvControlTypeEnum)MyVrvControlTypeEnum::Control_LightScale;
myVersion = 1;
mySize = sizeof(MyLightScale_v1);
// Initial Values
myDiffuseLightScale = 0;
myAmbientLightScale = 0;
myValuesSetFlags = 0;
}
MyLightScale_v1::~MyLightScale_v1()
{
}
//----------------------AttachObserverToSensor ----------------------
MyAttachObserverToSensor_v1::MyAttachObserverToSensor_v1()
: vrvControlToolkit::DtVrvControl_v1()
{
// Base struct setup
myType = (vrvControlToolkit::DtVrvControlTypeEnum) MyVrvControlTypeEnum::AttachObserverToSensor;
myVersion = 1;
mySize = sizeof( MyAttachObserverToSensor_v1 );
memset( myObserverName, 0, sizeof( vrvControlToolkit::DtInt8[vrvControlToolkit::DtVrvControlNameSize] ) );
myCreateOverlay = true;
}
MyAttachObserverToSensor_v1::~MyAttachObserverToSensor_v1()
{
}
}
A 3D Area Stealth Draw Control Object.
Definition DtVrlinkDataInterMarshaller.h:18