VR-Forces 4.6.1 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
exampleCloudDriver

This example is a plugin that creates a new driver.

This driver reads a CSV file (clouds.csv), then dynamically places clouds in the scene. The CSV file contains information about cloud layers and wind volumes. This example is meant to be used in flat earth projections only. The cloud layer coordinates are in database coordinates.

At each tick, the driver moves each cloud layer based on the wind volumes at its altitude.

Wind volumes are stored as DtWind classes and are declared in DtCloudDriverCommon.h. A wind volume consists of a direction in degrees from north to east, a minimum and maximum altitude, and a speed in meters per second.

/******************************************************************************
** Copyright (c) 2011 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/
#pragma once
#include <vector>
namespace makVrv
{
namespace vrvExampleCloudDriver
{
class DtWind
{
public:
DtWind(double directionN2E,
double minAltitude = 0,
double maxAltitude = 100000,
double speedInMps = 100);
bool withinAltitude(double alt) const;
double dirNtoE;
double northVel;
double eastVel;
double minAlt;
double maxAlt;
double speed;
};
typedef std::vector<DtWind> WindList;
}
}

The driver's onStart() method does two things: First it connects to the DtEnvironmentSignaler's signal_cloudLayerAdded and signalCloudLayerToBeDestroyed signals. These are used to keep track of the current cloud layers in the scene.

DtEnvironmentSignaler::instance(myAgentManager.de()).signal_cloudLayerAdded.connect(
boost::bind(&DtCloudDriver::on_cloudLayerAdded,this,_1));
DtEnvironmentSignaler::instance(myAgentManager.de()).signal_cloudLayerToBeDestroyed.connect(
boost::bind(&DtCloudDriver::on_cloudLayerDestroyed,this,_1));

Then it parses the CSV file first and then creates the cloud layers and wind volumes.

DtCloudParser parser;
if (!parser.parseFile("../examples/exampleCloudDriver/clouds.csv"))
{
DtWarn << "Error parsing cloud file clouds.csv" << std::endl;
}
else
{
makeClouds(parser);
makeWind(parser);

In the driver's onTick() method, the cloud layer list is iterated over, and for each wind volume, if the cloud layer's altitude falls within the wind volume, it is moved the appropriate distance.

for (int index = 0; index < myCloudLayers.size(); ++index)
{
makArchives::DtCloudLayerRecord& cloud = myCloudLayers[index];
bool changed = false;
double cloudAltitude = cloud.position()[2];
BOOST_FOREACH(DtWind& wind, myWindList)
{
if (wind.withinAltitude(cloudAltitude))
{
double eastChange = wind.eastVel * dt;
double northChange = wind.northVel * dt;
cloud.setPosition(cloud.position()[0] + eastChange,
cloud.position()[1] + northChange,cloud.position()[2]);
changed = true;

The plugin initialization is performed in exampleCloudDriverPluginInit.cxx. This consists of the exported function initDeModule(), and a couple of other helper functions. The init() function connects to the display engine's signal_postInitialize signal. After the DtDe has been initialized, installDriver() will be called, which will install the DtCloudDriver into the driver manager, and set it to automatically start.

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


exampleCloudDriverPluginInit.cxx

/******************************************************************************
** Copyright (c) 2011 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/
#include "DtCloudDriver.h"
#include <vrvCore/DtDe.h>
#include <boost/bind.hpp>
{
{
return true;
}
return false;
}
namespace makVrv
{
namespace vrvExampleCloudDriver
{
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 driver if we are running in master mode.
if (de.isInMasterMode())
{
// The driver must be created after the DE's initialization is
// finished, to make sure all the objects it uses exist.
de.signal_postInitialize.connect(boost::bind(
&installDriver, boost::ref(de) ));
}
}
void installDriver(DtDe& de)
{
DtCloudDriver* driver = new DtCloudDriver( de.agentManager());
driver->setAutoStart(true);
// prevent the driver from being added to the connections list
driver->setIsUserControllable(false);
de.driverManager().addDriver(driver);
}
}
}

Document ID: Generated on Wed Jul 25 16:57:45 EDT 2018 from SVN revision 190790
Copyright © 2005-2018 VT MÄK. All Rights Reserved (www.mak.com)