VR-Link API Documentation for DIS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Listen C Example

This is a wrapped version of the Listen example, that works in the C environment.


First a C language interface is created. No classes or other C++ concepts are exported.

#ifdef __cplusplus
extern "C" {
#endif
/* routines to interface between listenC.c and VR-Link C++ calls */
void initVRLink(int argc, char *argv[]);
void tickVRLink();
#ifdef __cplusplus
}
#endif

Here is a C language program that uses the C Language interface.

#include <stdio.h>
#include "listenC.h"
#include "interface.h"
int main(int argc, char *argv[])
{
double *firstPos;
/* this C++ function is being called from C */
initVRLink(argc, argv);
while (1)
{
firstPos = firstEntityPosition();
if (firstPos)
{
printf("Position of first entity: %.1f %.1f %.1f\n",
firstPos[0], firstPos[1], firstPos[2]);
}
}
return 0;
}
/* this C function will be called from C++ */
void firePrint(const char* attacker)
{
printf("Fire Pdu from %s\n", attacker);
}

We write the wrapper code in C++ inside the interface.

/*********************************************************************
** Copyright (c) 1997 MaK Technologies, Inc.
** All rights reserved.
*********************************************************************/
#include "listenC.h"
#include "interface.h"
/* routines to interface between listenC.c and VR-Link C++ calls */
static void fireCb(DtFireInteraction *inter, void *);
static DtExerciseConn *exConn;
void initVRLink(int argc, char *argv[])
{
// Create a VR-Link initializer to parse command lines.
DtVrlApplicationInitializer appInit(argc, argv, "VR-Link ListenC");
// Parse the command lines.
appInit.parseCmdLine();
// Connect to the RTI or the Network.
exConn = new DtExerciseConn(appInit);
// Add a callback for FIRE interactions/PDUs
DtFireInteraction::addCallback(exConn, fireCb, NULL);
// Create a class which will contain all known entities from the network.
rva = new DtReflectedEntityList(exConn);
// Set up our time.
}
void tickVRLink()
{
exConn->drainInput();
DtSleep(0.1);
}
{
DtReflectedEntity *first = rva->first();
if (first)
{
return (double *) (const double*) first->entityStateRep()->location();
}
return NULL;
}
static void fireCb(DtFireInteraction *inter, void *)
{
}


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)