void Update()
    {
        if (m_obj != null)
        {
            if (m_fiducialController.IsSnapped() &&
                !Mathf.Approximately(this.transform.position.x, newPos.x))
            {
                newPos = this.transform.position;

                //tells locationBar new position
                if (startMarker)
                {
                    m_locationBar.SetStartBarPosition(newPos);
                }
                else
                {
                    m_locationBar.SetEndBarPosition(newPos);
                }
            }

            if (!m_fiducialController.IsSnapped() && ghost == null)
            {
                ghost = GameObject.Instantiate(ghostPrefab, newPos, Quaternion.identity);
            }
            else if (m_fiducialController.IsSnapped())
            {
                Destroy(ghost);
                ghost = null;
            }
        }
        else
        {
            m_obj = m_tuioManager.GetMarker(m_fiducialController.MarkerID);
        }
    }
    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));
    }