private void updateEvent(BBTouchEvent anEvent, TuioCursor cursor) { anEvent.lastScreenPosition = anEvent.screenPosition; anEvent.tuioPosition = new Vector2(cursor.getX(), (1.0f - cursor.getY())); anEvent.screenPosition = new Vector3(cursor.getX() * cameraPixelWidth, (1.0f - cursor.getY()) * cameraPixelHeight, 0.3f); anEvent.lastTouchTime = anEvent.touchTime; anEvent.touchTime = Time.time; }
// Cursor down is for new touch events. we take the TUIO cursor object and convert it // into a touch event, and add it to our active list of events public virtual void cursorDown(TuioCursor cursor) { // first, make a new BBTouchEvent, tag it with the unique touch id BBTouchEvent newEvent = new BBTouchEvent(cursor.getSessionID()); // set the initial information newEvent.screenPosition = new Vector3(cursor.getX() * cameraPixelWidth, (1.0f - cursor.getY()) * cameraPixelHeight, 0.3f); newEvent.eventState = BBTouchEventState.Began; newEvent.didChange = true; // set all the rest of the info updateEvent(newEvent, cursor); // add it to our active event dictionary so we can retireve it based on it's unique ID // some times badness happens and we get an error adding one here for some reason // it should not ever be the case that the ID is already there. // if it is, then we need to behave if (activeEvents.ContainsKey(cursor.getSessionID())) { // then something is not right.. remove the old one and add a new one activeEvents.Remove(cursor.getSessionID()); } activeEvents.Add(cursor.getSessionID(), newEvent); // queue it up for processing lock (eventQueueLock) eventQueue.Add(newEvent); }
public void UpdateTuioCursor(TuioCursor tuioCursor) { _refreshTimer.Stop(); int pid = tuioCursor.getCursorID(); int i = _pointerTouchInfos.FindIndex(pti => pti.PointerInfo.PointerId == pid); if (i != -1) { int x = (int)((tuioCursor.getX() * (_screenRect.Width + _calibrationBuffer.Width)) + _calibrationBuffer.Left + _screenRect.Left); int y = (int)((tuioCursor.getY() * (_screenRect.Height + _calibrationBuffer.Height)) + _calibrationBuffer.Top + _screenRect.Top); PointerTouchInfo pointerTouchInfo = _pointerTouchInfos[i]; pointerTouchInfo.PointerInfo.PointerFlags = PointerFlags.UPDATE | PointerFlags.INRANGE | ((this.IsContactEnabled) ? PointerFlags.INCONTACT : PointerFlags.NONE); pointerTouchInfo.PointerInfo.PtPixelLocation = new PointerTouchPoint { X = x, Y = y }; pointerTouchInfo.ContactArea = new ContactArea { Left = x - CONTACT_AREA_RADIUS, Right = x + CONTACT_AREA_RADIUS, Top = y - CONTACT_AREA_RADIUS, Bottom = y + CONTACT_AREA_RADIUS }; _pointerTouchInfos[i] = pointerTouchInfo; Trace.WriteLine(string.Format("set cur {0} ({1}) {2} {3} {4} {5}", pid, tuioCursor.getSessionID(), x, y, tuioCursor.getMotionSpeed(), tuioCursor.getMotionAccel()), "TUIO"); } }
public void updateCursor(TuioCursor cursor) { if (!activeEvents.ContainsKey(cursor.getSessionID())) { return; } mtEvent anEvent = activeEvents[cursor.getSessionID()]; anEvent.lastScreenPosition = anEvent.screenPosition; anEvent.screenPosition = new Vector3(cursor.getX() * cameraPixelWidth, 0, (1.0f - cursor.getY()) * cameraPixelHeight); anEvent.tuioPosition = new Vector2(cursor.getX(), (1.0f - cursor.getY())); anEvent.eventState = mtEventState.Moved; lock (eventQueueLock) eventQueue.Add(anEvent); didChange = true; }
public void newCursor(TuioCursor cursor) { mtCntrEvent newEvent = new mtCntrEvent(cursor.getSessionID()); newEvent.tuioPosition = new Vector2(cursor.getX(), (1.0f - cursor.getY())); //switching y and z (y is up axis by default in unity) newEvent.screenPosition = new Vector3(cursor.getX() * cameraPixelWidth, 0, (1.0f - cursor.getY()) * cameraPixelHeight); newEvent.lastScreenPosition = newEvent.screenPosition; newEvent.eventState = mtEventState.Began; if (activeEvents.ContainsKey(cursor.getSessionID())) { //Already on list, remove old - add new activeEvents.Remove(cursor.getSessionID()); } activeEvents.Add(cursor.getSessionID(), newEvent); // queue it up for processing lock (eventQueueLock) eventQueue.Add(newEvent); didChange = true; }
public void newCursor(TuioCursor cursor) { ibheTuioEvent newEvent = new ibheTuioEvent(cursor.getSessionID()); newEvent.tuioPosition = new Vector2(cursor.getX(), (1.0f - cursor.getY())); //switching y and z (y is up axis by default in unity) newEvent.screenPosition = new Vector3(cursor.getX() * cameraPixelWidth, 0, (1.0f - cursor.getY()) * cameraPixelHeight); newEvent.lastScreenPosition = newEvent.screenPosition; newEvent.eventState = mtEventState.Began; newEvent.xPos = cursor.getHXpos() * cameraPixelWidth; newEvent.yPos = (1.0f - cursor.getHYpos()) * cameraPixelHeight; newEvent.width = cursor.getWidth(); newEvent.height = cursor.getHeight(); if (cursor.getHeightPoints() != null) { newEvent.heights = cursor.getHeightPoints().ToArray(); } float min = 250.0F; for (int i = 0; i < newEvent.heights.Length; i++) { if (((newEvent.heights[i] / 255.0F) * -4.0F) < min) { min = (newEvent.heights[i] / 255.0F) * -4.0F; } } newEvent.minHeight = min; if (activeEvents.ContainsKey(cursor.getSessionID())) { //Already on list, remove old - add new activeEvents.Remove(cursor.getSessionID()); } activeEvents.Add(cursor.getSessionID(), newEvent); // queue it up for processing lock (eventQueueLock) eventQueue.Add(newEvent); didChange = true; }
public void updateCursor(TuioCursor cursor) { if (!activeEvents.ContainsKey(cursor.getSessionID())) { return; } ibheTuioEvent anEvent = activeEvents[cursor.getSessionID()]; anEvent.lastScreenPosition = anEvent.screenPosition; anEvent.screenPosition = new Vector3(cursor.getX() * cameraPixelWidth, 0, (1.0f - cursor.getY()) * cameraPixelHeight); anEvent.tuioPosition = new Vector2(cursor.getX(), (1.0f - cursor.getY())); anEvent.eventState = mtEventState.Moved; anEvent.xPos = cursor.getHXpos() * cameraPixelWidth; anEvent.yPos = (1.0f - cursor.getHYpos()) * cameraPixelHeight; anEvent.width = cursor.getWidth(); anEvent.height = cursor.getHeight(); if (cursor.getHeightPoints() != null) { anEvent.heights = cursor.getHeightPoints().ToArray(); } float min = 250.0F; for (int i = 0; i < anEvent.heights.Length; i++) { if (((anEvent.heights[i] / 255.0F) * -4.0F) < min) { min = (anEvent.heights[i] / 255.0F) * -4.0F; } } anEvent.minHeight = min; //calibrate //Matrix mat = Matrix.Translate(xTCalib, yTCalib, 0.0F); //anEvent.xPos = mat.TransformVector( anEvent.xPos ); lock (eventQueueLock) eventQueue.Add(anEvent); didChange = true; }
public static void updateTuioCursor(TuioCursor c) { int id = c.getCursorID(); if (!deviceDictionary.Keys.Contains(id)) { addTuioCursor(c); } TUIOTouchDevice device = deviceDictionary[id]; if (device != null) { device.OriginalPosition = new Point(c.getX(), c.getY()); device.ReportMove(); } }
public void AddTuioCursor(TuioCursor tuioCursor) { _refreshTimer.Stop(); int pid = tuioCursor.getCursorID(); int i = _pointerTouchInfos.FindIndex(pti => pti.PointerInfo.PointerId == pid); if (i != -1) { _pointerTouchInfos.RemoveAt(i); } int x = (int)((tuioCursor.getX() * (_screenRect.Width + _calibrationBuffer.Width)) + _calibrationBuffer.Left + _screenRect.Left); int y = (int)((tuioCursor.getY() * (_screenRect.Height + _calibrationBuffer.Height)) + _calibrationBuffer.Top + _screenRect.Top); _pointerTouchInfos.Add ( new PointerTouchInfo() { TouchFlags = TouchFlags.NONE, Orientation = TOUCH_ORIENTATION, Pressure = TOUCH_PRESSURE, TouchMasks = TouchMask.CONTACTAREA | TouchMask.ORIENTATION | TouchMask.PRESSURE, PointerInfo = new PointerInfo { PointerInputType = PointerInputType.TOUCH, PointerFlags = PointerFlags.DOWN | PointerFlags.INRANGE | ((this.IsContactEnabled) ? PointerFlags.INCONTACT : PointerFlags.NONE), PtPixelLocation = new PointerTouchPoint { X = x, Y = y }, PointerId = (uint)pid }, ContactArea = new ContactArea { Left = x - CONTACT_AREA_RADIUS, Right = x + CONTACT_AREA_RADIUS, Top = y - CONTACT_AREA_RADIUS, Bottom = y + CONTACT_AREA_RADIUS } } ); Trace.WriteLine(string.Format("add cur {0} ({1}) {2} {3}", pid, tuioCursor.getSessionID(), x, y), "TUIO"); }
public static void addTuioCursor(TuioCursor c) { TUIOTouchDevice device = null; if (!deviceDictionary.Keys.Contains(c.getCursorID())) { device = new TUIOTouchDevice(c.getCursorID()); deviceDictionary.Add(c.getCursorID(), device); } if (device != null) { device.OriginalPosition = new Point(c.getX(), c.getY()); device.SetActiveSource(PresentationSource.FromVisual(_root)); device.Activate(); device.ReportDown(); } }
public void updateTuioCursor(TuioCursor tcur) { Console.WriteLine("set cur " + tcur.getCursorID() + " (" + tcur.getSessionID() + ") " + tcur.getX() + " " + tcur.getY() + " " + tcur.getMotionSpeed() + " " + tcur.getMotionAccel()); }
public void addTuioCursor(TuioCursor tcur) { lock (cursorSync) { cursorList.Add(tcur.getSessionID(), tcur); } Console.WriteLine("add cur " + tcur.getCursorID() + " (" + tcur.getSessionID() + ") " + tcur.getX() + " " + tcur.getY()); // VisualFeedback.InvalidateVisual(); }
private void TuioChannel_OnTuioRefresh(TuioTime t) { //TODO: re-enable frequent screen monitoring //if (frameCount % checkScreenEvery == 0) // ScanScreens(); //loop through the TuioObjects List <PointerTouchInfo> toFire = new List <PointerTouchInfo>(); if (channel.CursorList.Count > 0) { foreach (var kvp in channel.CursorList) { TuioCursor cur = kvp.Value.TuioCursor; IncomingType type = kvp.Value.Type; int[] injectionCoordinates = ToInjectionCoordinates(cur.getX(), cur.getY()); //make a new pointertouchinfo with all neccessary information PointerTouchInfo contact = new PointerTouchInfo(); contact.PointerInfo.pointerType = PointerInputType.TOUCH; contact.TouchFlags = TouchFlags.NONE; //contact.Orientation = (uint)cur.getAngleDegrees();//this is only valid for TuioObjects contact.Pressure = pressure; contact.TouchMasks = TouchMask.CONTACTAREA | TouchMask.ORIENTATION | TouchMask.PRESSURE; contact.PointerInfo.PtPixelLocation.X = injectionCoordinates[0]; contact.PointerInfo.PtPixelLocation.Y = injectionCoordinates[1]; contact.PointerInfo.PointerId = SessionIDToTouchID(cur.getSessionID()); contact.ContactArea.left = injectionCoordinates[0] - areaRadius; contact.ContactArea.right = injectionCoordinates[0] + areaRadius; contact.ContactArea.top = injectionCoordinates[1] - areaRadius; contact.ContactArea.bottom = injectionCoordinates[1] + areaRadius; //set the right flag if (type == IncomingType.New) { contact.PointerInfo.PointerFlags = PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT; } else if (type == IncomingType.Update) { contact.PointerInfo.PointerFlags = PointerFlags.UPDATE | PointerFlags.INRANGE | PointerFlags.INCONTACT; } else if (type == IncomingType.Remove) { contact.PointerInfo.PointerFlags = PointerFlags.UP; } //add it to 'toFire' toFire.Add(contact); } } //fire the events bool success = TouchInjector.InjectTouchInput(toFire.Count, toFire.ToArray()); //remove those with type == IncomingType.Remove List <long> removeList = new List <long>(); foreach (var kvp in channel.CursorList) { if (kvp.Value.Type == IncomingType.Remove) { removeList.Add(kvp.Key); } } foreach (long key in removeList) { channel.CursorList.Remove(key);//remove from the tuio channel } }