public void updateCursor(TuioCursor cursor) { if (!activeEvents.ContainsKey(cursor.getSessionID())) { return; } mtCntrEvent anEvent = activeEvents[cursor.getSessionID()]; anEvent.eventState = mtEventState.Moved; if (cursor.getContour() != null) { List <TuioPoint> contr = cursor.getContour(); List <Vector3> cntrPoints = new List <Vector3>(); foreach (TuioPoint pnt in contr) { float xC = pnt.getX(); float yC = pnt.getY(); cntrPoints.Add(new Vector3(xC * cameraPixelWidth, 0, (1.0f - yC) * cameraPixelHeight)); } anEvent.contour = cntrPoints.ToArray(); //calibrate and CoM (center of mass) float xCoM = 0.0F; float yCoM = 0.0F; Matrix mat = Matrix.Translate(xTCalib, yTCalib, 0.0F); for (int i = 0; i < anEvent.contour.Length; i++) { anEvent.contour[i] = mat.TransformVector(anEvent.contour[i]); xCoM += anEvent.contour[i].x; yCoM += anEvent.contour[i].y; } xCoM /= anEvent.contour.Length; yCoM /= anEvent.contour.Length; //translate to 0 for (int i = 0; i < anEvent.contour.Length; i++) { anEvent.contour[i].x -= xCoM; anEvent.contour[i].y -= yCoM; } anEvent.lastScreenPosition = anEvent.screenPosition; anEvent.screenPosition = new Vector3(xCoM, 0, yCoM); } lock (eventQueueLock) eventQueue.Add(anEvent); didChange = true; }
public void updateCursor(TuioCursor cursor) { if (!activeEvents.ContainsKey(cursor.getSessionID())) { return; } mtCntrEvent anEvent = activeEvents[cursor.getSessionID()]; anEvent.eventState = mtEventState.Moved; if (cursor.getContour() != null) { List <TuioPoint> contr = cursor.getContour(); List <Vector3> cntrPoints = new List <Vector3>(); foreach (TuioPoint pnt in contr) { float xC = pnt.getX(); float yC = pnt.getY(); cntrPoints.Add(new Vector3(xC * cameraPixelWidth, (1.0f - yC) * cameraPixelHeight, 0)); } anEvent.contour = cntrPoints.ToArray(); //calibrate and CoM (center of mass) float xCoM = 0.0F; float yCoM = 0.0F; Matrix mat = Matrix.Translate(xTCalib, yTCalib, 0.0F); for (int i = 0; i < anEvent.contour.Length; i++) { anEvent.contour[i] = mat.TransformVector(anEvent.contour[i]); xCoM += anEvent.contour[i].x; yCoM += anEvent.contour[i].y; } xCoM /= anEvent.contour.Length; yCoM /= anEvent.contour.Length; //translate to 0 for (int i = 0; i < anEvent.contour.Length; i++) { anEvent.contour[i].x -= xCoM; anEvent.contour[i].y -= yCoM; } anEvent.lastScreenPosition = anEvent.screenPosition; anEvent.screenPosition = new Vector3(xCoM, 0, yCoM); /* * anEvent.lastTime = anEvent.currentTime; * anEvent.currentTime = Time.time; * float dt = anEvent.currentTime - anEvent.lastTime; //delta time * if(dt > 0) * { * float dx = anEvent.lastScreenPosition.x - anEvent.screenPosition.x; * float dy = anEvent.lastScreenPosition.z - anEvent.screenPosition.z; * float distance = (float)Mathf.Sqrt(dx*dx+dy*dy); * float lastMspeed = anEvent.mAccel; * anEvent.x_speed = dx / dt; // delta x / delta time = velocity x * anEvent.y_speed = dy / dt; // -||- * anEvent.mSpeed = distance / dt; * anEvent.mAccel = (anEvent.mSpeed - lastMspeed) / dt; * } */ } lock (eventQueueLock) eventQueue.Add(anEvent); didChange = true; }