The example will run through a series of 3D objects (sphere/cube/cylinder/line), then move on to 2D objects (text/line/circle/triangle/square). Please note that in order to see the 3D objects, you need to load Makland.mtf, and use the saved view "exampleDrawObjectsMaklandView.osrx".
This example is an application. First open Vantage, load MakLand terrain than from the "Observer Views" panel click on "import and append views" and select "exampleDrawObjectsMaklandView.osrx" then click on "remoteGraphicsMaklandView", then connect with the <protocol> you will use the example with. Run ./bin64/exampleDrawObjects<protocol>.exe (on Windows) or ./bin64/exampleDrawObjects<protocol> (on Linux). Upon running this example, any running instances of VR-Vantage that are connected to the appropriate connection (DIS/HLA13/HLA1516) will display the objects rendered by the example.
#include <vl/exerciseConn.h>
#include <vl/exerciseConnInitializer.h>
#include <vlutil/vlProcessControl.h>
#include <matrix/utmCoord.h>
#include <matrix/vlTaitBryan.h>
#include <vl/dataInteraction.h>
#include <matrix/topoCoord.h>
#include <stdio.h>
#include <vlutil/vlKeyboard.h>
#ifdef DtDIS
# define DT_PROTOCOL_NAMESPACE vrvDis
#else
# ifdef DtHLA_1516_EVOLVED
# define DT_PROTOCOL_NAMESPACE vrvHla1516e
# else
# ifdef DtHLA_1516
# define DT_PROTOCOL_NAMESPACE vrvHla1516
# else
# ifdef DtHLA
# define DT_PROTOCOL_NAMESPACE vrvHla13
# define DL_DLL_IGCONVRLINK DT_DLL_VRVHLA13
# else
# error "Protocol not specified or unsupported."
# endif
# endif
# endif
#endif
#if DtHLA
#endif
using namespace vrvControlToolkit;
DtExerciseConn* exConn;
std::vector<DtDrawControlObject*> myObjects;
int id = 0;
void updateObjects(double time = 0.0)
{
if (time > 0.0)
{
DtTime tickTime = exConn->clock()->elapsedRealTime();
while (exConn->clock()->simTime() <= tickTime + time)
{
exConn->drainInput();
for (unsigned int i = 0; i < myObjects.size(); ++i)
{
myObjects[i]->update();
}
exConn->clock()->setSimTime(exConn->clock()->elapsedRealTime());
DtSleep(0.1);
}
}
else
{
exConn->drainInput();
for (unsigned int i = 0; i < myObjects.size(); ++i)
{
myObjects[i]->update();
}
exConn->clock()->setSimTime(exConn->clock()->elapsedRealTime());
}
}
void setMsg(char *msg)
{
DtNetU8 ucolor[4] = {255, 255, 255, 255};
double pos1[2];
pos1[0] = (-40 / 200.) + .5;
pos1[1] = (70 / 200.) + .5;
if (!myText)
{
exConn->drainInput();
myText->setFlashing(0);
DtVdcColor colorToSet(ucolor[0], ucolor[1], ucolor[2], ucolor[3]);
myText->setColor(colorToSet);
myObjects.push_back(myText);
}
myText->setFont("$(SHARED_DATA_DIR)/Fonts/FreeSans.otf", 14);
myText->setText(msg);
myText->update();
exConn->drainInput();
DtSleep(0.1);
}
{
sprintf(showSetCommand.
mySetName,
"%s", setName.c_str());
DtDataInteraction dataInter;
myCommandMarshaller.encode(&showSetCommand, &dataInter);
exConn->sendStamped(dataInter);
}
{
sprintf(showSetCommand.
mySetName,
"%s", setName.c_str());
DtDataInteraction dataInter;
myCommandMarshaller.encode(&showSetCommand, &dataInter);
exConn->sendStamped(dataInter);
}
void demo2d()
{
id = 100;
showSet("2D Objects");
setMsg("2D Demo, Text....");
showSet("2D Objects::Text");
int i;
double pos1[2], pos2[2];
double rot;
pos1[0] = .1;
pos1[1] = .3;
ucolor[0] = 255;ucolor[1] = 255; ucolor[2] = 255; ucolor[3] = 255;
char texts[3][256] ={"2DText1", "2DText2", "2DText with spaces 3"};
for (i = 0; i < 3; i++)
{
myObjects.push_back(text2D);
updateObjects();
ucolor[i] -= 50;
pos1[1] += 0.2;
DtSleep(1);
}
DtSleep(2);
hideSet("2D Objects::Text");
setMsg("2D Demo, Squares....");
showSet("2D Objects::Squares");
pos1[0] = .3;
pos1[1] = .2;
rot = 0;
scale[0] = 0.15;
scale[1] = 0.15;
pattern = 0xffffffff;
ucolor[0] = 255;ucolor[1] = 255; ucolor[2] = 255; ucolor[3] = 255;
for (i = 0; i < 4; i++)
{
myObjects.push_back(square);
updateObjects();
pattern -= 678;
ucolor[i%3] -= 120;
pos1[1] += .15;
rot += DtDeg2Rad(35);
scale[i%2] += 0.05 *(i+1);
DtSleep(1);
}
DtSleep(2);
hideSet("2D Objects::Squares");
setMsg("2D Demo, Circles....");
showSet("2D Objects::Circles");
pos1[0] = 0.5;
pos1[1] = 0.1;
rot = 0;
scale[0] = 0.15;
scale[1] = 0.15;
pattern = 0xbbbbbbbb;
ucolor[0] = 255;ucolor[1] = 255; ucolor[2] = 255; ucolor[3] = 255;
for (i = 0; i < 4; i++)
{
myObjects.push_back(circle);
updateObjects();
pattern -= 678;
ucolor[i%3] -= 80;
pos1[1] += 0.2;
rot += DtDeg2Rad(55);
scale[i%2] += 0.05 *(i+1);
DtSleep(1);
}
DtSleep(2);
hideSet("2D Objects::Circles");
setMsg("2D Demo, Triangles....");
showSet("2D Objects::Triangles");
pos1[0] = 0.7;
pos1[1] = 0.2;
rot = 0;
scale[0] = 0.05;
scale[1] = 0.05;
pattern = 0xbbbbbbbb;
ucolor[0] = 255;ucolor[1] = 255; ucolor[2] = 255; ucolor[3] = 255;
points[0] = DtVector(0, 0, .5);
points[1] = DtVector(1, 0, .5);
points[2] = DtVector(.5, 1, .5);
for (i = 0; i < 4; i++)
{
triangle->
setFill((((i+1)%3) != 0));
myObjects.push_back(triangle);
updateObjects();
pattern -= 678;
ucolor[i%3] -= 80;
pos1[1] += 0.2;
rot += DtDeg2Rad(55);
scale[i%2] += 0.05 *(i+1);
DtSleep(1);
}
DtSleep(2);
hideSet("2D Objects::Triangles");
setMsg("2D Demo, Lines....");
showSet("2D Objects::Lines");
pos2[0] = 0.75;
pos2[1] = 0.2;
pos1[0] = 0.25;
pos1[1] = 0.5;
rot = 0;
scale[0] = 0.05;
scale[1] = 0.05;
pattern = 0xffffffff;
ucolor[0] = 255;ucolor[1] = 255; ucolor[2] = 80; ucolor[3] = 255;
int thick = 1;
for (i = 0; i < 4; i++)
{
myObjects.push_back(line);
updateObjects();
thick += 1;
pattern -= 678;
ucolor[i%3] -= 80;
pos1[1] += .075;
pos2[1] += .075;
DtSleep(1);
}
DtSleep(2);
hideSet("2D Objects::Lines");
pattern = 0xffffffff;
setMsg("2D Demo, Segmented Line....");
showSet("2D Objects::Segmented Lines");
pos2[0] = 0.9;
pos2[1] = 0.1;
pos1[0] = 0.1;
pos1[1] = 0.9;
4);
thick = 1;
ucolor[0] = 255;ucolor[1] = 255; ucolor[2] = 255; ucolor[3] = 255;
for (i = 0; i < 4; i++)
{
pattern -= 0x11111111;
ucolor[i%3] -= 100;
thick += 2;
}
myObjects.push_back(segLine);
updateObjects(2.0);
setMsg("2D Demo, Changing Segmented Line....");
int dt = 25;
int inc = -1;
for(int j = 0; j < 200; j++)
{
for (i = 1; i < 3; i++)
{
}
dt += inc;
if (dt == 25 || dt == 1)
inc *= -1;
updateObjects();
DtSleep(0.1);
}
DtSleep(2);
showSet("2D Objects::Text");
showSet("2D Objects::Squares");
showSet("2D Objects::Circles");
showSet("2D Objects::Triangles");
showSet("2D Objects::Lines");
DtSleep(3);
hideSet("2D Objects");
}
void demo3d()
{
int i = 0;
id = 1000;
showSet("3D Objects");
setMsg("Area...");
showSet("3D Objects::Areas");
unsigned ar1 = id++;
std::vector<DtVector> vertices;
vertices.push_back(DtVector(3140604, 5441190, 1101666));
vertices.push_back(DtVector(3140317, 5440732, 1101132));
vertices.push_back(DtVector(3140185, 5440580, 1101789));
myObjects.push_back(ar);
updateObjects(1.0);
DtSleep(5);
hideSet("3D Objects::Areas");
setMsg("Sphere...");
showSet("3D Objects::Ellipsoids");
unsigned sph1 = id++;
DtVector(20, 20, 20));
myObjects.push_back(sphere);
updateObjects(2.0);
setMsg("Scaling sphere...");
int scales[3];
scales[0] = 20;
scales[1] = 20;
scales[2] = 20;
int inc = 0;
inc = 0;
int clplus = 5;
for (i = 0; inc < 3; i++)
{
scales[inc] += 4;
clsp1[2] += clplus;
sphere->
setDiameters(DtVector(scales[0], scales[1], scales[2]));
updateObjects();
if (scales[inc] > 60)
inc++;
DtSleep(0.1);
}
setMsg("Rotating sphere...");
inc = 0;
scales[0] = 10;
scales[1] = 10;
scales[2] = 10;
for (i = 0; inc < 3; i++)
{
scales[inc] += 5;
clsp1[2] += clplus;
if (clsp1[2] == 250 || clsp1[2] == 50)
clplus *= -1;
sphere->
setRotation(DtTaitBryan(DtDeg2Rad(scales[0]), DtDeg2Rad(scales[1]), DtDeg2Rad(scales[2])));
updateObjects();
if (scales[inc] > 60)
inc++;
DtSleep(0.1);
}
hideSet("3D Objects::Ellipsoids");
setMsg("Cube...");
showSet("3D Objects::Cuboids");
unsigned cubeId = id++;
myObjects.push_back(cube);
updateObjects(2.0);
setMsg("Scaling cube...");
scales[0] = 10;
scales[1] = 10;
scales[2] = 10;
inc = 0;
clplus = 5;
for (i = 0; inc < 3; i++)
{
scales[inc] += 4;
clsp1[3] += clplus;
if (clsp1[3] == 250 || clsp1[3] == 50)
clplus *= -1;
updateObjects();
if (scales[inc] > 60)
inc++;
DtSleep(0.1);
}
setMsg("Rotating cube...");
inc = 0;
scales[0] = 10;
scales[1] = 10;
scales[2] = 10;
for (i = 0; inc < 3; i++)
{
scales[inc] += 5;
clsp1[2] += clplus;
if (clsp1[2] == 250 || clsp1[2] == 50)
clplus *= -1;
cube->
setRotation(DtTaitBryan(DtDeg2Rad(scales[0]), DtDeg2Rad(scales[1]), DtDeg2Rad(scales[2])));
updateObjects();
if (scales[inc] > 60)
inc++;
DtSleep(0.1);
}
updateObjects();
hideSet("3D Objects::Cuboids");
setMsg("Cylinder...");
showSet("3D Objects::Cylinders");
int cyl1 = id++;
myObjects.push_back(cylinder);
updateObjects(2.0);
setMsg("Scaling cylinder...");
scales[0] = 20;
scales[1] = 4;
scales[2] = 4;
inc = 0;
clplus = 5;
for (i = 0; inc < 3; i++)
{
scales[inc] += 4;
clsp1[3] += clplus;
if (clsp1[3] == 250 || clsp1[3] == 50)
clplus *= -1;
updateObjects();
if (scales[inc] > size)
{
inc++;
size = 15;
}
DtSleep(0.1);
}
setMsg("Rotating cylinder...");
inc = 0;
scales[0] = 10;
scales[1] = 10;
scales[2] = 10;
for (i = 0; inc < 3; i++)
{
scales[inc] += 5;
clsp1[2] += clplus;
if (clsp1[2] == 250 || clsp1[2] == 50)
clplus *= -1;
cylinder->
setRotation(DtTaitBryan(DtDeg2Rad(scales[0]), DtDeg2Rad(scales[1]), DtDeg2Rad(scales[2])));
updateObjects();
if (scales[inc] > 60)
inc++;
DtSleep(0.1);
}
updateObjects();
setMsg("3D texts");
showSet("3D Objects::Text");
myObjects.push_back(text);
updateObjects(2.0);
myObjects.push_back(text2);
updateObjects(2.0);
DtSleep(4);
hideSet("3D Objects::Cylinders");
hideSet("3D Objects::Text");
setMsg("3D lines");
showSet("3D Objects::Lines");
int line1 = id++;
myObjects.push_back(line);
updateObjects(2.0);
myObjects.push_back(line2);
updateObjects(2.0);
DtSleep(4);
hideSet("3D Objects::Lines");
setMsg("Segmented line....");
showSet("3D Objects::Segmented Lines");
myObjects.push_back(segLine);
linecolor2[0] = 255;linecolor2[1] = 255; linecolor2[2] = 255; linecolor2[3] = 255;
for (i = 0; i < 4; i++)
{
linecolor2[i%3] -= 100;
}
updateObjects(2.0);
setMsg("Changing segmented Line....");
int dt = 25;
inc = -1;
for(int j = 0; j < 200; j++)
{
for (i = 1; i < 3; i++)
{
}
dt +=inc;
if (dt == 1 || dt == 25)
inc *= -1;
updateObjects();
DtSleep(0.1);
}
DtSleep(2);
showSet("3D Objects::Cuboids");
showSet("3D Objects::Ellipsoids");
showSet("3D Objects::Cylinders");
showSet("3D Objects::Text");
showSet("3D Objects::Lines");
showSet("3D Objects::Areas");
DtSleep(3);
hideSet("3D Objects");
return;
}
int main(int argc, char** argv)
{
appInit.parseCmdLine();
#if DtHLA
appInit.setFomMapper( fixFomMapper );
#endif
exConn = new DtExerciseConn(appInit);
exConn->setApplicationId(3, 5);
#if DtHLA
fixFomMapper->
init( exConn );
exConn->ignoreAdvisories();
#endif
setMsg("start demo 3D..");
demo3d();
setMsg("End demo 3D..");
DtSleep(2);
setMsg("Start demo 2D..");
demo2d();
setMsg("End demo 2D..");
for (unsigned int i = 0; i < myObjects.size(); ++i)
{
delete myObjects[i];
}
delete exConn;
return 0;
}