Shows how to create and manipulate DtWindowObjects in VR-Vantage.
The VR-Vantage Control Toolkit lets you create 2D window objects, such as lines, polygons and textboxes. This example shows how to add new window objects and manipulate them around the screen.
It allows you to create, translate (x&y), rotate, scale (x&y) multiple different objects, using both a parenting and non-parenting mode.
The box that is initially displayed in white on the screen is a visual representation of the DtWindowSurface's clipping box.
The key bindings for the example are as follows: “Space” - Creates a window object object of the selected type “1” - Sets window object type to Polygon “2” - Sets window object type to Line “3” - Sets window object type to Text Box “4” - Sets window object type to Eclipse “WASD” - Translates the object and its children around the screen “Left” & “Right” arrow keys - scale -/+ in the x direction “Up” & “Down” arrow keys - scale -/+ in the y direction "R" - Rotate object 45 degrees counterclockwise “,” & “.” - The comma and period keys traverse up and down the vector the objects are stored in for individual control. “p” - Turns off parenting for newly created objects, for individual control. Parenting is on by default, and each newly created object is attached to the previously created object. “v” - Turns the currently selected window object's visibility on / off.
This example is a plug-in. You can run it by running ./bin64/exampleWindowObjects_stealth.bat (on Windows from cmd.exe) or ./bin64/exampleWindowObjects_stealth.sh (on Linux). For more information about running examples, please see Running Applications and Examples.
#include <iostream>
{
DtAgentManager& agentManager, const std::string& instanceName )
: DtDriver( agentManager, instanceName )
, myWindowAgents()
, myActivatedObjectType( 1 )
, myActivatedObjectId( 0 )
, myParenting( true )
, mySurface( 0 )
, mySurfaceClipBoxVisualPoly( 0 )
{
setAutoStart( true );
myUserControllableFlag = false;
mySurfaceClipBoxVisualPoly = DtWindowPolygonAgent::create( myAgentManager );
if ( mySurfaceClipBoxVisualPoly )
{
mySurfaceClipBoxVisualPoly->setNumVertices( 4 );
mySurfaceClipBoxVisualPoly->setVertex( 0, 0.0, 0.0 );
mySurfaceClipBoxVisualPoly->setVertex( 1, 0.0, 0.5 );
mySurfaceClipBoxVisualPoly->setVertex( 2, 0.5, 0.5 );
mySurfaceClipBoxVisualPoly->setVertex( 3, 0.5, 0.0 );
mySurfaceClipBoxVisualPoly->setScale( 1.0 );
mySurfaceClipBoxVisualPoly->setRotation( 0.0 );
mySurfaceClipBoxVisualPoly->setFill( false );
mySurfaceClipBoxVisualPoly->setColor( 1.0, 1.0, 1.0, 1.0 );
mySurfaceClipBoxVisualPoly->setPosition( -0.25, -0.25 );
mySurface = DtWindowSurfaceAgent::create( myAgentManager );
mySurface->setClipBox( 0.25, 0.25, 0.75, 0.75 );
mySurface->setPosition( 0.5, 0.5 );
mySurfaceClipBoxVisualPoly->setParentId( mySurface->uniqueId() );
mySurface->addChild( mySurfaceClipBoxVisualPoly->uniqueId() );
}
}
DtWindowObjectsDriver::~DtWindowObjectsDriver()
{
}
const std::string& DtWindowObjectsDriver::className() const
{
static std::string name( "DtWindowObjectsDriver" );
return name;
}
void DtWindowObjectsDriver::drawObject()
{
switch ( myActivatedObjectType )
{
case 1:
drawPolygon();
break;
case 2:
drawLine();
break;
case 3:
drawText();
break;
case 4:
drawEllipse();
break;
}
}
void DtWindowObjectsDriver::drawPolygon()
{
DtWindowPolygonAgent* agent = DtWindowPolygonAgent::create( myAgentManager );
if ( agent )
{
agent->setNumVertices( 4 );
agent->setVertex( 0, 0.0, 0.0 );
agent->setVertex( 1, 0.8, 0.0 );
agent->setVertex( 2, 0.8, 0.1 );
agent->setVertex( 3, 0.0, 0.8 );
agent->setRotation( 0.0 );
agent->setFill( false );
agent->setColor( 1.0, 1.0, 1.0, 1.0 );
DtWindowObjectAgent* baseAgent = dynamic_cast<DtWindowObjectAgent*>(agent);
if ( baseAgent )
{
if ( myParenting && !myWindowAgents.empty() )
{
myWindowAgents.back()->addChild( baseAgent->uniqueId() );
baseAgent->setParentId( myWindowAgents.back()->uniqueId());
}
else if( myParenting && myWindowAgents.empty() )
{
mySurface->addChild( baseAgent->uniqueId() );
baseAgent->setParentId( mySurface->uniqueId() );
}
myWindowAgents.push_back( baseAgent );
}
}
}
void DtWindowObjectsDriver::drawLine()
{
DtWindowLineAgent* agentLine = DtWindowLineAgent::create( myAgentManager );
if ( agentLine )
{
agentLine->setVisible( true );
agentLine->setVertex( 0, 0.05, 0.05 );
agentLine->setVertex( 1, 0.1, 0.1 );
agentLine->setWidth( 4 );
agentLine->setColor( 1.0, 1.0, 1.0, 1.0 );
agentLine->setPosition( 0.1, 0.1 );
DtWindowObjectAgent* baseAgentLine = dynamic_cast<DtWindowObjectAgent*>(agentLine);
if ( baseAgentLine )
{
if ( myParenting && !myWindowAgents.empty() )
{
myWindowAgents.back()->addChild( baseAgentLine->uniqueId() );
baseAgentLine->setParentId( myWindowAgents.back()->uniqueId() );
}
else if( myParenting && myWindowAgents.empty() )
{
mySurface->addChild( baseAgentLine->uniqueId() );
baseAgentLine->setParentId( mySurface->uniqueId() );
}
myWindowAgents.push_back(baseAgentLine);
}
}
}
void DtWindowObjectsDriver::drawText()
{
DtWindowTextAgent* agentText = DtWindowTextAgent::create( myAgentManager );
if ( agentText )
{
agentText->setColor( 1.0, 1.0, 1.0, 1.0 );
agentText->setTopLeftCorner( (float)0.0, (float)0.0 );
agentText->setText( "Hello World!" );
agentText->setTextBoxWidth( 400 );
agentText->setFont( "FreeMono.otf", 14 );
agentText->setVisible( true );
DtWindowObjectAgent* baseAgentText = dynamic_cast<DtWindowObjectAgent*>(agentText);
if ( baseAgentText )
{
if ( myParenting && !myWindowAgents.empty() )
{
myWindowAgents.back()->addChild( baseAgentText->uniqueId() );
baseAgentText->setParentId( myWindowAgents.back()->uniqueId() );
}
else if( myParenting && myWindowAgents.empty() )
{
mySurface->addChild( baseAgentText->uniqueId() );
baseAgentText->setParentId( mySurface->uniqueId() );
}
myWindowAgents.push_back( baseAgentText );
}
}
}
void DtWindowObjectsDriver::drawEllipse()
{
DtWindowEllipseAgent* agent = DtWindowEllipseAgent::create( myAgentManager );
if ( agent )
{
agent->setCenter( 0.0, 0.0 );
agent->setDimensions( 0.25, 0.25 );
agent->setNumVertices( 10 );
agent->setFill( false );
agent->setScale( 1.0, 1.0 );
DtWindowObjectAgent* base = dynamic_cast<DtWindowObjectAgent*>(agent);
if ( base )
{
if ( myParenting && !myWindowAgents.empty() )
{
myWindowAgents.back()->addChild( base->uniqueId() );
base->setParentId( myWindowAgents.back()->uniqueId() );
}
else if( myParenting && myWindowAgents.empty() )
{
mySurface->addChild( base->uniqueId() );
base->setParentId( mySurface->uniqueId() );
}
myWindowAgents.push_back( base );
}
}
}
void DtWindowObjectsDriver::activateObjectType( int objectId )
{
myActivatedObjectType = objectId;
}
void DtWindowObjectsDriver::modifyActivateObjectId( bool increaseIdNumber )
{
if ( increaseIdNumber )
{
if ( myActivatedObjectId < myWindowAgents.size()-1 )
{
myActivatedObjectId++;
}
}
else
{
if ( myActivatedObjectId > 0 )
{
myActivatedObjectId--;
}
}
}
void DtWindowObjectsDriver::setParenting()
{
if ( myParenting )
{
myParenting = false;
}
else
{
myParenting = true;
}
}
void DtWindowObjectsDriver::modifyObjectVisibility()
{
DtWindowObjectAgent* temp = findWindowObjectAgent( myActivatedObjectId );
if ( temp )
{
DtWindowObject* actualObj = temp->findObject();
if ( actualObj )
{
if ( actualObj->visible() )
{
temp->setVisible( false );
}
else
{
temp->setVisible( true);
}
}
}
}
void DtWindowObjectsDriver::shiftWindowObjectPosition( DtDirection direction )
{
DtWindowObjectAgent* temp = findWindowObjectAgent( myActivatedObjectId );
if ( temp )
{
DtWindowObject* actualObj = temp->findObject();
if ( actualObj )
{
actualObj->getPosition( x, y );
switch ( direction )
{
case Up:
y = y + 0.1;
break;
break;
case Down:
y = y - 0.1;
break;
break;
default:
break;
}
temp->setPosition( x, y );
}
}
}
void DtWindowObjectsDriver::scaleWindowObject( DtDirection direction )
{
DtWindowObjectAgent* temp = findWindowObjectAgent( myActivatedObjectId );
if ( temp )
{
DtWindowObject* actualObj = temp->findObject();
if ( actualObj )
{
actualObj->getScale( x, y );
switch ( direction )
{
case Up:
y = y + 0.1;
break;
break;
case Down:
y = y - 0.1;
break;
break;
default:
break;
}
temp->setScale( x, y );
}
}
}
void DtWindowObjectsDriver::rotateWindowObject()
{
DtWindowObjectAgent* temp = findWindowObjectAgent( myActivatedObjectId );
if ( temp )
{
DtWindowObject* actualObj = temp->findObject();
if ( actualObj )
{
double rotation;
actualObj->getRotation( rotation );
temp->setRotation( rotation + 0.1 );
}
}
}
DtWindowObjectAgent* DtWindowObjectsDriver::findWindowObjectAgent( int vecLocation )
{
if ( vecLocation < myWindowAgents.size() )
{
return myWindowAgents[vecLocation];
}
return 0;
}
bool DtWindowObjectsDriver::onStart()
{
return true ;
}
bool DtWindowObjectsDriver::onStop()
{
DtWindowObjects::iterator iter = myWindowAgents.begin();
DtWindowObjects::iterator endIter = myWindowAgents.end();
for ( ; iter != endIter; ++iter )
{
DtWindowObjectAgent* toDelete = *iter;
delete toDelete;
toDelete = 0;
}
myWindowAgents.clear();
delete mySurfaceClipBoxVisualPoly;
mySurfaceClipBoxVisualPoly = 0;
delete mySurface;
mySurface = 0;
return true;
}
bool DtWindowObjectsDriver::onTick()
{
return true;
}
}
Contains makVrv::DtWindowObject class.
Contains DtWindowObjectsDriver class.
DtWindowObjectsDriver(DtAgentManager &agentManager, const std::string &instanceName)
CTOR.
x y t t *t x y t t t x y t t t x *y t *t t x *y t *t t x y t t t x y t t t x(y+z)
Contains DtCreateSensorFieldOfViewCommand and DtCreateSensorFieldOfViewCommandCreator class declarati...
Definition DtGridLinesSettingsRecord.h:16
@ Right
Icon appears in the right zone of the status bar.
Definition DtBackgroundStatus.h:26
@ Left
Icon appears in the left zone of the status bar.
Definition DtBackgroundStatus.h:24
#include <boost/bind/bind.hpp>
#include <string>
#include <sstream>
static vrvSignalsLib::connection postInitializeConnection;
static vrvSignalsLib::connection keyMapChangedConnection;
static vrvSignalsLib::connection quitConnection;
{
{
}
}
{
return true;
}
{
keyMapChangedConnection.disconnect();
boost::bind(&applyKeyMap, de));
}
{
quitConnection.disconnect();
keyMapChangedConnection.disconnect();
}
{
postInitializeConnection.disconnect();
applyKeyMap(de);
boost::bind(&applyKeyMap, de));
boost::bind(&disconnectFromSignals, de));
for ( int i = 1; i < 5; ++i )
{
std::ostringstream ss;
ss << i;
ss.clear();
}
}
Contains makVrv::DtDe class.
#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:DtMasterScene class.
Contains makVrv::DtKeyMap and related classes.
Contains makVrv::DtKeyMapManagerSignaler class.
Contains makVrv::DtOsgEmptySceneLogo class.
The DtDe is the core component of any VR-Vantage application. It owns a DtRenderer,...
Definition DtDe.h:77
DtAgentManager & agentManager()
Get the scene manager.
virtual bool isInMasterMode() const
Returns true if the DtDe is in master mode.
boost::signalslib::signal< void()> signal_quit
Definition DtDe.h:619
virtual DtDriverManager & driverManager()
The DtMasterScene accessor. The function will throw before the initialize function is called.
boost::signalslib::signal< void()> signal_postInitialize
Definition DtDe.h:535
void addDriver(DtDriver *driver)
Add a host driver to the master scene. The host is now owned by the Master Scene.
DtInputDriver & inputDriver()
Return the DtInputDriver associated with the master scene.
a Key Map contains a map of keys to FunctionMapEntrys, as well as a list of functions to execute when...
Definition DtKeyMap.h:313
The manager for owning key maps.
Definition DtKeyMapManager.h:32
virtual void activateMap(const std::string &mapName)
invoke the function(s) on a map's pre-function list
@ Rendering
Definition DtKeyMapManager.h:43
static DtKeyMapManager & instance(DtDe &de)
Get an instance of the key map.
virtual void addKeyFunction(const std::string &functionName, const KeyFunction &function, FunctionCategory functionCategory, bool categorize=true)
bind a function to string name that can be used in a key map (or binary function set)
virtual DtKeyMap * createKeyMap(const std::string &mapName, bool silent=false)
create and return a key map
static DtKeyMapManagerSignaler & instance(DtDe &de)
Get an instance used to emit, or to connect.
@ KEY_PERIOD
Definition DtKeyState.h:123
@ KEY_V
Definition DtKeyState.h:77
@ KEY_S
Definition DtKeyState.h:74
@ KEY_3
Definition DtKeyState.h:49
@ KEY_SPACE
Definition DtKeyState.h:33
@ KEY_UP
Definition DtKeyState.h:39
@ KEY_A
Definition DtKeyState.h:56
@ KEY_4
Definition DtKeyState.h:50
@ KEY_DOWN
Definition DtKeyState.h:41
@ KEY_LEFT
Definition DtKeyState.h:38
@ KEY_RIGHT
Definition DtKeyState.h:40
@ KEY_COMMA
Definition DtKeyState.h:121
@ KEY_2
Definition DtKeyState.h:48
@ KEY_R
Definition DtKeyState.h:73
@ KEY_D
Definition DtKeyState.h:59
@ KEY_1
Definition DtKeyState.h:47
@ KEY_P
Definition DtKeyState.h:71
@ KEY_W
Definition DtKeyState.h:78
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...
Definition DtWindowObjectsDriver.h:43
DT_DLL_EXAMPLEACCESSORY void init(makVrv::DtDe &de)
void loadDriver(DtDe *de)
DT_DE_PLUGIN_EXPORT_MACRO bool initDeModule(makVrv::DtDe *de)