VR-Vantage 2.8 API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
exampleWindowObjects

Table of Contents

Overview

Shows how to create and manipulate DtWindowObjects in VR-Vantage.

Example details

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 90 degrees clockwise “,” & “.” - 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.

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/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.

Example Source Files


DtWindowObjectsDriver.cxx

// /******************************************************************************
// ** Copyright (c) 2020 MAK Technologies, Inc.
// ** All rights reserved.
// ******************************************************************************/
#include <iostream>
namespace makVrv
{
DtAgentManager& agentManager, const std::string& instanceName )
: DtDriver( agentManager, instanceName )
, myWindowAgents()
, myActivatedObjectType( 1 )
, myActivatedObjectId( 0 )
, myParenting( true )
, mySurface( 0 )
, mySurfaceClipBoxVisualPoly( 0 )
{
// Tell the driver to start automatically when added to the DE
setAutoStart( true );
// This driver can't be started or stopped from the GUI; myUserControllableFlag sets this property
myUserControllableFlag = false;
// This polygon gives a visual representation of the clip box that the surface uses
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
{
// name must be static, since it's returned by reference
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()
{
// Text
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 )
{
double x, y;
actualObj->getPosition( x, y );
switch ( direction )
{
case Up:
y = y + 0.1;
break;
case Left:
x = x - 0.1;
break;
case Down:
y = y - 0.1;
break;
case Right:
x = x + 0.1;
break;
default:
break;
}
temp->setPosition( x, y );
}
}
}
void DtWindowObjectsDriver::scaleWindowObject( DtDirection direction )
{
DtWindowObjectAgent* temp = findWindowObjectAgent( myActivatedObjectId );
if ( temp )
{
DtWindowObject* actualObj = temp->findObject();
if ( actualObj )
{
double x, y;
actualObj->getScale( x, y );
switch ( direction )
{
case Up:
y = y + 0.1;
break;
case Left:
x = x - 0.1;
break;
case Down:
y = y - 0.1;
break;
case Right:
x = x + 0.1;
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 );
// 45 degrees
temp->setRotation( rotation + 0.1 /*+ 0.785398*/ );
}
}
}
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;
}
}

DtWindowObjectsDriver.h

// /******************************************************************************
// ** Copyright (c) 2020 MAK Technologies, Inc.
// ** All rights reserved.
// ******************************************************************************/
#pragma once
namespace makVrv
{
class DtWindowObjectsDriver : public DtDriver
{
public:
{
Up = 0,
Left = 1,
Down = 2,
Right = 4
};
typedef std::vector<DtWindowObjectAgent*> DtWindowObjects;
DtWindowObjectsDriver( DtAgentManager& agentManager, const std::string& instanceName );
virtual const std::string& className() const;
virtual void drawObject();
virtual void drawPolygon();
virtual void drawLine();
virtual void drawText();
virtual void drawEllipse();
virtual void activateObjectType( int objectType );
virtual void modifyActivateObjectId( bool increaseIdNumber );
virtual void setParenting();
virtual void modifyObjectVisibility();
virtual void shiftWindowObjectPosition( DtDirection direction );
virtual void scaleWindowObject( DtDirection direction );
virtual void rotateWindowObject();
virtual DtWindowObjectAgent* findWindowObjectAgent( int vecLocation );
protected:
virtual bool onStart();
virtual bool onStop();
virtual bool onTick();
DtWindowSurfaceAgent* mySurface;
DtWindowPolygonAgent* mySurfaceClipBoxVisualPoly;
};
}

exampleWindowObjectsPluginInit.cxx

/******************************************************************************
** Copyright (c) 2020 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/
#include <vrvCore/DtDe.h>
#include <boost/bind.hpp>
#include <string>
#include <sstream>
using namespace makVrv;
void init( DtDe& de )
{
// Ensure that init only gets called once
// (not strictly necessary here, but this is good practice in general)
// We only want to create the accessory if we're running in master mode:
if ( de.isInMasterMode() )
{
// The accessory must be created after the DE's initialization is
// finished, to make sure all the objects it uses exist.
}
}
{
// Setup the plugin
init( *de );
return true;
}
{
&loadDriver, de ) );
DtWindowObjectsDriver* driver = new DtWindowObjectsDriver( de->agentManager(), "winowObjectDriver" );
de->driverManager().addDriver( driver );
DtInputDriver& inputDriver = de->driverManager().inputDriver();
DtKeyMapManager& keyMapManager = DtKeyMapManager::instance( *de );
// Over ride the default key map so our new key map will work
DtKeyMap* windowObjectMap = keyMapManager.createKeyMap( "WindowObjectMap" );
keyMapManager.activateMap( "WindowObjectMap" );
inputDriver.setKeyMap( "WindowObjectMap" );
// "SPACE" Draw Object!
keyMapManager.addKeyFunction( "Draw Window Object", boost::bind(
// "WASD" Move Window Object around the screen!
keyMapManager.addKeyFunction( "Shift Left", boost::bind(
keyMapManager.addKeyFunction( "Shift Right", boost::bind(
keyMapManager.addKeyFunction( "Shift Up", boost::bind(
keyMapManager.addKeyFunction( "Shift Down", boost::bind(
// "ARROWS" Scale Window Object
keyMapManager.addKeyFunction( "Scale X Up", boost::bind(
keyMapManager.addKeyFunction( "Scale X Down", boost::bind(
keyMapManager.addKeyFunction( "Scale Y Up", boost::bind(
keyMapManager.addKeyFunction( "Scale Y Down", boost::bind(
// "1-4" for type of object to create
// 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
for ( int i = 1; i < 5; ++i )
{
std::ostringstream ss;
ss << i;
keyMapManager.addKeyFunction( ss.str(), boost::bind(
ss.clear();
}
// "P" for parenting on / off, attaches new objects to the previously created one.
keyMapManager.addKeyFunction( "Parenting", boost::bind(
// "," and "." to move through the Object IDs / keys to control
keyMapManager.addKeyFunction( "DecreaseObjectId", boost::bind(
keyMapManager.addKeyFunction( "IncreaseObjectId", boost::bind(
// "R" to rotate selected Object
keyMapManager.addKeyFunction( "RotateObject", boost::bind(
// "V" to change the visibility of the Object
keyMapManager.addKeyFunction( "Visibility", boost::bind(
inputDriver.addKeyBinding( windowObjectMap, DtKeyState::KEY_SPACE, "Draw Window Object" );
inputDriver.addKeyBinding( windowObjectMap, DtKeyState::KEY_W, "Shift Up" );
inputDriver.addKeyBinding( windowObjectMap, DtKeyState::KEY_A, "Shift Left" );
inputDriver.addKeyBinding( windowObjectMap, DtKeyState::KEY_S, "Shift Down" );
inputDriver.addKeyBinding( windowObjectMap, DtKeyState::KEY_D, "Shift Right" );
inputDriver.addKeyBinding( windowObjectMap, DtKeyState::KEY_RIGHT, "Scale X Up" );
inputDriver.addKeyBinding( windowObjectMap, DtKeyState::KEY_LEFT, "Scale X Down" );
inputDriver.addKeyBinding( windowObjectMap, DtKeyState::KEY_UP, "Scale Y Up" );
inputDriver.addKeyBinding( windowObjectMap, DtKeyState::KEY_DOWN, "Scale Y Down" );
inputDriver.addKeyBinding( windowObjectMap, DtKeyState::KEY_1, "1"); // create polygon
inputDriver.addKeyBinding( windowObjectMap, DtKeyState::KEY_2, "2"); // create line
inputDriver.addKeyBinding( windowObjectMap, DtKeyState::KEY_3, "3"); // create text
inputDriver.addKeyBinding( windowObjectMap, DtKeyState::KEY_4, "4"); // create circle
inputDriver.addKeyBinding( windowObjectMap, DtKeyState::KEY_P, "Parenting" );
inputDriver.addKeyBinding( windowObjectMap, DtKeyState::KEY_COMMA, "DecreaseObjectId" );
inputDriver.addKeyBinding( windowObjectMap, DtKeyState::KEY_PERIOD, "IncreaseObjectId" );
inputDriver.addKeyBinding( windowObjectMap, DtKeyState::KEY_R, "RotateObject" );
inputDriver.addKeyBinding( windowObjectMap, DtKeyState::KEY_V, "Visibility" );
}

exampleWindowObjectsPluginInit.h

/******************************************************************************
** Copyright (c) 2020 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/
#pragma once
// Get proper local export symbol
// Setup proper plugin export symbol
#define DT_DE_PLUGIN_EXPORT_MACRO DT_DLL_EXAMPLEWINDOWOBJECTS
// Declare & export the plugin initialization function (bool initDeModule(DtDe* de))
namespace makVrv { class DtDe; }
// Work function for the plugin initialization

[<< Examples] [Home] [Top of Page]



Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)