Exemple #1
0
    /*
     * Returns the circle center position of the new path that starts at given intersection and uses given curve and radius.
     * */
    private Vector3 calculateCircleCenterOfPath(VirtualIntersection startIntersection, Curve curve, float radius)
    {
        int newPathIndex = this.getPathIndex(startIntersection.getJoint(), curve);

        Vector3 directionToCurveCircleCenter = (curve.getCircleCenter() - startIntersection.getJoint().getWalkingStartPosition(newPathIndex)).normalized;
        Vector3 directionToPathCircleCenter  = new Vector3();

        // Check which paths are connected to the intersection and pick one (first) for calculation.
        // New path circle center can be calculated by using the direction to the curve circle center and rotating it.
        for (int i = 0; i < 4; i++)
        {
            if (startIntersection.getPath(i) != null)
            {
                Vector3 directionToStartWalkingPosOnPath  = (startIntersection.getWalkingStartPosition(i) - startIntersection.getPosition()).normalized;
                Vector3 directionToStartWalkingPosOnCurve = (startIntersection.getJoint().getWalkingStartPosition(i) - startIntersection.getJoint().getPosition()).normalized;
                float   angle = -angle360(directionToStartWalkingPosOnPath, directionToStartWalkingPosOnCurve);
                directionToPathCircleCenter = Quaternion.AngleAxis(angle, Vector3.up) * directionToCurveCircleCenter;
                break;
            }
            if (i == 3)
            {
                // If no case was chosen this is the start joint. Then,
                // we can use the curve circle center for calculating the path circle center without rotating.
                directionToPathCircleCenter = directionToCurveCircleCenter;
            }
        }

        Vector3 result = startIntersection.getWalkingStartPosition(newPathIndex) + directionToPathCircleCenter.normalized * radius;

        return(result);
    }
Exemple #2
0
    /*
     * Starts, stops, and executes the redirection.
     * In the beginning, "ready" button has to be pressed. Then, the user can start walking and
     * the redirection will be started and stopped automatically when crossing the intersections.
     *
     * "Ready" button -> startRedirection -> stopRedirection
     * */
    void Update()
    {
        if (redirectionStarted)
        {
            doRedirection();

            // if user reaches one of the endpoints of current path
            //      stop redirection

            // Is user stopping at end intersection?
            if (isPathLeft(currentPath.getOtherIntersection(currentIntersection)))
            {
                stopRedirection(currentPath.getOtherIntersection(currentIntersection), true);
            }

            // Is user stopping at start intersection?
            else if (isPathLeft(currentIntersection))
            {
                stopRedirection(currentIntersection, false);
            }
        }
        else if (ready)
        {
            // if user crosses boundary to one of the paths
            //      start redirection

            if (currentIntersection.getPath(0) != null)
            {
                if (isPathChosen(currentIntersection.getPath(0)))
                {
                    startRedirection(currentIntersection.getPath(0));
                }
            }
            if (currentIntersection.getPath(1) != null)
            {
                if (isPathChosen(currentIntersection.getPath(1)))
                {
                    startRedirection(currentIntersection.getPath(1));
                }
            }
            if (currentIntersection.getPath(2) != null)
            {
                if (isPathChosen(currentIntersection.getPath(2)))
                {
                    startRedirection(currentIntersection.getPath(2));
                }
            }
            if (currentIntersection.getPath(3) != null)
            {
                if (isPathChosen(currentIntersection.getPath(3)))
                {
                    startRedirection(currentIntersection.getPath(3));
                }
            }
        }
    }