VR-Forces Development_Version Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
4.3 - Creating a Simulation Object

Table of Contents

The Object Manager creates simulation objects with the DtVrfObjectManager::createAndInitVrfObject() member function.

An Object Manager may create a simulation object under the following circumstances:

Note
If a back-end reads the order of battle file, it does not read the object map file and creates all simulation objects as local simulation objects.
VR-Forces will not create simulation objects unless a simulation has loaded a terrain and a coordinate system exists.

4.3.1 Creating a Local Simulation Object from Within an Application

If you want to create a local simulation object from within an application, call DtVrfObjectManager::createAndInitVrfObject(). The createAndInitVrfObject() member function creates and initializes the new DtVrfObject, and adds it to the Object Manager. Call the form of createAndInitVrfObject() that takes a single position as an argument. This form is suitable for creating simulation objects that have simple geometry defined by a single vertex. For example, to create a new M1A2 tank, do the following:

DtVrfObject * tank;
// M1A2 object type.
// Extensions to object type enumerations are in objTypeEnums.h
DtObjectType tankType(1, 1, 1, 225, 1, 1, 3, 0);
// Initial position of object, in local (database) coordinates.
DtVector initialPosition(2000.0, 4000.0, 0.0);
// Ask the Object Manager to generate the next available unique name.
// It will generate a name similar to "M1A2 1".
DtString name = objectManager->nextName(tankType, DtForceFriendly);
tank = objectManager->createAndInitVrfObject(
tankType,
true,
name,
DtString::nullString(),
DtForceFriendly,
initialPosition);

The echelon ID is not immediately available when a new organized simulation object is created. It may take one or more simulation ticks before the echelon ID gets assigned to the new simulation object. To get notified when the echelon ID is assigned or changed, you can register a callback function with the object. For example:

tank->addVrfObjectPredicateCallback(echelonIdChangedCb, pred);

In the callback function echelonChangedCb(), you can examine the echelon ID, for example:

static void echelonIdChangedCb(DtVrfObject * obj, DtVrfObjectPredicateEvaluator* predicateEval, void * usr)
{
DtInfo("Echelon Id: %s);
}
Note
Do not call the DtVrfObject constructor directly. Do all of the creation of DtVrfObjects through the Object Manager (through its createAndInitVrfObject()) functions. The Object Manager not only instantiates the object, but initializes and adds the object to itself for management.

[<< Components and The Component Manager] [Home] [Top of Page] [Managing Local and Remote Simulation Objects >>]


Document ID: Generated on Tue Mar 8 22:13:38 EST 2016 from SVN revision 162938
Copyright © 2005-2015 VT MÄK. All Rights Reserved (www.mak.com)