UnityMol  0.9.6-875
UnityMol viewer / In developement
VRPNTestScript.cs
Go to the documentation of this file.
1 using UnityEngine;
2 using System.Collections;
3 using System.Runtime.InteropServices;
4 using System;
5 using System.Threading;
6 using System.Reflection;
7 
8 public class VRPNTestScript : MonoBehaviour {
9 
10  System.IntPtr t;
11  System.IntPtr b;
12  System.IntPtr f;
13  System.IntPtr a;
14 
15  static GameObject go;
16 
17  static float factor = 25f;
18 
19  public void dummyLogger(uint sensor, System.IntPtr pos, System.IntPtr quat)
20  {
21  double[] managedArray = new double[3];
22  double[] quaternionArray = new double[4];
23  Marshal.Copy(pos, managedArray, 0, 3);
24  Marshal.Copy(quat, quaternionArray, 0, 4);
25 
26  go.transform.position = new Vector3((float)managedArray[0] * factor, (float)managedArray[1] * factor, (float)managedArray[2] * factor);
27 
28  go.transform.rotation = new Quaternion((float)quaternionArray[0], (float)quaternionArray[1], (float)quaternionArray[2], (float)quaternionArray[3]);
29  }
30 
31  public static void dummyButtonLogger(Int32 button, Int32 state)
32  {
33  Debug.Log("Button " + button + " in state " + state);
34  }
35 
36  public static void dummyAnalogLogger(VRPN.Wrapper.VRPNAnalogReport report)
37  {
38  Debug.Log("----------");
39  Debug.Log(report.tv_sec);
40  Debug.Log(report.tv_usec);
41  Debug.Log(report.num_channel);
42  Debug.Log("----------Tran");
43  Debug.Log(report.channel[0]);
44  Debug.Log(report.channel[1]);
45  Debug.Log(report.channel[2]);
46  Debug.Log("----------Rot");
47  Debug.Log(report.channel[3]);
48  Debug.Log(report.channel[4]);
49  Debug.Log(report.channel[5]);
50  }
51 
53 
54  // Use this for initialization
55  void Start () {
57 
58  Debug.Log("VRPNTestScript::Start");
60  MethodInfo minfo = typeof(VRPNTestScript).GetMethod("dummyLogger");
61  functionPointer = (VRPN.Wrapper.TrackerCallbackDelegate) Delegate.CreateDelegate(typeof(VRPN.Wrapper.TrackerCallbackDelegate), this, minfo, false);
62 
66 
68  b = VRPN.Wrapper.vrpn_c_open_button("Omni@baaden", buttonFunctionPointer);
69 
70  f = VRPN.Wrapper.vrpn_c_open_force_feedback("Omni@baaden");
71 
73  a = VRPN.Wrapper.vrpn_c_open_analog("device0@localhost", analogFunctionPointer);
74 
75  go = GameObject.CreatePrimitive(PrimitiveType.Capsule);
76  }
77 
78  void OnDestroy () {
79  Debug.Log("Destroying VRPNTestScript");
85  }
86 
87  // Update is called once per frame
88  void Update () {
90  manager.DeviceLoop();
94  }
96  Debug.Log(VRPN.Wrapper.vrpn_c_poll_tracker(t));
100  Debug.Log(VRPN.Wrapper.vrpn_c_poll_button(b));
101  Debug.Log(VRPN.Wrapper.vrpn_c_poll_analog(a));
102  bool isForceSet = VRPN.Wrapper.vrpn_c_force_feedback_set_force(f, 0.4f, 0.4f, 0.4f);
103  Debug.Log(isForceSet);
104  }
105 }
static bool vrpn_c_button_is_connected(System.IntPtr device)
static System.IntPtr vrpn_c_open_analog(string name, AnalogCallbackDelegate analogCallbackF)
static bool vrpn_c_close_analog(System.IntPtr device)
static void dummyButtonLogger(Int32 button, Int32 state)
static GameObject go
static bool vrpn_c_poll_analog(System.IntPtr device)
System.IntPtr f
static bool vrpn_c_close_button(System.IntPtr device)
static VRPN.VRPNManager getVRPNManager()
Definition: UnityMolMain.cs:58
delegate void ButtonCallbackDelegate(Int32 button, Int32 state)
static bool vrpn_c_tracker_is_connected(System.IntPtr device)
static bool vrpn_c_close_force_feedback(System.IntPtr device)
delegate void AnalogCallbackDelegate(VRPN.Wrapper.VRPNAnalogReport report)
System.IntPtr t
static System.IntPtr vrpn_c_open_button(string name, ButtonCallbackDelegate buttonCallbackF)
static System.IntPtr vrpn_c_open_force_feedback(string name)
void dummyLogger(uint sensor, System.IntPtr pos, System.IntPtr quat)
static float factor
delegate void TrackerCallbackDelegate(uint sensor, System.IntPtr pos, System.IntPtr quat)
VRPN.Wrapper.TrackerCallbackDelegate functionPointer
static void dummyAnalogLogger(VRPN.Wrapper.VRPNAnalogReport report)
static System.IntPtr vrpn_c_open_tracker(string name, TrackerCallbackDelegate trackerCallbackF)
static bool vrpn_c_force_feedback_set_force(System.IntPtr device, float force_x, float force_y, float force_z)
System.IntPtr a
System.IntPtr b
static bool vrpn_c_poll_tracker(System.IntPtr device)
static bool vrpn_c_poll_button(System.IntPtr device)
static void vrpn_c_force_feedback_stop(System.IntPtr device)
static bool vrpn_c_close_tracker(System.IntPtr device)