void Update() { if (this.m_TuioManager.IsConnected && this.m_TuioManager.IsMarkerAlive(this.MarkerID)) { TUIO.TuioObject marker = this.m_TuioManager.GetMarker(this.MarkerID); //update parameters this.m_ScreenPosition.x = marker.getX(); this.m_ScreenPosition.y = marker.getY(); this.m_Angle = marker.getAngle() * RotationMultiplier; this.m_AngleDegrees = marker.getAngleDegrees() * RotationMultiplier; this.m_Speed = marker.getMotionSpeed(); this.m_Acceleration = marker.getMotionAccel(); this.m_RotationSpeed = marker.getRotationSpeed() * RotationMultiplier; this.m_RotationAcceleration = marker.getRotationAccel(); this.m_Direction.x = marker.getXSpeed(); this.m_Direction.y = marker.getYSpeed(); this.m_IsVisible = true; if (this.fitGrid) { //fit position into the grid int colX = (int)(marker.getX() / this.gridSize); this.m_ScreenPosition.x = (float)(colX * this.gridSize); int colY = (int)(marker.getY() / this.gridSize); this.m_ScreenPosition.y = (float)(colY * this.gridSize); //fit rotation angle into a grid int step = (int)(marker.getAngleDegrees() / this.rotationGridSize); this.m_AngleDegrees = (float)(step * this.rotationGridSize); } //set game object to visible, if it was hidden before ShowGameObject(); //update transform component UpdateTransform(); } else { //automatically hide game object when marker is not visible if (this.AutoHideGO) { HideGameObject(); } this.m_IsVisible = false; } }
void Update() { if (this.m_TuioManager.IsMarkerAlive(this.MarkerID)) { } if (this.m_TuioManager.IsConnected && this.m_TuioManager.IsMarkerAlive(this.MarkerID)) { TUIO.TuioObject marker = this.m_TuioManager.GetMarker(this.MarkerID); //update parameters this.m_ScreenPosition.x = marker.getX(); this.m_ScreenPosition.y = marker.getY(); this.m_Angle = marker.getAngle() * RotationMultiplier; this.m_AngleDegrees = marker.getAngleDegrees() * RotationMultiplier; this.m_Speed = marker.getMotionSpeed(); this.m_Acceleration = marker.getMotionAccel(); this.m_RotationSpeed = marker.getRotationSpeed() * RotationMultiplier; this.m_RotationAcceleration = marker.getRotationAccel(); this.m_Direction.x = marker.getXSpeed(); this.m_Direction.y = marker.getYSpeed(); this.m_IsVisible = true; //set game object to visible, if it was hidden before ShowGameObject(); //update transform component UpdateTransform(); } else { //automatically hide game object when marker is not visible if (this.AutoHideGO) { HideGameObject(); } this.m_IsVisible = false; } }
void Update() { if (this.m_TuioManager.IsMarkerAlive(this.MarkerID)) { } if (this.m_TuioManager.IsConnected && this.m_TuioManager.IsMarkerAlive(this.MarkerID)) { TUIO.TuioObject marker = this.m_TuioManager.GetMarker(this.MarkerID); //update parameters this.m_Angle = marker.getAngle() * RotationMultiplier; this.m_AngleDegrees = marker.getAngleDegrees() * RotationMultiplier; this.m_Acceleration = marker.getMotionAccel(); this.m_RotationSpeed = marker.getRotationSpeed() * RotationMultiplier; this.m_RotationAcceleration = marker.getRotationAccel(); this.m_Direction.x = marker.getXSpeed(); this.m_Direction.y = marker.getYSpeed(); //update transform component if (rotate) { UpdateTransform(); } } else { this.m_IsVisible = false; } if (this.Manager.GetRightWayFound()) { this.rotate = false; //Lässt Gelenk nur drehen, solang der richtige Weg noch nicht gefunden wurde } }
/** * The OSC callback method where all TUIO messages are received and decoded * and where the TUIO event callbacks are dispatched * * @param message the received OSC message */ private void processMessage(OSCMessage message) { string address = message.Address; ArrayList args = message.Values; string command = (string)args[0]; if (address == "/tuio/2Dobj") { if (command == "set") { long s_id = (int)args[1]; int f_id = (int)args[2]; float xpos = (float)args[3]; float ypos = (float)args[4]; float angle = (float)args[5]; float xspeed = (float)args[6]; float yspeed = (float)args[7]; float rspeed = (float)args[8]; float maccel = (float)args[9]; float raccel = (float)args[10]; lock (objectSync) { if (!objectList.ContainsKey(s_id)) { TuioObject addObject = new TuioObject(s_id, f_id, xpos, ypos, angle); frameObjects.Add(addObject); } else { TuioObject tobj = objectList[s_id]; if (tobj == null) { return; } if ((tobj.getX() != xpos) || (tobj.getY() != ypos) || (tobj.getAngle() != angle) || (tobj.getXSpeed() != xspeed) || (tobj.getYSpeed() != yspeed) || (tobj.getRotationSpeed() != rspeed) || (tobj.getMotionAccel() != maccel) || (tobj.getRotationAccel() != raccel)) { TuioObject updateObject = new TuioObject(s_id, f_id, xpos, ypos, angle); updateObject.update(xpos, ypos, angle, xspeed, yspeed, rspeed, maccel, raccel); frameObjects.Add(updateObject); } } } } else if (command == "alive") { newObjectList.Clear(); for (int i = 1; i < args.Count; i++) { // get the message content long s_id = (int)args[i]; newObjectList.Add(s_id); // reduce the object list to the lost objects if (aliveObjectList.Contains(s_id)) { aliveObjectList.Remove(s_id); } } // remove the remaining objects lock (objectSync) { for (int i = 0; i < aliveObjectList.Count; i++) { long s_id = aliveObjectList[i]; TuioObject removeObject = objectList[s_id]; removeObject.remove(currentTime); frameObjects.Add(removeObject); } } } else if (command == "fseq") { int fseq = (int)args[1]; bool lateFrame = false; if (fseq > 0) { if (fseq > currentFrame) { currentTime = TuioTime.getSessionTime(); } if ((fseq >= currentFrame) || ((currentFrame - fseq) > 100)) { currentFrame = fseq; } else { lateFrame = true; } } else if ((TuioTime.getSessionTime().getTotalMilliseconds() - currentTime.getTotalMilliseconds()) > 100) { currentTime = TuioTime.getSessionTime(); } if (!lateFrame) { IEnumerator <TuioObject> frameEnum = frameObjects.GetEnumerator(); while (frameEnum.MoveNext()) { TuioObject tobj = frameEnum.Current; switch (tobj.getTuioState()) { case TuioObject.TUIO_REMOVED: TuioObject removeObject = tobj; removeObject.remove(currentTime); for (int i = 0; i < listenerList.Count; i++) { TuioListener listener = (TuioListener)listenerList[i]; if (listener != null) { listener.removeTuioObject(removeObject); } } lock (objectSync) { objectList.Remove(removeObject.getSessionID()); } break; case TuioObject.TUIO_ADDED: TuioObject addObject = new TuioObject(currentTime, tobj.getSessionID(), tobj.getSymbolID(), tobj.getX(), tobj.getY(), tobj.getAngle()); lock (objectSync) { objectList.Add(addObject.getSessionID(), addObject); } for (int i = 0; i < listenerList.Count; i++) { TuioListener listener = (TuioListener)listenerList[i]; if (listener != null) { listener.addTuioObject(addObject); } } break; default: TuioObject updateObject = getTuioObject(tobj.getSessionID()); if ((tobj.getX() != updateObject.getX() && tobj.getXSpeed() == 0) || (tobj.getY() != updateObject.getY() && tobj.getYSpeed() == 0)) { updateObject.update(currentTime, tobj.getX(), tobj.getY(), tobj.getAngle()); } else { updateObject.update(currentTime, tobj.getX(), tobj.getY(), tobj.getAngle(), tobj.getXSpeed(), tobj.getYSpeed(), tobj.getRotationSpeed(), tobj.getMotionAccel(), tobj.getRotationAccel()); } for (int i = 0; i < listenerList.Count; i++) { TuioListener listener = (TuioListener)listenerList[i]; if (listener != null) { listener.updateTuioObject(updateObject); } } break; } } for (int i = 0; i < listenerList.Count; i++) { TuioListener listener = (TuioListener)listenerList[i]; if (listener != null) { listener.refresh(new TuioTime(currentTime)); } } List <long> buffer = aliveObjectList; aliveObjectList = newObjectList; // recycling the List newObjectList = buffer; } frameObjects.Clear(); } } else if (address == "/tuio/2Dcur") { if (command == "set") { long s_id = (int)args[1]; float xpos = (float)args[2]; float ypos = (float)args[3]; float xspeed = (float)args[4]; float yspeed = (float)args[5]; float maccel = (float)args[6]; lock (cursorList) { if (!cursorList.ContainsKey(s_id)) { TuioCursor addCursor = new TuioCursor(s_id, -1, xpos, ypos); frameCursors.Add(addCursor); } else { TuioCursor tcur = (TuioCursor)cursorList[s_id]; if (tcur == null) { return; } if ((tcur.getX() != xpos) || (tcur.getY() != ypos) || (tcur.getXSpeed() != xspeed) || (tcur.getYSpeed() != yspeed) || (tcur.getMotionAccel() != maccel)) { TuioCursor updateCursor = new TuioCursor(s_id, tcur.getCursorID(), xpos, ypos); updateCursor.update(xpos, ypos, xspeed, yspeed, maccel); frameCursors.Add(updateCursor); } } } } else if (command == "alive") { newCursorList.Clear(); for (int i = 1; i < args.Count; i++) { // get the message content long s_id = (int)args[i]; newCursorList.Add(s_id); // reduce the cursor list to the lost cursors if (aliveCursorList.Contains(s_id)) { aliveCursorList.Remove(s_id); } } // remove the remaining cursors lock (cursorSync) { for (int i = 0; i < aliveCursorList.Count; i++) { long s_id = aliveCursorList[i]; if (!cursorList.ContainsKey(s_id)) { continue; } TuioCursor removeCursor = cursorList[s_id]; removeCursor.remove(currentTime); frameCursors.Add(removeCursor); } } } else if (command == "fseq") { int fseq = (int)args[1]; bool lateFrame = false; if (fseq > 0) { if (fseq > currentFrame) { currentTime = TuioTime.getSessionTime(); } if ((fseq >= currentFrame) || ((currentFrame - fseq) > 100)) { currentFrame = fseq; } else { lateFrame = true; } } else if ((TuioTime.getSessionTime().getTotalMilliseconds() - currentTime.getTotalMilliseconds()) > 100) { currentTime = TuioTime.getSessionTime(); } if (!lateFrame) { IEnumerator <TuioCursor> frameEnum = frameCursors.GetEnumerator(); while (frameEnum.MoveNext()) { TuioCursor tcur = frameEnum.Current; switch (tcur.getTuioState()) { case TuioCursor.TUIO_REMOVED: TuioCursor removeCursor = tcur; removeCursor.remove(currentTime); for (int i = 0; i < listenerList.Count; i++) { TuioListener listener = (TuioListener)listenerList[i]; if (listener != null) { listener.removeTuioCursor(removeCursor); } } lock (cursorSync) { cursorList.Remove(removeCursor.getSessionID()); if (removeCursor.getCursorID() == maxCursorID) { maxCursorID = -1; if (cursorList.Count > 0) { IEnumerator <KeyValuePair <long, TuioCursor> > clist = cursorList.GetEnumerator(); while (clist.MoveNext()) { int f_id = clist.Current.Value.getCursorID(); if (f_id > maxCursorID) { maxCursorID = f_id; } } List <TuioCursor> freeCursorBuffer = new List <TuioCursor>(); IEnumerator <TuioCursor> flist = freeCursorList.GetEnumerator(); while (flist.MoveNext()) { TuioCursor testCursor = flist.Current; if (testCursor.getCursorID() < maxCursorID) { freeCursorBuffer.Add(testCursor); } } freeCursorList = freeCursorBuffer; } else { freeCursorList.Clear(); } } else if (removeCursor.getCursorID() < maxCursorID) { freeCursorList.Add(removeCursor); } } break; case TuioCursor.TUIO_ADDED: TuioCursor addCursor; lock (cursorSync) { int c_id = cursorList.Count; if ((cursorList.Count <= maxCursorID) && (freeCursorList.Count > 0)) { TuioCursor closestCursor = freeCursorList[0]; IEnumerator <TuioCursor> testList = freeCursorList.GetEnumerator(); while (testList.MoveNext()) { TuioCursor testCursor = testList.Current; if (testCursor.getDistance(tcur) < closestCursor.getDistance(tcur)) { closestCursor = testCursor; } } c_id = closestCursor.getCursorID(); freeCursorList.Remove(closestCursor); } else { maxCursorID = c_id; } addCursor = new TuioCursor(currentTime, tcur.getSessionID(), c_id, tcur.getX(), tcur.getY()); cursorList.Add(addCursor.getSessionID(), addCursor); } for (int i = 0; i < listenerList.Count; i++) { TuioListener listener = (TuioListener)listenerList[i]; if (listener != null) { listener.addTuioCursor(addCursor); } } break; default: TuioCursor updateCursor = getTuioCursor(tcur.getSessionID()); if ((tcur.getX() != updateCursor.getX() && tcur.getXSpeed() == 0) || (tcur.getY() != updateCursor.getY() && tcur.getYSpeed() == 0)) { updateCursor.update(currentTime, tcur.getX(), tcur.getY()); } else { updateCursor.update(currentTime, tcur.getX(), tcur.getY(), tcur.getXSpeed(), tcur.getYSpeed(), tcur.getMotionAccel()); } for (int i = 0; i < listenerList.Count; i++) { TuioListener listener = (TuioListener)listenerList[i]; if (listener != null) { listener.updateTuioCursor(updateCursor); } } break; } } for (int i = 0; i < listenerList.Count; i++) { TuioListener listener = (TuioListener)listenerList[i]; if (listener != null) { listener.refresh(new TuioTime(currentTime)); } } List <long> buffer = aliveCursorList; aliveCursorList = newCursorList; // recycling the List newCursorList = buffer; } frameCursors.Clear(); } } }
void Update() { if (this.m_TuioManager.IsConnected && this.m_TuioManager.IsMarkerAlive(this.MarkerID)) { if (fighting == false) { TUIO.TuioObject marker = this.m_TuioManager.GetMarker(this.MarkerID); //update parameters this.m_ScreenPosition.x = marker.getX(); this.m_ScreenPosition.y = marker.getY(); this.m_Angle = marker.getAngle() * RotationMultiplier; this.m_AngleDegrees = marker.getAngleDegrees() * RotationMultiplier; this.m_Speed = marker.getMotionSpeed(); this.m_Acceleration = marker.getMotionAccel(); this.m_RotationSpeed = marker.getRotationSpeed() * RotationMultiplier; this.m_RotationAcceleration = marker.getRotationAccel(); this.m_Direction.x = marker.getXSpeed(); this.m_Direction.y = marker.getYSpeed(); this.m_IsVisible = true; //set game object to visible, if it was hidden before ShowGameObject(); //update transform component UpdateTransform(); } } else { //automatically hide game object when marker is not visible if (this.AutoHideGO) { HideGameObject(); } else { if (fighting == false) { //activate markers transform.GetChild(0).gameObject.SetActive(true); //keyboard commands to test if (MarkerID == 0) { Vector3 t = transform.position; if (Input.GetKey(KeyCode.UpArrow)) { Vector3 forward = Vector3.forward * 0.5f; t += forward; } if (Input.GetKey(KeyCode.DownArrow)) { Vector3 backward = Vector3.forward * -0.5f; t += backward; } if (Input.GetKey(KeyCode.RightArrow)) { Vector3 right = Vector3.right * 0.5f; t += right; } if (Input.GetKey(KeyCode.LeftArrow)) { Vector3 left = Vector3.right * -0.5f; t += left; } if (t.x >= 96.0f || t.x <= 4.0f) { t.x = transform.position.x; } if (t.z >= 96.0f || t.z <= 4.0f) { t.z = transform.position.z; } if (t != transform.position) { transform.position = t; } } if (MarkerID == 1) { if (Input.GetKey(KeyCode.Keypad8)) { transform.position += Vector3.forward * 0.5f; } if (Input.GetKey(KeyCode.Keypad2)) { transform.position += Vector3.forward * -0.5f; } if (Input.GetKey(KeyCode.Keypad6)) { transform.position += Vector3.right * 0.5f; } if (Input.GetKey(KeyCode.Keypad4)) { transform.position += Vector3.right * -0.5f; } } if (MarkerID == 2) { Vector3 t = transform.position; if (Input.GetKey(KeyCode.W)) { Vector3 forward = Vector3.forward * 0.5f; t += forward; } if (Input.GetKey(KeyCode.S)) { Vector3 backward = Vector3.forward * -0.5f; t += backward; } if (Input.GetKey(KeyCode.D)) { Vector3 right = Vector3.right * 0.5f; t += right; } if (Input.GetKey(KeyCode.A)) { Vector3 left = Vector3.right * -0.5f; t += left; } if (t.x >= 96.0f || t.x <= 4.0f) { t.x = transform.position.x; } if (t.z >= 96.0f || t.z <= 4.0f) { t.z = transform.position.z; } if (t != transform.position) { transform.position = t; } } if (MarkerID == 3) { if (Input.GetKey(KeyCode.I)) { transform.position += Vector3.forward * 0.5f; } if (Input.GetKey(KeyCode.K)) { transform.position += Vector3.forward * -0.5f; } if (Input.GetKey(KeyCode.L)) { transform.position += Vector3.right * 0.5f; } if (Input.GetKey(KeyCode.J)) { transform.position += Vector3.right * -0.5f; } } } } this.m_IsVisible = false; } }
void Update() { if (this.m_TuioManager.IsMarkerAlive(this.MarkerID)) { //Debug.Log("FidcialController Zeile 110:this.m_TuioManager.IsMarkerAlive(this.MarkerID)"); } if (this.m_TuioManager.IsConnected && this.m_TuioManager.IsMarkerAlive(this.MarkerID)) { TUIO.TuioObject marker = this.m_TuioManager.GetMarker(this.MarkerID); //update parameters this.m_ScreenPosition.x = marker.getX(); this.m_ScreenPosition.y = marker.getY(); this.m_Angle = marker.getAngle() * RotationMultiplier; this.m_AngleDegrees = marker.getAngleDegrees() * RotationMultiplier; this.m_Speed = marker.getMotionSpeed(); this.m_Acceleration = marker.getMotionAccel(); this.m_RotationSpeed = marker.getRotationSpeed() * RotationMultiplier; this.m_RotationAcceleration = marker.getRotationAccel(); this.m_Direction.x = marker.getXSpeed(); this.m_Direction.y = marker.getYSpeed(); this.m_IsVisible = true; //set game object to visible, if it was hidden before ShowGameObject(); //update transform component UpdateTransform(); //Hier werden die Rüben gesucht, die auf der Seite der jeweiligen Person sind und ihre Kreise eingefärbt if (Time.time - Fiducial_Counter.time > 2) { //Hier wird der Index gesetzt, damit man weiß, welche "kleinen" Rüben und Kreise zu welcher Rübe gehören if (this.name.IndexOf("Ruebe" + Fiducial_Counter.count) > -1) { /*Die Rüben in der Mitte werden von 1 - 4 gezählt und * die unteren Rüben werden ebenfalls von 1-4 nummeriert, * jedoch nach dem "_" werden sie pro Seite mit gleich nummeriert. * Auf der Seite der Marker ID 0 ist bspw. die Ruebe1_1 * Hier soll die jeweilige Rübe in Kleinformat gefunden werden */ if (this.name.Equals("Ruebe" + Fiducial_Counter.count + "_" + (this.MarkerID + 1))) { //Dadurch findet man den Jeweiligen kreis der Unterrübe und färbt diesen Grün GameObject circle = GameObject.Find(this.name.Replace("Ruebe", "Kreis")); SpriteRenderer renderer = circle.GetComponents <SpriteRenderer> () [0]; renderer.color = new Color(0.133f, 0.545f, 0.133f); /*Hier kommt die Methode handleMarkerMovement in Aktion, die unten im Code zu finden ist. * Über diese Methode wird der Füllstand und die Bewegungsrichtung der Fiducials festgelegt*/ float diff = this.handleMarkerMovement(); /*Die Bewegungsachse wird in der Methode handleMarkerMovement festgelegt und * hier wird nochmal festgelegt ob sie in die + oder - Richtung * auf der jeweiligen Achse bewegt werden müssen. * Spricht MarkerID 0 muss in Richtung +y, MarkerID 1 -x, * MarkerID 2 -y und MarkerID 3 +x*/ diff *= MarkerID == 0 && MarkerID == 3 ? -1 : 1; if (diff > 0) { //Der maximale Füllstand wird dann in den jeweiligen Loadscreen-Skripten kontrolliert ScreenArray [MarkerID] += diff; } } } else { //Ist die Rübe nicht dran, so bleibt der Kreis braun GameObject circle = GameObject.Find(this.name.Replace("Ruebe", "Kreis")); SpriteRenderer renderer = circle.GetComponents <SpriteRenderer> () [0]; renderer.color = new Color(0.35f, 0.19f, 0.1f); } } else { //automatically hide game object when marker is not visible if (this.AutoHideGO) { HideGameObject(); } //Wird das Fiducial nicht erkannt, so bleibt die Rübe auch braun recognized = false; GameObject circle = GameObject.Find(this.name.Replace("Ruebe", "Kreis")); SpriteRenderer renderer = circle.GetComponents <SpriteRenderer> () [0]; renderer.color = new Color(0.35f, 0.19f, 0.1f); this.m_IsVisible = false; } } else { //automatically hide game object when marker is not visible if (this.AutoHideGO) { HideGameObject(); } recognized = false; GameObject circle = GameObject.Find(this.name.Replace("Ruebe", "Kreis")); SpriteRenderer renderer = circle.GetComponents <SpriteRenderer> () [0]; renderer.color = new Color(0.35f, 0.19f, 0.1f); this.m_IsVisible = false; } }
/** * The OSC callback method where all TUIO messages are received and decoded * and where the TUIO event callbacks are dispatched * * @param message the received OSC message */ private void processMessage(OSCMessage message) { string address = message.Address; ArrayList args = message.Values; string command = (string)args[0]; if (address == "/tuio/2Dobj") { if (command == "set") { if (currentTime.getTotalMilliseconds() == 0) { currentTime = TuioTime.getSessionTime(); } long s_id = (int)args[1]; int f_id = (int)args[2]; float x = (float)args[3]; float y = (float)args[4]; float a = (float)args[5]; float X = (float)args[6]; float Y = (float)args[7]; float A = (float)args[8]; float m = (float)args[9]; float r = (float)args[10]; if (!objectList.ContainsKey(s_id)) { TuioObject addObject = new TuioObject(currentTime, s_id, f_id, x, y, a); objectList.Add(s_id, addObject); for (int i = 0; i < listenerList.Count; i++) { TuioListener listener = (TuioListener)listenerList[i]; if (listener != null) { listener.addTuioObject(addObject); } } } else { TuioObject updateObject = objectList[s_id]; if ((updateObject.getX() != x) || (updateObject.getY() != y) || (updateObject.getAngle() != a)) { TuioObject tobj = new TuioObject(currentTime, s_id, updateObject.getSymbolID(), x, y, a); tobj.update(currentTime, x, y, a, X, Y, A, m, r); frameObjects.Add(tobj); /*updateObject.update(currentTime,x,y,a,X,Y,A,m,r); * for (int i=0;i<listenerList.Count;i++) { * TuioListener listener = (TuioListener)listenerList[i]; * if (listener!=null) listener.updateTuioObject(updateObject); * }*/ //objectList[s_id] = tobj; } } } else if (command == "alive") { for (int i = 1; i < args.Count; i++) { // get the message content long s_id = (int)args[i]; newObjectList.Add(s_id); // reduce the object list to the lost objects if (aliveObjectList.Contains(s_id)) { aliveObjectList.Remove(s_id); } } // remove the remaining objects for (int i = 0; i < aliveObjectList.Count; i++) { long s_id = aliveObjectList[i]; TuioObject removeObject = objectList[s_id]; removeObject.remove(currentTime); objectList.Remove(s_id); for (int j = 0; j < listenerList.Count; j++) { TuioListener listener = (TuioListener)listenerList[j]; if (listener != null) { listener.removeTuioObject(removeObject); } } } List <long> buffer = aliveObjectList; aliveObjectList = newObjectList; // recycling of the List newObjectList = buffer; newObjectList.Clear(); } else if (command == "fseq") { int fseq = (int)args[1]; bool lateFrame = false; if (fseq > 0) { if ((fseq >= currentFrame) || ((currentFrame - fseq) > 100)) { currentFrame = fseq; } else { lateFrame = true; } } if (!lateFrame) { IEnumerator <TuioObject> frameEnum = frameObjects.GetEnumerator(); while (frameEnum.MoveNext()) { TuioObject tobj = frameEnum.Current; TuioObject updateObject = getTuioObject(tobj.getSessionID()); updateObject.update(currentTime, tobj.getX(), tobj.getY(), tobj.getAngle(), tobj.getXSpeed(), tobj.getYSpeed(), tobj.getRotationSpeed(), tobj.getMotionAccel(), tobj.getRotationAccel()); for (int i = 0; i < listenerList.Count; i++) { TuioListener listener = (TuioListener)listenerList[i]; if (listener != null) { listener.updateTuioObject(updateObject); } } } for (int i = 0; i < listenerList.Count; i++) { TuioListener listener = (TuioListener)listenerList[i]; if (listener != null) { listener.refresh(currentTime); } } if (fseq > 0) { currentTime.reset(); } } frameObjects.Clear(); } } else if (address == "/tuio/2Dcur") { if (command == "set") { if (currentTime.getTotalMilliseconds() == 0) { currentTime = TuioTime.getSessionTime(); } long s_id = (int)args[1]; float x = (float)args[2]; float y = (float)args[3]; float X = (float)args[4]; float Y = (float)args[5]; float m = (float)args[6]; if (!cursorList.ContainsKey(s_id)) { int f_id = cursorList.Count; if (cursorList.Count <= maxFingerID) { TuioCursor closestCursor = freeCursorList[0]; IEnumerator <TuioCursor> testList = freeCursorList.GetEnumerator(); while (testList.MoveNext()) { TuioCursor testCursor = testList.Current; if (testCursor.getDistance(x, y) < closestCursor.getDistance(x, y)) { closestCursor = testCursor; } } f_id = closestCursor.getCursorID(); freeCursorList.Remove(closestCursor); } else { maxFingerID = f_id; } TuioCursor addCursor = new TuioCursor(currentTime, s_id, f_id, x, y); cursorList.Add(s_id, addCursor); for (int i = 0; i < listenerList.Count; i++) { TuioListener listener = (TuioListener)listenerList[i]; if (listener != null) { listener.addTuioCursor(addCursor); } } } else { TuioCursor updateCursor = (TuioCursor)cursorList[s_id]; if ((updateCursor.getX() != x) || (updateCursor.getY() != y)) { TuioCursor tcur = new TuioCursor(currentTime, s_id, updateCursor.getCursorID(), x, y); tcur.update(currentTime, x, y, X, Y, m); frameCursors.Add(tcur); /*updateCursor.update(currentTime,x,y,X,Y,m); * for (int i=0;i<listenerList.Count;i++) { * TuioListener listener = (TuioListener)listenerList[i]; * if (listener!=null) listener.updateTuioCursor(updateCursor); * }*/ //cursorList[s_id] = tcur; } } } else if (command == "alive") { for (int i = 1; i < args.Count; i++) { // get the message content long s_id = (int)args[i]; newCursorList.Add(s_id); // reduce the cursor list to the lost cursors if (aliveCursorList.Contains(s_id)) { aliveCursorList.Remove(s_id); } } // remove the remaining cursors for (int i = 0; i < aliveCursorList.Count; i++) { long s_id = aliveCursorList[i]; if (!cursorList.ContainsKey(s_id)) { continue; } TuioCursor removeCursor = cursorList[s_id]; int c_id = removeCursor.getCursorID(); cursorList.Remove(s_id); removeCursor.remove(currentTime); if (c_id == maxFingerID) { maxFingerID = -1; if (cursorList.Count > 0) { IEnumerator <KeyValuePair <long, TuioCursor> > clist = cursorList.GetEnumerator(); while (clist.MoveNext()) { int f_id = clist.Current.Value.getCursorID(); if (f_id > maxFingerID) { maxFingerID = f_id; } } List <TuioCursor> freeCursorBuffer = new List <TuioCursor>(); IEnumerator <TuioCursor> flist = freeCursorList.GetEnumerator(); while (flist.MoveNext()) { TuioCursor testCursor = flist.Current; if (testCursor.getCursorID() < maxFingerID) { freeCursorBuffer.Add(testCursor); } } freeCursorList = freeCursorBuffer; } } else if (c_id < maxFingerID) { freeCursorList.Add(removeCursor); } for (int j = 0; j < listenerList.Count; j++) { TuioListener listener = (TuioListener)listenerList[j]; if (listener != null) { listener.removeTuioCursor(removeCursor); } } } List <long> buffer = aliveCursorList; aliveCursorList = newCursorList; // recycling of the List newCursorList = buffer; newCursorList.Clear(); } else if (command == "fseq") { int fseq = (int)args[1]; bool lateFrame = false; if (fseq > 0) { if ((fseq >= currentFrame) || ((currentFrame - fseq) > 100)) { currentFrame = fseq; } else { lateFrame = true; } } if (!lateFrame) { IEnumerator <TuioCursor> frameEnum = frameCursors.GetEnumerator(); while (frameEnum.MoveNext()) { TuioCursor tcur = frameEnum.Current; TuioCursor updateCursor = getTuioCursor(tcur.getSessionID()); updateCursor.update(currentTime, tcur.getX(), tcur.getY(), tcur.getXSpeed(), tcur.getYSpeed(), tcur.getMotionAccel()); for (int i = 0; i < listenerList.Count; i++) { TuioListener listener = (TuioListener)listenerList[i]; if (listener != null) { listener.updateTuioCursor(updateCursor); } } } for (int i = 0; i < listenerList.Count; i++) { TuioListener listener = (TuioListener)listenerList[i]; if (listener != null) { listener.refresh(currentTime); } } if (fseq > 0) { currentTime.reset(); } } frameCursors.Clear(); } } }
/** * The OSC callback method where all TUIO messages are received and decoded * and where the TUIO event callbacks are dispatched * * @param message the received OSC message */ private void processMessage(OSCMessage message) { string address = message.Address; ArrayList args = message.Values; string command = (string)args[0]; if (address == "/tuio/2Dobj") { if (command == "set") { long s_id = (int)args[1]; int f_id = (int)args[2]; float xpos = (float)args[3]; float ypos = (float)args[4]; float angle = (float)args[5]; float xspeed = (float)args[6]; float yspeed = (float)args[7]; float rspeed = (float)args[8]; float maccel = (float)args[9]; float raccel = (float)args[10]; lock (objectSync) { if (!objectList.ContainsKey(s_id)) { TuioObject addObject = new TuioObject(s_id, f_id, xpos, ypos, angle); frameObjects.Add(addObject); } else { TuioObject tobj = objectList[s_id]; if (tobj == null) { return; } if ((tobj.getX() != xpos) || (tobj.getY() != ypos) || (tobj.getAngle() != angle) || (tobj.getXSpeed() != xspeed) || (tobj.getYSpeed() != yspeed) || (tobj.getRotationSpeed() != rspeed) || (tobj.getMotionAccel() != maccel) || (tobj.getRotationAccel() != raccel)) { TuioObject updateObject = new TuioObject(s_id, f_id, xpos, ypos, angle); updateObject.update(xpos, ypos, angle, xspeed, yspeed, rspeed, maccel, raccel); frameObjects.Add(updateObject); } } } } else if (command == "alive") { newObjectList.Clear(); for (int i = 1; i < args.Count; i++) { // get the message content long s_id = (int)args[i]; newObjectList.Add(s_id); // reduce the object list to the lost objects if (aliveObjectList.Contains(s_id)) { aliveObjectList.Remove(s_id); } } // remove the remaining objects lock (objectSync) { for (int i = 0; i < aliveObjectList.Count; i++) { long s_id = aliveObjectList[i]; TuioObject removeObject = objectList[s_id]; removeObject.remove(currentTime); frameObjects.Add(removeObject); } } } else if (command == "fseq") { int fseq = (int)args[1]; bool lateFrame = false; if (fseq > 0) { if (fseq > currentFrame) { currentTime = TuioTime.getSessionTime(); } if ((fseq >= currentFrame) || ((currentFrame - fseq) > 100)) { currentFrame = fseq; } else { lateFrame = true; } } else if ((TuioTime.getSessionTime().getTotalMilliseconds() - currentTime.getTotalMilliseconds()) > 100) { currentTime = TuioTime.getSessionTime(); } if (!lateFrame) { IEnumerator <TuioObject> frameEnum = frameObjects.GetEnumerator(); while (frameEnum.MoveNext()) { TuioObject tobj = frameEnum.Current; switch (tobj.getTuioState()) { case TuioObject.TUIO_REMOVED: TuioObject removeObject = tobj; removeObject.remove(currentTime); for (int i = 0; i < listenerList.Count; i++) { TuioListener listener = (TuioListener)listenerList[i]; if (listener != null) { listener.removeTuioObject(removeObject); } } lock (objectSync) { objectList.Remove(removeObject.getSessionID()); } break; case TuioObject.TUIO_ADDED: TuioObject addObject = new TuioObject(currentTime, tobj.getSessionID(), tobj.getSymbolID(), tobj.getX(), tobj.getY(), tobj.getAngle()); lock (objectSync) { objectList.Add(addObject.getSessionID(), addObject); } for (int i = 0; i < listenerList.Count; i++) { TuioListener listener = (TuioListener)listenerList[i]; if (listener != null) { listener.addTuioObject(addObject); } } break; default: TuioObject updateObject = getTuioObject(tobj.getSessionID()); if ((tobj.getX() != updateObject.getX() && tobj.getXSpeed() == 0) || (tobj.getY() != updateObject.getY() && tobj.getYSpeed() == 0)) { updateObject.update(currentTime, tobj.getX(), tobj.getY(), tobj.getAngle()); } else { updateObject.update(currentTime, tobj.getX(), tobj.getY(), tobj.getAngle(), tobj.getXSpeed(), tobj.getYSpeed(), tobj.getRotationSpeed(), tobj.getMotionAccel(), tobj.getRotationAccel()); } for (int i = 0; i < listenerList.Count; i++) { TuioListener listener = (TuioListener)listenerList[i]; if (listener != null) { listener.updateTuioObject(updateObject); } } break; } } for (int i = 0; i < listenerList.Count; i++) { TuioListener listener = (TuioListener)listenerList[i]; if (listener != null) { listener.refresh(new TuioTime(currentTime)); } } List <long> buffer = aliveObjectList; aliveObjectList = newObjectList; // recycling the List newObjectList = buffer; } frameObjects.Clear(); } } else if (address == "/tuio/2Dcur" || address == "/tuio/2Dcur source ccv@localhost") { if (command == "set") { long s_id = (int)args[1]; float xpos = (float)args[2]; float ypos = (float)args[3]; float xspeed = (float)args[4]; float yspeed = (float)args[5]; float maccel = (float)args[6]; //~ Debug.Log("Cursor - id: " + s_id); lock (cursorList) { if (!cursorList.ContainsKey(s_id)) { TuioCursor addCursor = new TuioCursor(s_id, -1, xpos, ypos); frameCursors.Add(addCursor); } else { TuioCursor tcur = (TuioCursor)cursorList[s_id]; if (tcur == null) { return; } if ((tcur.getX() != xpos) || (tcur.getY() != ypos) || (tcur.getXSpeed() != xspeed) || (tcur.getYSpeed() != yspeed) || (tcur.getMotionAccel() != maccel)) { TuioCursor updateCursor = new TuioCursor(s_id, tcur.getCursorID(), xpos, ypos); updateCursor.update(xpos, ypos, xspeed, yspeed, maccel); frameCursors.Add(updateCursor); } } } //experimental contour data (by Rasmus H. - www.schnitzel.dk) } else if (command == "contour") { long s_id = (int)args[1]; int m_length = (int)args[2]; //~ Debug.Log("Contour - id: " + s_id + " Lenght: " + m_length); if (m_length > 0) { lock (cursorList) { List <TuioPoint> contr = new List <TuioPoint>(); for (int i = 3; i + 2 <= m_length + 3; i += 2) { float xpos = (float)args[i]; float ypos = (float)args[i + 1]; contr.Add(new TuioPoint(xpos, ypos)); } if (!cursorList.ContainsKey(s_id)) { //no cursor with that id so we return return; } else { TuioCursor tcur = (TuioCursor)cursorList[s_id]; if (tcur == null) { return; } TuioCursor updateCursor = new TuioCursor(tcur); updateCursor.update(tcur, contr); frameCursors.Add(updateCursor); } } } //experimental height data (by Rasmus H. - www.schnitzel.dk) } else if (command == "height") { long s_id = (int)args[1]; float xpos = (float)args[2]; float ypos = (float)args[3]; int xwidth = (int)args[4]; int yheight = (int)args[5]; int hpoints = (int)args[6]; //Debug.Log("Contour - id: " + s_id + " x: " + xpos + " y: " + ypos + " width: " + xwidth + " height: " + yheight + " hpoints: " + hpoints ); lock (cursorList) { List <float> heightp = new List <float>(); for (int i = 7; i < hpoints + 7; i++) { heightp.Add((float)args[i]); } if (!cursorList.ContainsKey(s_id)) { //no cursor with that id so we return return; } else { TuioCursor tcur = (TuioCursor)cursorList[s_id]; if (tcur == null) { return; } TuioCursor updateCursor = new TuioCursor(tcur); updateCursor.update(tcur, xpos, ypos, xwidth, yheight, heightp); frameCursors.Add(updateCursor); } } } else if (command == "alive") { newCursorList.Clear(); for (int i = 1; i < args.Count; i++) { // get the message content long s_id = (int)args[i]; newCursorList.Add(s_id); // reduce the cursor list to the lost cursors if (aliveCursorList.Contains(s_id)) { aliveCursorList.Remove(s_id); } } // remove the remaining cursors lock (cursorSync) { for (int i = 0; i < aliveCursorList.Count; i++) { long s_id = aliveCursorList[i]; if (!cursorList.ContainsKey(s_id)) { continue; } TuioCursor removeCursor = cursorList[s_id]; removeCursor.remove(currentTime); frameCursors.Add(removeCursor); } } } else if (command == "fseq") { int fseq = (int)args[1]; bool lateFrame = false; if (fseq > 0) { if (fseq > currentFrame) { currentTime = TuioTime.getSessionTime(); } if ((fseq >= currentFrame) || ((currentFrame - fseq) > 100)) { currentFrame = fseq; } else { lateFrame = true; } } else if ((TuioTime.getSessionTime().getTotalMilliseconds() - currentTime.getTotalMilliseconds()) > 100) { currentTime = TuioTime.getSessionTime(); } if (!lateFrame) { IEnumerator <TuioCursor> frameEnum = frameCursors.GetEnumerator(); while (frameEnum.MoveNext()) { TuioCursor tcur = frameEnum.Current; switch (tcur.getTuioState()) { case TuioCursor.TUIO_REMOVED: TuioCursor removeCursor = tcur; removeCursor.remove(currentTime); for (int i = 0; i < listenerList.Count; i++) { TuioListener listener = (TuioListener)listenerList[i]; if (listener != null) { listener.removeTuioCursor(removeCursor); } } lock (cursorSync) { cursorList.Remove(removeCursor.getSessionID()); if (removeCursor.getCursorID() == maxCursorID) { maxCursorID = -1; if (cursorList.Count > 0) { IEnumerator <KeyValuePair <long, TuioCursor> > clist = cursorList.GetEnumerator(); while (clist.MoveNext()) { int f_id = clist.Current.Value.getCursorID(); if (f_id > maxCursorID) { maxCursorID = f_id; } } List <TuioCursor> freeCursorBuffer = new List <TuioCursor>(); IEnumerator <TuioCursor> flist = freeCursorList.GetEnumerator(); while (flist.MoveNext()) { TuioCursor testCursor = flist.Current; if (testCursor.getCursorID() < maxCursorID) { freeCursorBuffer.Add(testCursor); } } freeCursorList = freeCursorBuffer; } else { freeCursorList.Clear(); } } else if (removeCursor.getCursorID() < maxCursorID) { freeCursorList.Add(removeCursor); } } break; case TuioCursor.TUIO_ADDED: TuioCursor addCursor; lock (cursorSync) { int c_id = cursorList.Count; if ((cursorList.Count <= maxCursorID) && (freeCursorList.Count > 0)) { TuioCursor closestCursor = freeCursorList[0]; IEnumerator <TuioCursor> testList = freeCursorList.GetEnumerator(); while (testList.MoveNext()) { TuioCursor testCursor = testList.Current; if (testCursor.getDistance(tcur) < closestCursor.getDistance(tcur)) { closestCursor = testCursor; } } c_id = closestCursor.getCursorID(); freeCursorList.Remove(closestCursor); } else { maxCursorID = c_id; } addCursor = new TuioCursor(currentTime, tcur.getSessionID(), c_id, tcur.getX(), tcur.getY()); cursorList.Add(addCursor.getSessionID(), addCursor); } for (int i = 0; i < listenerList.Count; i++) { TuioListener listener = (TuioListener)listenerList[i]; if (listener != null) { listener.addTuioCursor(addCursor); } } break; default: TuioCursor updateCursor = getTuioCursor(tcur.getSessionID()); if ((tcur.getX() != updateCursor.getX() && tcur.getXSpeed() == 0) || (tcur.getY() != updateCursor.getY() && tcur.getYSpeed() == 0)) { updateCursor.update(currentTime, tcur.getX(), tcur.getY()); } else { updateCursor.update(currentTime, tcur.getX(), tcur.getY(), tcur.getXSpeed(), tcur.getYSpeed(), tcur.getMotionAccel()); } //rasmus edit if (tcur.getContour() != null) { updateCursor.update(updateCursor, tcur.getContour()); } if (tcur.getHeightPoints() != null) { updateCursor.update(updateCursor, tcur.getHXpos(), tcur.getHYpos(), tcur.getWidth(), tcur.getHeight(), tcur.getHeightPoints()); } for (int i = 0; i < listenerList.Count; i++) { TuioListener listener = (TuioListener)listenerList[i]; if (listener != null) { listener.updateTuioCursor(updateCursor); } } break; } } for (int i = 0; i < listenerList.Count; i++) { TuioListener listener = (TuioListener)listenerList[i]; if (listener != null) { listener.refresh(new TuioTime(currentTime)); } } List <long> buffer = aliveCursorList; aliveCursorList = newCursorList; // recycling the List newCursorList = buffer; } frameCursors.Clear(); } } }