// Creates an event from an XML-formatted description. xmlDescription is modified as part of the constructor. The // first VREvent described <VREvent>...</VREvent> is popped off the string and xmlDescription is set to whatever // remains in the string. public VREvent(ref string xmlDescription) { Dictionary<string, string> props = new Dictionary<string, string>(); string xmlDataIndex = string.Empty; string xmlRemaining = string.Empty; bool success = XMLUtils.GetXMLField(xmlDescription, "VREvent", ref props, ref xmlDataIndex, ref xmlRemaining); if (!success) { Debug.Log("Error decoding VREvent"); return; } _name = props["name"]; _dataIndex = new VRDataIndex(ref xmlDataIndex); xmlDescription = xmlRemaining; }
// Creates an event from an XML-formatted description. xmlDescription is modified as part of the constructor. The // first VREvent described <VREvent>...</VREvent> is popped off the string and xmlDescription is set to whatever // remains in the string. public VREvent(ref string xmlDescription) { Dictionary <string, string> props = new Dictionary <string, string>(); string xmlDataIndex = string.Empty; string xmlRemaining = string.Empty; bool success = XMLUtils.GetXMLField(xmlDescription, "VREvent", ref props, ref xmlDataIndex, ref xmlRemaining); if (!success) { Debug.Log("Error decoding VREvent"); return; } _name = props["name"]; _dataIndex = new VRDataIndex(ref xmlDataIndex); xmlDescription = xmlRemaining; }
// Generic constructor, creates an empty event public VREvent() { _name = string.Empty; _dataIndex = new VRDataIndex(); }
// Typical constructor public VREvent(string name, VRDataIndex dataIndex) { _name = name; _dataIndex = dataIndex; }
// AT THE START OF EACH FRAME: SYNCHRONIZE INPUT EVENTS AND CALL ONVREVENT CALLBACK FUNCTIONS void PreUpdate() { // TODO: Add input events generated in Unity to the list of inputEvents to sync them across all clients /* * int brushType = 1; * VRDataIndex myEventData = new VRDataIndex(); * myEventData.AddData("BrushType", brushType); * VRMain.AddInputEvent(new VREvent("BrushTypeChange", myEventData)); */ /* * foreach (var item in clientEvents) { * inputEvents.Add (item); * clientEvents.Clear (); * }*/ if (fakeTrackersForDebugging) { float x = Input.mousePosition.x; float y = Input.mousePosition.y; // first time through if (lastx == -9999) { lastx = x; lasty = y; return; } if (Input.GetKeyDown("1")) { curTracker = 0; } else if (Input.GetKeyDown("2")) { curTracker = 1; } if (Input.GetKey("x")) { float angle = 0.1f * (x - lastx); if (curTracker == 0) { tracker1Rot = Quaternion.AngleAxis(angle, new Vector3(1f, 0f, 0f)) * tracker1Rot; } else if (curTracker == 1) { tracker2Rot = Quaternion.AngleAxis(angle, new Vector3(1f, 0f, 0f)) * tracker2Rot; } } else if (Input.GetKey("y")) { float angle = 0.1f * (x - lastx); if (curTracker == 0) { tracker1Rot = Quaternion.AngleAxis(angle, new Vector3(0f, 1f, 0f)) * tracker1Rot; } else if (curTracker == 1) { tracker2Rot = Quaternion.AngleAxis(angle, new Vector3(0f, 1f, 0f)) * tracker2Rot; } } else if (Input.GetKey("z")) { float angle = 0.1f * (x - lastx); if (curTracker == 0) { tracker1Rot = Quaternion.AngleAxis(angle, new Vector3(0f, 0f, 1f)) * tracker1Rot; } else if (curTracker == 1) { tracker2Rot = Quaternion.AngleAxis(angle, new Vector3(0f, 0f, 1f)) * tracker2Rot; } } else if (Input.GetKey("left shift")) { float depth = 0.005f * (y - lasty); if (curTracker == 0) { tracker1Pos += depth * Camera.main.transform.forward; } else if (curTracker == 1) { tracker2Pos += depth * Camera.main.transform.forward; } } else { Ray ray = Camera.main.ScreenPointToRay(new Vector3(x, y, 0f)); Plane p = new Plane(); float dist = 0.0f; if (curTracker == 0) { p.SetNormalAndPosition(-Camera.main.transform.forward, tracker1Pos); if (p.Raycast(ray, out dist)) { tracker1Pos = ray.GetPoint(dist); } } else if (curTracker == 1) { p.SetNormalAndPosition(-Camera.main.transform.forward, tracker2Pos); if (p.Raycast(ray, out dist)) { tracker2Pos = ray.GetPoint(dist); } } } Matrix4x4 m1 = Matrix4x4.TRS(tracker1Pos, tracker1Rot, Vector3.one); double[] d1 = VRConvert.ToDoubleArray(m1); VRDataIndex data1 = new VRDataIndex(); data1.AddData("Transform", d1); inputEvents.Add(new VREvent(fakeTracker1Event, data1)); Matrix4x4 m2 = Matrix4x4.TRS(tracker2Pos, tracker2Rot, Vector3.one); double[] d2 = VRConvert.ToDoubleArray(m2); VRDataIndex data2 = new VRDataIndex(); data2.AddData("Transform", d2); inputEvents.Add(new VREvent(fakeTracker2Event, data2)); lastx = x; lasty = y; } if (fakeHeadTracking) { if (Input.GetKey("up")) { headTrackerPos += 0.1f * Camera.main.transform.forward; } else if (Input.GetKey("down")) { headTrackerPos -= 0.1f * Camera.main.transform.forward; } else if (Input.GetKey("left")) { headTrackerRot *= Quaternion.AngleAxis(-1.0f, new Vector3(0f, 1f, 0f)); } else if (Input.GetKey("right")) { headTrackerRot *= Quaternion.AngleAxis(1.0f, new Vector3(0f, 1f, 0f)); } Matrix4x4 m3 = Matrix4x4.TRS(headTrackerPos, headTrackerRot, Vector3.one); double[] d3 = VRConvert.ToDoubleArray(m3); VRDataIndex data3 = new VRDataIndex(); data3.AddData("Transform", d3); inputEvents.Add(new VREvent(fakeHeadTrackerEvent, data3)); } // ----- END FAKE TRACKER INPUT ----- // Synchronize with the server if (_netClient != null) { _netClient.SynchronizeInputEventsAcrossAllNodes(ref inputEvents); } // Call any event callback functions that have been registered with the VREventHandler for (int i = 0; i < inputEvents.Count; i++) { if (VREventHandler != null) { VREventHandler(inputEvents [i]); } } _state = NetState.PostRenderNext; }
// AT THE START OF EACH FRAME: SYNCHRONIZE INPUT EVENTS AND CALL ONVREVENT CALLBACK FUNCTIONS void PreUpdate() { List<VREvent> inputEvents = new List<VREvent> (); // TODO: Add input events generated in Unity to the list of inputEvents to sync them across all clients // ----- FAKE TRACKER INPUT FOR DEBUGGING IN DESKTOP MODE USING MOUSE INPUT ----- if (fakeTrackersForDebugging) { float x = Input.mousePosition.x; float y = Input.mousePosition.y; // first time through if (lastx == -9999) { lastx = x; lasty = y; return; } if (Input.GetKeyDown ("1")) { curTracker = 0; } else if (Input.GetKeyDown ("2")) { curTracker = 1; } if (Input.GetKey ("x")) { float angle = 0.1f * (x - lastx); if (curTracker == 0) { tracker1Rot = Quaternion.AngleAxis (angle, new Vector3 (1f, 0f, 0f)) * tracker1Rot; } else if (curTracker == 1) { tracker2Rot = Quaternion.AngleAxis (angle, new Vector3 (1f, 0f, 0f)) * tracker2Rot; } } else if (Input.GetKey ("y")) { float angle = 0.1f * (x - lastx); if (curTracker == 0) { tracker1Rot = Quaternion.AngleAxis (angle, new Vector3 (0f, 1f, 0f)) * tracker1Rot; } else if (curTracker == 1) { tracker2Rot = Quaternion.AngleAxis (angle, new Vector3 (0f, 1f, 0f)) * tracker2Rot; } } else if (Input.GetKey ("z")) { float angle = 0.1f * (x - lastx); if (curTracker == 0) { tracker1Rot = Quaternion.AngleAxis (angle, new Vector3 (0f, 0f, 1f)) * tracker1Rot; } else if (curTracker == 1) { tracker2Rot = Quaternion.AngleAxis (angle, new Vector3 (0f, 0f, 1f)) * tracker2Rot; } } else if (Input.GetKey ("left shift")) { float depth = 0.005f * (y - lasty); if (curTracker == 0) { tracker1Pos += depth * Camera.main.transform.forward; } else if (curTracker == 1) { tracker2Pos += depth * Camera.main.transform.forward; } } else { Ray ray = Camera.main.ScreenPointToRay (new Vector3 (x, y, 0f)); Plane p = new Plane (); float dist = 0.0f; if (curTracker == 0) { p.SetNormalAndPosition (-Camera.main.transform.forward, tracker1Pos); if (p.Raycast (ray, out dist)) { tracker1Pos = ray.GetPoint (dist); } } else if (curTracker == 1) { p.SetNormalAndPosition (-Camera.main.transform.forward, tracker2Pos); if (p.Raycast (ray, out dist)) { tracker2Pos = ray.GetPoint (dist); } } } Matrix4x4 m1 = Matrix4x4.TRS (tracker1Pos, tracker1Rot, Vector3.one); double[] d1 = VRConvert.ToDoubleArray (m1); VRDataIndex data1 = new VRDataIndex (); data1.AddData ("Transform", d1); inputEvents.Add (new VREvent (fakeTracker1Event, data1)); Matrix4x4 m2 = Matrix4x4.TRS (tracker2Pos, tracker2Rot, Vector3.one); double[] d2 = VRConvert.ToDoubleArray (m2); VRDataIndex data2 = new VRDataIndex (); data2.AddData ("Transform", d2); inputEvents.Add (new VREvent (fakeTracker2Event, data2)); lastx = x; lasty = y; } if (fakeHeadTracking) { if (Input.GetKey("up")) { headTrackerPos += 0.1f * Camera.main.transform.forward; } else if (Input.GetKey("down")) { headTrackerPos -= 0.1f * Camera.main.transform.forward; } else if (Input.GetKey("left")) { headTrackerRot *= Quaternion.AngleAxis (-1.0f, new Vector3 (0f, 1f, 0f)); } else if (Input.GetKey("right")) { headTrackerRot *= Quaternion.AngleAxis (1.0f, new Vector3 (0f, 1f, 0f)); } Matrix4x4 m3 = Matrix4x4.TRS (headTrackerPos, headTrackerRot, Vector3.one); double[] d3 = VRConvert.ToDoubleArray (m3); VRDataIndex data3 = new VRDataIndex (); data3.AddData ("Transform", d3); inputEvents.Add (new VREvent (fakeHeadTrackerEvent, data3)); } // ----- END FAKE TRACKER INPUT ----- // Synchronize with the server if (_netClient != null) { _netClient.SynchronizeInputEventsAcrossAllNodes(ref inputEvents); } // Call any event callback functions that have been registered with the VREventHandler for (int i=0; i<inputEvents.Count; i++) { if (VREventHandler != null) { VREventHandler(inputEvents[i]); } } _state = NetState.PostRenderNext; }