![]() |
VR-Link API Documentation for DIS
|
The directory .
/examples/simpleC contains an example of using VR-Link with an application written in C. The example is a C version of the listen-only program described in 2.9.1 A Listen-Only Example. For details, please see the header files interface.h and simpleC.h.
Since VR-Link is a C++ toolkit, any code that directly calls a VR-Link function must be compiled by a C++ compiler. You can compile this code in such a way that it may be called from C. To do so, you need at least one C++ file from which all calls to VR-Link functions can be made. In our example, the file interface.cxx serves this purpose. It contains several functions that interact with VR- Link code: initVRLink(), tickVRLink(), and firstEntityPosition().
To alert the C++ compiler that these functions should be compiled to be callable from C, their declarations are surrounded by the following keywords, as seen by the C++ compiler:
The file listenC.c represents the rest of the application. It is compiled by a C compiler, and does not directly call any VR-Link functions. It does, however, call the functions defined in interface.cxx that were compiled to be called from C.
You can create a C++ function that interfaces with VR-Link code and can also call C functions. For example, in interface.cxx, the callback on Fire PDUs (fireCb) is a C++ function which calls the C function firePrint().
To alert the C++ compiler that an external function is a C function, its declaration is surrounded by the following keywords, as seen by the C++ compiler:
When C and C++ code interact, the declarations of many of the same functions must be included by both C and C++ code. As described above, these declarations need to be surrounded by:
when presented to the C++ compiler. However, these keywords are meaningless to a C compiler, so that they should always be surrounded by:
For example, listenC.h reads as follows:
[<< Compiling and Linking a VR-Link Application] [Home] [Top of Page] [Delivering VR-Link Applications to Users >>]