The VRPNWrapper plugin consists of two main C# scripts which can be found in the Assets/Plugin directory of the Unity VRPNProject.

  • The VRPNManager.cs script is usually attached to the main camera and manages the creation and polling of VRPN clients and servers. The manager script operates either in client mode or server mode. In client mode, an external address of a running VRPN server is put into the Server Address field of the VRPNManager.cs script. In server mode, no external server address is provided and the script constructs and loads a VRPN sever configuration file.
  • When running in either client or server mode, VRPN analog tracking devices are created by adding a VRPNTracker.cs script to an untransformed Unity GameObject. The Tracker Type and Tracker Name fields list each device and assigned name found in the VRPN configuration file referenced in the Config File field of the VRPNManager.cs script. The VRPN configuration file, vrpn.cfg by default, is located in the Assets/Resources directory. When running in server mode, a separate configuration file is constructed and loaded that includes only the devices referenced and enabled by the existing VRPNTracker.cs scripts.

Each VRPNTracker script has several fields; apply tracking, sensor number and derivation, along with two transform references, Device To Unity and Sensor Offset. The apply tracking field should usually be set to “both” and indicates whether analog tracking data is applied to GameObject translation or orientation. VRPN analog trackers can have a sensor number and some trackers provide velocity and acceleration data. The derivation field is set to “none” by default and does not apply received data to the GameObject transform in “velocity” or “acceleration” modes. The Device To Unity transform is used to translate the reported VRPN data into the Unity coordinate system. Usually this is the unity transform, but can be used to offset or scale data coming in from the server. The Sensor Offset transform is used when the sensor device is offset from the actual desired tracking point.

The VRPNTrackerConfig.cs script is regenerated each time a new tracker name is added to the configuration file in the VRPNManager Config File field. The VRPNTrackerCalibrate.cs script can be added to each instance of the VRPNTracker.cs script game object. This script allows for the interactive adjustment of the VRPNTracker Sensor Offset field. It creates a GUI interface that allows position, orientation and camera field of view to be adjusted in realtime. The 8 key turns on the GUI and toggles through each VRPNTracker with and attached VRPNTrackerCalibrate script. Pressing the I,o,p and [ keys begins adjustment of field of view, orientation, XY axis translation or XZ axis translation respectively. Orientation and translation changes are made by switching the VRPNTracker into apply tracking mode of “none” and adjusting the Sensor Offset transform instead. Field of view adjustments are made via the mouse horizontal movement.