public Vector3 CalculateGridPosition(int markerID, float cameraOffset, bool isLoopBarMarker, bool isJoker, FiducialController fiducialController, Vector3 oldPositionInScreen) { //does not change position if the marker is currently being played if (!isLoopBarMarker && m_lastComeLastServe.IsBeingPlayed(markerID)) { return(fiducialController.gameObject.transform.position); } TuioObject m_obj = m_tuioManager.GetMarker(markerID); Vector3 position = new Vector3(m_obj.getX() * (Screen.width), isLoopBarMarker ? 0.5f * Screen.height : (1 - m_obj.getY()) * Screen.height, cameraOffset); //when the marker is snapped... if (fiducialController.IsSnapped()) { position.x = this.CalculateXPosition(position, isLoopBarMarker, m_settings.GetMarkerWidthMultiplier(markerID), false); // calculate x position while not moving //reads correctOldPos if marker is a JokerMarkers if (isJoker) { realOldPos = new Vector3(oldPositionInScreen.x, fiducialController.gameObject.GetComponent <JokerMarker>().GetRealOldYPosition(), oldPositionInScreen.z); } //...and the new position is NOT far away enough from the old position (different for Joker Markers), then set position to oldPosition if (isJoker ? !this.MovedFurtherThanThreshold(position, realOldPos, isJoker) : !this.MovedFurtherThanThreshold(position, oldPositionInScreen, isJoker)) { position = oldPositionInScreen; } //...and the new position is far away enoug from the old position, set snapped to false else if (this.MovedFurtherThanThreshold(position, oldPositionInScreen, isJoker)) { fiducialController.SetIsSnapped(false); } } //otherwise, if marker is NOT snapped... else if (!fiducialController.IsSnapped()) { //...and motion speed is zero, snap him to nearest grid position, set snapped to true and save the time of snapping (for lastcomelastserve algorithm) if (m_obj.getMotionSpeed() == 0) { #region X-Axis position.x = this.CalculateXPosition(position, isLoopBarMarker, m_settings.GetMarkerWidthMultiplier(markerID), false); // calculate x position while not moving #endregion #region Y-Axis //suggests the y Position because it's a joker marker if (isJoker) { position.y = fiducialController.gameObject.GetComponent <JokerMarker>().CalculateYPosition(position, fiducialController, this.GetTactPosition(Camera.main.ScreenToWorldPoint(position))); } else if (!isLoopBarMarker) { float snappingDistance = -cellHeightInPx / 2; //if marker is below grid area if (position.y < heightOffsetInPx_top + snappingDistance) { position.y = 0; } //if marker is above grid area else if (position.y > gridHeightInPx + heightOffsetInPx_bottom - snappingDistance) { position.y = gridHeightInPx + heightOffsetInPx_bottom - cellHeightInPx; } //if marker is on grid area else { float yPos = position.y - heightOffsetInPx_bottom - snappingDistance; float markerYOffset = yPos % cellHeightInPx; if (markerYOffset < cellHeightInPx / 2) { position.y = yPos - markerYOffset; } else { position.y = yPos - markerYOffset + cellHeightInPx; } } position.y += (heightOffsetInPx_bottom + snappingDistance); } #endregion //check if another tune is currently being played, if so: snap marker if (!m_lastComeLastServe.IsOtherMarkerBeingPlayedAtThisBeat(this.GetTactPosition(m_lastComeLastServe.markers[beats].transform.position))) { fiducialController.SetIsSnapped(true); fiducialController.SetLastTimeSnapped(Time.time); } } else { position.x = this.CalculateXPosition(position, isLoopBarMarker, m_settings.GetMarkerWidthMultiplier(markerID), true); // calculate x position while moving } } return(this.m_MainCamera.ScreenToWorldPoint(position)); }
public void updateTuioObject(TuioObject tobj) { Console.WriteLine("set obj " + tobj.getSymbolID() + " " + tobj.getSessionID() + " " + tobj.getX() + " " + tobj.getY() + " " + tobj.getAngle() + " " + tobj.getMotionSpeed() + " " + tobj.getRotationSpeed() + " " + tobj.getMotionAccel() + " " + tobj.getRotationAccel()); }
//here we go, thats the method called by vvvv each frame //all data handling should be in here public void Evaluate(int SpreadMax) { //if any of the inputs has changed //recompute the outputs if (FTUIOPacketInput.PinIsChanged) { string currentPacket; FTUIOPacketInput.GetString(0, out currentPacket); if (currentPacket == "" || currentPacket == null) { return; } int tuioPosition = currentPacket.IndexOf("#bundle"); if (tuioPosition == -1) { return; } while ((tuioPosition = currentPacket.IndexOf("#bundle")) >= 0) { int nextpos = currentPacket.IndexOf("#bundle", tuioPosition + 1); string currentSeperatedPacket = ""; if (nextpos == -1) { currentSeperatedPacket = currentPacket; currentPacket = ""; } else { currentSeperatedPacket = currentPacket.Substring(tuioPosition, nextpos - tuioPosition); currentPacket = currentPacket.Substring(nextpos); } OSC.NET.OSCPacket packet = OSC.NET.OSCPacket.Unpack(Encoding.Default.GetBytes(currentSeperatedPacket)); if (packet.IsBundle()) { ArrayList messages = packet.Values; for (int i = 0; i < messages.Count; i++) { FTuioClient.ProcessMessage((OSC.NET.OSCMessage)messages[i]); } } else { FTuioClient.ProcessMessage((OSC.NET.OSCMessage)packet); } } } List <TuioCursor> cursors = FTuioClient.getTuioCursors(); List <TuioObject> objects = FTuioClient.getTuioObjects(); List <TuioBlob> blobs = FTuioClient.getTuioBlobs(); int slicecount = cursors.Count + objects.Count + blobs.Count; FSessionIDOut.SliceCount = slicecount; FClassIDOut.SliceCount = slicecount; FUniqueIDOut.SliceCount = slicecount; FPosXOut.SliceCount = slicecount; FPosYOut.SliceCount = slicecount; FWidthOut.SliceCount = slicecount; FHeightOut.SliceCount = slicecount; FAreaOut.SliceCount = slicecount; FAngleOut.SliceCount = slicecount; FMovementXOut.SliceCount = slicecount; FMovementYOut.SliceCount = slicecount; FMotionAccelerationOut.SliceCount = slicecount; FRotationAccelerationOut.SliceCount = slicecount; FMotionSpeedOut.SliceCount = slicecount; FRotationSpeedOut.SliceCount = slicecount; int curindex = 0; for (int i = 0; i < cursors.Count; i++) { TuioCursor cur = cursors[i]; FSessionIDOut.SetValue(curindex, cur.getSessionID()); FClassIDOut.SetValue(curindex, 0); FUniqueIDOut.SetValue(curindex, cur.getFingerID()); FPosXOut.SetValue(curindex, cur.getPosition().getX() * 2 - 1); FPosYOut.SetValue(curindex, -cur.getPosition().getY() * 2 + 1); FAngleOut.SetValue(curindex, 0); FMovementXOut.SetValue(curindex, cur.getXSpeed()); FMovementYOut.SetValue(curindex, cur.getYSpeed()); FMotionAccelerationOut.SetValue(curindex, cur.getMotionAccel()); FRotationAccelerationOut.SetValue(curindex, 0); FMotionSpeedOut.SetValue(curindex, cur.getMotionSpeed()); FRotationSpeedOut.SetValue(curindex, 0); curindex++; } int objectOffset = 1000; for (int i = 0; i < objects.Count; i++) { TuioObject obj = objects[i]; FSessionIDOut.SetValue(curindex, obj.getSessionID()); FClassIDOut.SetValue(curindex, 1); FUniqueIDOut.SetValue(curindex, obj.getFiducialID() + objectOffset); FPosXOut.SetValue(curindex, obj.getPosition().getX() * 2 - 1); FPosYOut.SetValue(curindex, -obj.getPosition().getY() * 2 + 1); FAngleOut.SetValue(curindex, 1 - ((obj.getAngle()) / (Math.PI + Math.PI))); FMovementXOut.SetValue(curindex, obj.getXSpeed()); FMovementYOut.SetValue(curindex, obj.getYSpeed()); FMotionAccelerationOut.SetValue(curindex, obj.getMotionAccel()); FRotationAccelerationOut.SetValue(curindex, obj.getRotationAccel()); FMotionSpeedOut.SetValue(curindex, obj.getMotionSpeed()); FRotationSpeedOut.SetValue(curindex, obj.getRotationSpeed()); curindex++; } int blobOffset = 2000; for (int i = 0; i < blobs.Count; i++) { TuioBlob blb = blobs[i]; FSessionIDOut.SetValue(curindex, blb.getSessionID()); FClassIDOut.SetValue(curindex, 2); FUniqueIDOut.SetValue(curindex, blb.getBlobID() + blobOffset); FPosXOut.SetValue(curindex, blb.getPosition().getX() * 2 - 1); FPosYOut.SetValue(curindex, -blb.getPosition().getY() * 2 + 1); FWidthOut.SetValue(curindex, blb.getWidth()); FHeightOut.SetValue(curindex, blb.getHeight()); FAreaOut.SetValue(curindex, blb.getArea()); FAngleOut.SetValue(curindex, 1 - ((blb.getAngle()) / (Math.PI + Math.PI))); FMovementXOut.SetValue(curindex, blb.getXSpeed()); FMovementYOut.SetValue(curindex, blb.getYSpeed()); FMotionAccelerationOut.SetValue(curindex, blb.getMotionAccel()); FRotationAccelerationOut.SetValue(curindex, blb.getRotationAccel()); FMotionSpeedOut.SetValue(curindex, blb.getMotionSpeed()); FRotationSpeedOut.SetValue(curindex, blb.getRotationSpeed()); curindex++; } }