// Update is called once per frame void Update() { // Poll new data from Unity VRPNController.VrpnUpdate(device_id); // This is an example of how to move a cube with the mouse using VRPN transform.localPosition = new Vector3((mouse_x - 0.5f) * 5, -(mouse_y - 0.5f) * 5, 0); }
// Free the VRPN and Vrpn2Unity resources. // Don't use OnDestory for this because if you modify your script while Unity is // running the only two methods called to notify of it are: OnEnable() and // OnDisable(). void OnDisable() { if (device_id != -1) { Debug.Log("Freeing resources used by VRPN and Vrpn2Unity for " + "device_id:" + device_id); VRPNController.VrpnOnDestroy(device_id); device_id = -1; } }
//************************************************************************* // Unity callbacks necessary to react for obejct's lifetime events //************************************************************************* // Start the VRPN connection through Vrpn2Unity. // Don't use Start for this because if you modify your script while Unity is // running the only two methods called to notify of it are: OnEnable() and // OnDisable(). void OnEnable() { // Open the device for button+analog updates. Note that as a mouse // doesn't generate tracker callbacks we are passing 'null' as the // tracker delegate. device_id = VRPNController.VrpnStart(device_address, new VRPNController.AnalogCallback(onMouseMove), new VRPNController.ButtonCallback(onMouseButton), null); Debug.Log("Opened VRPN device " + device_address + " with device_id:" + device_id); }