VR-Link C# API Documentation
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events Macros Pages
9.6 - Reflected Objects

A reflected object is a class used to store information about an object that has been discovered on the exercise connection.

A reflected object list keeps track of multiple reflected objects. The reflected object lists also handle the callbacks associated with discovering, updating, and deleting objects. This means that when an object is published from a source that the VR-Link application can receive information from, the reflected object list is notified and handles the information according to its callback functions. For example, if an object is discovered, the reflected object list stores it. If an object is updated, the refelected object is updated.

In the F-18 example, the ReflectedEntityList is used to store multiple ReflectedEntity types. First, the reflected list is created using the exercise connection defined.

ReflectedEntityList rel = new ReflectedEntityList(exConn);

Now that the ReflectedEntityList is hooked into the exercise connection, we need to make sure the exercise connection is listening to input. To do that we use the drainInput(t) function inside the simulation's main loop. drainInput() takes a double representing the max time between updates. In f18-Sharp:

exConn.drainInput(-1.0);

This used so that the exercise connection is constantly listening to input (negative value).

From this point we have a ReflectedEntityList that will pick up entities that are published on the exercise connection. In the f18-Sharp example, the reflected entity list is used to find the closest entity when firing a projectile. Here is an example of a way to use this information:

static ReflectedEntity nearestEntity(string myObjId,Vector3d geocPos, ReflectedEntityList rel)
{
ReflectedEntity nearest = null;
double minDistSqr = 0.0;
// Loop through the entities in the rel
foreach (ReflectedEntity re in rel.entities)
{
if (re.esr.id == myObjId)
continue;
//NOTE: Is world position correct? Does this temp creation work?
double distSqr = (re.esr.worldPosition - geocPos).LengthSquared;
if (distSqr < minDistSqr || nearest == null)
{
nearest = re;
minDistSqr = distSqr;
}
}
return nearest;
}

[<< Publishing Objects] [Home] [Top of Page] [Callbacks and Interactions >>]


Document ID: Generated on Mon Apr 8 04:49:21 EDT 2019 from SVN revision 197403
Copyright © 2005-2016 VT MÄK. All Rights Reserved (www.mak.com)