VR-Link API Documentation for HLA Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
9.7 - Callbacks and Interactions

Interactions are handled differently than objects.

Typically, interactions are created and sent one time, then received and reacted to appropriately. An example of such interaction is the FireMessage. Interactions are denoted as messages in VR-Link for C#. The f18-Sharp example has the ability to fire at other entities, and it does so with fire interactions.

To send a fire interaction (FireMessage), create it and send it with the exercise connection. Here is a snippet from the example:

myFire = new FireMessage();
//Fill out FireMessage here
...
myFire.worldPosition = ESR.worldPosition;
myFire.velocity = ESR.worldVelocity;
...
myExConn.sendMessage(myFire);

This code creates and sends a FireMessage over the exercise connection.

To be able to receive a FireMessage the exercise connection needs to register a callback for receiving it, for example (from the VehicleSim class):

myExConn.addMessageHandler(FireMessage.theName, new MessageDelegate(processFireMessage));

This code uses the addMessageHandler() function. addMessageHandler() takes the name associated with the interaction type and a new MessageDelegate, which is a function to call when the message is received. The name is a static string defined within the message. The delegate is how you handle the interaction. Here is how f18-Sharp handles receiving a FireMessage:

internal void processFireMessage(Message m)
{
Console.WriteLine("Fire Message received from entity " + fm.firingId + " targeting entity " + fm.targetId + ".");
}

[<< Reflected Objects] [Home] [Top of Page]


Document ID: Generated on Tue Feb 2 21:02:17 EST 2021 from SVN revision 223668
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)