void LateUpdate() { if (rend.isVisible) { //gets current position of the current_location_bar r_color = rend.color; //if this marker is in list of active markers and current_location_bar is over this sprite and the marker is not moving, make it glow if (m_lastComeLastServe.IsBeingPlayed(this.gameObject) && fiducial.IsSnapped()) { //chooses correct glow material to be set if (r_color == red) { rend.material = redMaterial; } else if (r_color == green) { rend.material = greenMaterial; } else if (r_color == blue) { rend.material = blueMaterial; } } //sets material to defaultMaterial if current_location_bar is not over this sprite else if (rend.material != defaultMaterial) { rend.material = defaultMaterial; } } }
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)); }