VR-Forces 4.0.4 Class Documentation
Creating an Entity

Table of Contents

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

An Object Manager may create an entity 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 entities as local entities.
VR-Forces will not create entities unless a simulation has loaded a terrain and a coordinate system exists.

Creating a Local Entity from Within an Application

If you want to create a local entity 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 entities 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 entity type enumerations are in objTypeEnums.h
DtObjectType tankType(1, 1, 1, 225, 1, 1, 3, 0);

// Initial position of entity, 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 entity is created. It may take one or more simulation ticks before the echelon ID gets assigned to the new entity. To get notified when the echelon ID is assigned or changed, you can register a callback function with the object. For example:

#include "echelonIdChangedPred.h"
DtEchelonIdChangedPredicate pred(tank->echelonIdString());
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 Entities >>]


Document ID: Generated on Fri Jun 29 16:33:32 EDT 2012 from SVN revision 116588
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)