VR-Link C# API Documentation
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events Macros Pages
4.10 - Articulated Parts

Table of Contents

DIS and DIS-based FOMs like the RPR FOM define articulated parts as movable parts of an entity, such as a turret, gun, or landing gear.

The state of an entity's articulated parts is part of an entity's state, and is accessible through a DtEntityStateRepository.

A DtEntityStateRepository uses a DtArticulatedPartCollection (articulatedPartCollection.h), to store the articulated parts portion of its state. You can get a pointer to a DtEntityStateRepository's DtArticulatedPartCollection with its artPartList() member function.

4.10.1 Inspecting Articulated Parts Data

DtArticulatedPartCollection has many inspector functions for examining the state of an entity's articulated parts. The partCount() member function returns the number of articulated parts the entity has. For example, if a tank has a turret and a gun, partCount() returns 2. The totalParameterCount() member function returns the number of articulation parameters the entity is using to convey articulated parts information to the exercise. For example, if a tank is publishing information about its turret's azimuth and azimuth rate, and its gun's elevation, totalParameterCount() returns 3.

The DtArticulatedPartCollection has member functions (begin() and end()) that return the beginning and ending iterators of the collection, so that you can iterate through the articulated parts. Since the DtArticulatedPartCollection is an STL map, the iterator is a pair. first contains the part type of the articulated part; second contains a DtArticulatedPart pointer. To get a list of the parameters set for a DtArticulatedPart, call the getParameterMetrics() member function. To get the value of a particular parameter:

  1. Call isParameterSet().
  2. Call getParameterValue() on the articulated part.

If an articulated part parameter has a rate associated with it, and the rate has a value, the value returned is dead-reckoned to the current value of VR-Link simulation time. To retrieve the non dead-reckoned value, use the getParameter() member function. Pass in a reference to a DtArticulatedPart::Parameter structure, from which the value can be retrieved.

For example, do the following to inspect the value of the turret azimuth of an entity:

DtReflectedEntityList rel(...);
....
DtReflectedEntity* firstEnt = rel.first();
DtEntityStateRepository* esr = firstEnt->entityStateRep();
DtArticulatedPartCollection* artParts = esr->artPartList();
DtArticulatedPart* turret = artParts->findPart(DtPrimaryTurret1);
float turAz = 0.0;
if (turret)
{
if (turret->isParameterSet(DtApAzimuth))
{
turAz = turret->getParameterValue(DtApAzimuth);
}
else
{
printf("Entity has no turret azimuth.\n");
}
else
{
printf("Entity has no turret.\n");
}

To get more detailed information about articulated parts, including getting non-dead-reckoned values, you must look at the individual DtArticulatedPart objects that a DtArticulatedPartCollection uses to represent individual parts.

4.10.1.1 The DtArticulatedPart Class

You can get a pointer to a particular DtArticulatedPart (articulatedPart.h) by part type, with the DtArticulatedPartCollection findPart() member function. You can get a reference to the DtArticulatedPart with the getPart() member function. The findPart() function returns NULL if there is no part identified by the given part type. getPart() creates a new part with that type if there is no part of that type.

You can iterate through the DtArticulatedPartCollection as follows:

DtArticulatedPartCollection* parts = ...;
for (DtArticulatedPartCollection::iterator artPartIter = parts->begin();
artPartIter != parts->end();
++artPartIter)
{
int currentPartType = artPartIter->first;
DtArticulatedPart* currentPart = artPartIter->second;
}

You can also get a DtArticulatedPart's part type with the partType() member function. The partTypeAttachedTo() member function returns the type of the part to which the current part is attached. For example, a gun is often attached to a turret, whereas a turret is usually attached to the base entity (indicated by a return value of -1).

The number of parameters used for this part is found using parameterCount(), while getParameterMetrics() is used to fill a vector that you can use to iterate through the set of parameters, as follows:

DtArticulatedPart* part = ...;
std::vector<DtArticulatedPart::ParameterMetric> parameterMetrics;
part->getParameterMetrics(parameterMetrics);
std::vector<DtArticulatedPart::ParameterMetric>::const_iterator
paramIter = parameterMetrics.begin();
std::vector<DtArticulatedPart::ParameterMetric>::const_iterator
paramEnd = parameterMetrics.end();
for(;paramIter != paramEnd; ++paramIter)
{
int metric = *paramIter;
float value = part->getParameterValue(metric);
}

DtArticulatedPart::getVal() lets you inspect the value of a parameter by parameter type, returning the value, and returning 0.0 if the parameter is not valid for the part.

If you want to get the state of the part as a whole, instead of inspecting individual parameters, then use the functions translations() and angles(). You can get the part's state expressed as a vector of X, Y, and Z translations, or as a set of three angles representing azimuth, elevation, and rotation.

Both DtArticulatedPart and DtArticulatedPartCollection have printDataToStream() functions that print their data in human readable form.

4.10.2 Setting Articulated Parts Data

An articulated parts collection is empty when it is first created. To create articulated or attached parts, call the getPart() member function on the collection.

This creates a part of the specified type and returns it to the caller. To attach the part to another, call attachPart() on the collection, and pass in a pointer to the child part and a pointer to the parent part. By default, parts are attached to the base, for example:

DtArticulatedPartCollection* artPartCollection = myESR->artPartList();
DtArticulatedPart& turret = artPartCollection->getPart(DtPrimaryTurret1);
DtArticulatedPart& gun = artPartCollection->getPart(DtPrimaryGun1);
artPartCollection->attachPart(&gun, &turret);

This creates two parts: the turret and the gun, and attaches the gun to the turret.

When an articulated part is created, it has no parameters, and nothing will be sent in a network update if none have been set. To specify a parameter value, call setParameter() on the DtArticulatedPart (which could be retrieved by getPart()).

Note
getPart() returns the part if it exists. It creates a part if it does not exist.

The values for azimuth and azimuth rate are set for the turret, and the elevation is set for the gun as follows:

artPartCollection->getPart(DtPrimaryTurret1).setParameter(DtApAzimuth, DtDeg2Rad(myTurretAz));
artPartCollection->getPart(DtPrimaryTurret1).setParameter(
DtApAzimuthRate, DtDeg2Rad(myTurretAzRate));
artPartCollection->getPart(DtPrimaryGun1).setParameter(DtApElevation, DtDeg2Rad(myGunElev));
parttypeandattachedtype.png
Illustration of partType and attachedType

[<< Coordinate Views] [Home] [Top of Page] [Attached Parts >>]


Document ID: Generated on Mon Feb 6 18:36:34 EST 2017 from SVN revision 173107
Copyright © 2005-2016 VT MÄK. All Rights Reserved (www.mak.com)