4 using System.Collections.Generic;
6 using System.Runtime.InteropServices;
69 List<VRPNToolInstance> tools =
new List<VRPNToolInstance>();
71 List<VRPNToolConnections> connections =
new List<VRPNToolConnections>();
75 int current_tool_index = 0;
81 GameObject go = tool.
go;
83 double[] managedArray =
new double[3];
84 double[] quaternionArray =
new double[4];
85 Marshal.Copy(pos, managedArray, 0, 3);
86 Marshal.Copy(quat, quaternionArray, 0, 4);
89 float clutchingFactor = 6f;
92 Vector3 scaledTrackerPositionVector =
new Vector3((
float)managedArray[0] * factor, (
float)managedArray[1] * factor, -(
float)managedArray[2] * factor);
98 tool.
go.transform.localPosition = scaledTrackerPositionVector;
99 tool.
go.transform.localRotation =
new Quaternion(-(
float)quaternionArray[0], -(
float)quaternionArray[1], (
float)quaternionArray[2], (
float)quaternionArray[3]);
108 tools[current_tool_index] = tool;
124 if (button == 0 && state == 1) {
128 Vector3 force = tool.
go.transform.position - tool.
closest_atom.
go.transform.position;
131 tools[current_tool_index] = tool;
134 if (button == 0 && state == 0) {
136 artemis.
send_forces(1,
new int[1] {0},
new float[3] {0f, 0f, 0f});
139 tools[current_tool_index] = tool;
145 if (button == 1 && state == 1) {
149 tools[current_tool_index] = tool;
154 if (button == 1 && state == 0) {
156 tools[current_tool_index] = tool;
162 Debug.Log(
"----------");
163 Debug.Log(report.tv_sec);
164 Debug.Log(report.tv_usec);
165 Debug.Log(report.num_channel);
166 Debug.Log(
"----------Tran");
167 Debug.Log(report.channel[0]);
168 Debug.Log(report.channel[1]);
169 Debug.Log(report.channel[2]);
170 Debug.Log(
"----------Rot");
171 Debug.Log(report.channel[3]);
172 Debug.Log(report.channel[4]);
173 Debug.Log(report.channel[5]);
177 MethodInfo minfo = typeof(
VRPNManager).GetMethod(
"interactorTrackerCallback");
180 MethodInfo minfo2 = typeof(
VRPNManager).GetMethod(
"interactorButtonCallback");
183 MethodInfo minfo3 = typeof(
VRPNManager).GetMethod(
"explorerAnalogCallback");
194 int count = connections.Count;
195 for (
int i = count-1; i >= 0 ; i--) {
204 int count = connections.Count;
206 for (
int i = 0; i < count; i++) {
207 current_tool_index = i;
224 Debug.Log(
"VRPN: Adding tool of type " + tool_type.ToString());
227 instance.
type = tool_type;
233 GameObject go = GameObject.Instantiate(Resources.Load(
"VRPN/VRPNPicker", typeof(GameObject)), Vector3.zero, Quaternion.identity) as GameObject;
235 GameObject workspaceGo = GameObject.Instantiate(Resources.Load(
"VRPN/VRPN Interactor Grid") as GameObject);
237 workspaceGo.transform.parent = Camera.main.transform;
238 workspaceGo.transform.localPosition = Vector3.zero;
239 workspaceGo.transform.localRotation = Quaternion.identity;
240 workspaceGo.transform.Translate(
new Vector3(0f, 0f, 30f));
242 go.transform.parent = workspaceGo.transform;
243 go.transform.localPosition = Vector3.zero;
244 go.transform.localRotation = Quaternion.identity;
250 GameObject selection_sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
251 selection_sphere.transform.localScale = Vector3.one * 2f;
253 Shader s = Shader.Find(
"Transparent/Diffuse");
254 selection_sphere.GetComponent<Renderer>().material.shader = s;
255 Color c = Color.yellow;
257 selection_sphere.GetComponent<Renderer>().material.color = c;
261 this.tools.Add(instance);
264 this.connections.Add(connections_instance);
266 Debug.Log(
"VRPN: Tool was added");
267 return this.tools.Count() - 1;
274 Debug.Log(
"VRPN: Attempting to remove tool number " + tool_instance_index);
281 c = connections[tool_instance_index];
283 catch (ArgumentOutOfRangeException) {
303 this.connections[tool_instance_index] = c;
309 GameObject workspaceGo;
312 go = this.tools[tool_instance_index].go;
313 workspaceGo = this.tools[tool_instance_index].workspaceGo;
314 sphereGo = this.tools[tool_instance_index].selection_sphere;
316 GameObject.Destroy(go);
317 GameObject.Destroy(workspaceGo);
318 GameObject.Destroy(sphereGo);
320 this.tools.RemoveAt(tool_instance_index);
321 this.connections.RemoveAt(tool_instance_index);
323 catch(ArgumentOutOfRangeException) {
327 Debug.Log(
"VRPN: Removed tool correctly.");
336 connections_instance = this.connections[tool_instance_index];
345 System.Threading.Thread.Sleep(50);
350 Debug.LogWarning(
"Button instance got closed due to a mistaking server address.");
359 this.connections[tool_instance_index] = connections_instance;
369 connections_instance = this.connections[tool_instance_index];
378 System.Threading.Thread.Sleep(50);
383 Debug.LogWarning(
"Tracker instance got closed due to a mistaking server address.");
392 connections_instance.
tracker = tracker_connection;
394 this.connections[tool_instance_index] = connections_instance;
404 connections_instance = this.connections[tool_instance_index];
413 System.Threading.Thread.Sleep(50);
418 Debug.LogWarning(
"Button instance got closed due to a mistaking server address.");
427 connections_instance.
buttons = button_connection;
429 this.connections[tool_instance_index] = connections_instance;
439 connections_instance = this.connections[tool_instance_index];
449 this.connections[tool_instance_index] = connections_instance;
461 connections_instance = this.connections[tool_instance_index];
469 this.connections[tool_instance_index] = connections_instance;
481 connections_instance = this.connections[tool_instance_index];
489 this.connections[tool_instance_index] = connections_instance;
bool DisconnectToolFromTracker(int tool_instance_index)
static bool vrpn_c_button_is_connected(System.IntPtr device)
bool ConnectToolToTracker(int tool_instance_index, string vrpn_device)
Vector3 last_workspace_position
static bool vrpn_c_force_feedback_doing_okay(System.IntPtr device)
Vector3 last_tracker_position
static bool vrpn_c_close_button(System.IntPtr device)
VRPNToolConnections(System.IntPtr force_feedback=new IntPtr(), System.IntPtr buttons=new IntPtr(), System.IntPtr tracker=new IntPtr())
static bool vrpn_c_tracker_is_connected(System.IntPtr device)
delegate void ButtonCallbackDelegate(Int32 button, Int32 state)
static bool vrpn_c_close_force_feedback(System.IntPtr device)
delegate void AnalogCallbackDelegate(VRPN.Wrapper.VRPNAnalogReport report)
VRPN.Wrapper.TrackerCallbackDelegate interactorTrackerDelegate
GameObject selection_sphere
bool ConnectToolToForceFeedback(int tool_instance_index, string vrpn_device)
bool RemoveTool(int tool_instance_index)
System.IntPtr force_feedback
static bool vrpn_c_tracker_doing_okay(System.IntPtr device)
static System.IntPtr vrpn_c_open_button(string name, ButtonCallbackDelegate buttonCallbackF)
SingleAtomSelection closest_atom
static System.IntPtr vrpn_c_open_force_feedback(string name)
VRPN.Wrapper.ButtonCallbackDelegate interactorButtonDelegate
bool DisconnectToolFromButtons(int tool_instance_index)
int InstantiateTool(VRPNToolType tool_type)
delegate void TrackerCallbackDelegate(uint sensor, System.IntPtr pos, System.IntPtr quat)
!WiP Includes FLAGS of GUI.
void interactorButtonCallback(Int32 button, Int32 state)
bool ConnectToolToButtons(int tool_instance_index, string vrpn_device)
VRPN.Wrapper.AnalogCallbackDelegate explorerAnalogDelegate
static ArtemisManager getArtemisManager()
static System.IntPtr vrpn_c_open_tracker(string name, TrackerCallbackDelegate trackerCallbackF)
SingleAtomSelection getClosestAtomGameObject(Vector3 position)
static bool vrpn_c_force_feedback_set_force(System.IntPtr device, float force_x, float force_y, float force_z)
bool DisconnectToolFromForceFeedback(int tool_instance_index)
void interactorTrackerCallback(uint sensor, System.IntPtr pos, System.IntPtr quat)
static bool vrpn_c_button_doing_okay(System.IntPtr device)
static bool vrpn_c_poll_tracker(System.IntPtr device)
static bool vrpn_c_poll_button(System.IntPtr device)
void send_forces(int nb_forces, int[] indices, float[] coordinates)
static GenericManager getCurrentAtomManager()
static void vrpn_c_force_feedback_stop(System.IntPtr device)
void explorerAnalogCallback(VRPN.Wrapper.VRPNAnalogReport report)
static bool vrpn_c_close_tracker(System.IntPtr device)