Exemplo n.º 1
0
    /*
     * Checks if user reached an intersection.
     * */
    private bool isPathLeft(VirtualIntersection intersection)
    {
        int direction = getRedirectionDirection(intersection.getJoint(), currentPath.getCurve());
        int pathIndex = data.getPathIndex(intersection.getJoint(), currentPath.getCurve());

        Vector3 directionToPathCircleCenter = (currentPath.getCurve().getCircleCenter() - intersection.getJoint().getWalkingStartPosition(pathIndex)).normalized;
        Vector3 rotatedDirectionVector      = Quaternion.AngleAxis(-direction * 90f, Vector3.up) * directionToPathCircleCenter;
        Plane   plane = new Plane(rotatedDirectionVector.normalized, intersection.getJoint().getWalkingStartPosition(pathIndex));

        if (plane.GetSide(Camera.main.transform.localPosition))
        {
            return(false);
        }
        return(true);
    }
Exemplo n.º 2
0
    /*
     * Draws all joint points, curves, paths, and intersections to the scene view.
     * */
    void OnSceneGUI(SceneView sceneView)
    {
        if (data == null)
        {
            return;
        }
        if (data.jointPointA == null)
        {
            return;
        }
        if (data.jointPointB == null)
        {
            return;
        }
        if (data.jointPointC == null)
        {
            return;
        }

        GUIStyle style = new GUIStyle();

        style.normal.textColor = Color.black;

        // Real world joint points
        if (showJoints)
        {
            Handles.color = Color.red;
            Handles.SphereCap(0, data.jointPointA.getPosition(), Quaternion.identity, 0.2f);
            Handles.Label(data.jointPointA.getPosition(), data.jointPointA.getLabel(), style);
            Handles.SphereCap(0, data.jointPointA.getWalkingStartPosition(0), Quaternion.identity, 0.1f);
            Handles.SphereCap(0, data.jointPointA.getWalkingStartPosition(1), Quaternion.identity, 0.1f);
            Handles.SphereCap(0, data.jointPointA.getWalkingStartPosition(2), Quaternion.identity, 0.1f);
            Handles.SphereCap(0, data.jointPointA.getWalkingStartPosition(3), Quaternion.identity, 0.1f);

            Handles.SphereCap(0, data.jointPointB.getPosition(), Quaternion.identity, 0.2f);
            Handles.Label(data.jointPointB.getPosition(), data.jointPointB.getLabel(), style);
            Handles.SphereCap(0, data.jointPointB.getWalkingStartPosition(0), Quaternion.identity, 0.1f);
            Handles.SphereCap(0, data.jointPointB.getWalkingStartPosition(1), Quaternion.identity, 0.1f);
            Handles.SphereCap(0, data.jointPointB.getWalkingStartPosition(2), Quaternion.identity, 0.1f);
            Handles.SphereCap(0, data.jointPointB.getWalkingStartPosition(3), Quaternion.identity, 0.1f);

            Handles.SphereCap(0, data.jointPointC.getPosition(), Quaternion.identity, 0.2f);
            Handles.Label(data.jointPointC.getPosition(), data.jointPointC.getLabel(), style);
            Handles.SphereCap(0, data.jointPointC.getWalkingStartPosition(0), Quaternion.identity, 0.1f);
            Handles.SphereCap(0, data.jointPointC.getWalkingStartPosition(1), Quaternion.identity, 0.1f);
            Handles.SphereCap(0, data.jointPointC.getWalkingStartPosition(2), Quaternion.identity, 0.1f);
            Handles.SphereCap(0, data.jointPointC.getWalkingStartPosition(3), Quaternion.identity, 0.1f);
        }

        // Real world curves
        if (showCurves)
        {
            Handles.color = Color.red;

            Vector3 directionVector = data.jointPointB.getWalkingStartPosition(2) - data.curveABsmallRadius.getCircleCenter();
            Handles.DrawWireArc(data.curveABsmallRadius.getCircleCenter(), Vector3.up, directionVector, data.curveABsmallRadius.getAngle(), data.curveABsmallRadius.getRadius());

            directionVector = data.jointPointB.getWalkingStartPosition(3) - data.curveABlargeRadius.getCircleCenter();
            Handles.DrawWireArc(data.curveABlargeRadius.getCircleCenter(), Vector3.up, directionVector, data.curveABlargeRadius.getAngle(), data.curveABlargeRadius.getRadius());

            directionVector = data.jointPointC.getWalkingStartPosition(2) - data.curveBCsmallRadius.getCircleCenter();
            Handles.DrawWireArc(data.curveBCsmallRadius.getCircleCenter(), Vector3.up, directionVector, data.curveBCsmallRadius.getAngle(), data.curveBCsmallRadius.getRadius());

            directionVector = data.jointPointC.getWalkingStartPosition(3) - data.curveBClargeRadius.getCircleCenter();
            Handles.DrawWireArc(data.curveBClargeRadius.getCircleCenter(), Vector3.up, directionVector, data.curveBClargeRadius.getAngle(), data.curveBClargeRadius.getRadius());

            directionVector = data.jointPointA.getWalkingStartPosition(2) - data.curveACsmallRadius.getCircleCenter();
            Handles.DrawWireArc(data.curveACsmallRadius.getCircleCenter(), Vector3.up, directionVector, data.curveACsmallRadius.getAngle(), data.curveACsmallRadius.getRadius());

            directionVector = data.jointPointA.getWalkingStartPosition(3) - data.curveAClargeRadius.getCircleCenter();
            Handles.DrawWireArc(data.curveAClargeRadius.getCircleCenter(), Vector3.up, directionVector, data.curveAClargeRadius.getAngle(), data.curveAClargeRadius.getRadius());
        }

        // Virtual world intersections
        if (showIntersections)
        {
            Handles.color = Color.green;
            foreach (VirtualIntersection intersection in data.intersections)
            {
                // Change color for currently chosen intersection
                if (intersection.Equals(data.intersections[intersectionIndex]))
                {
                    Handles.color = Color.yellow;
                }
                else
                {
                    Handles.color = Color.green;
                }

                Handles.SphereCap(0, intersection.getPosition(), Quaternion.identity, 0.2f);
                Handles.Label(intersection.getPosition(), intersection.getLabel(), style);
                Handles.SphereCap(0, intersection.getWalkingStartPosition(0), Quaternion.identity, 0.1f);
                Handles.SphereCap(0, intersection.getWalkingStartPosition(1), Quaternion.identity, 0.1f);
                Handles.SphereCap(0, intersection.getWalkingStartPosition(2), Quaternion.identity, 0.1f);
                Handles.SphereCap(0, intersection.getWalkingStartPosition(3), Quaternion.identity, 0.1f);
            }
        }

        // Virtual world paths
        if (showPaths)
        {
            foreach (VirtualPath path in data.paths)
            {
                int sign      = data.getSignOfCurve(path.getEndPoints()[0].getJoint(), path.getEndPoints()[1].getJoint());
                int pathIndex = data.getPathIndex(path.getEndPoints()[0].getJoint(), path.getCurve());

                Handles.color = Color.green;
                Vector3 directionVector = path.getEndPoints()[0].getWalkingStartPosition(pathIndex) - path.getCircleCenter();
                Handles.DrawWireArc(path.getCircleCenter(), Vector3.up, directionVector, sign * path.getAngle(), path.getRadius());
            }
        }

        Handles.BeginGUI();
        // GUI stuff comes here
        Handles.EndGUI();
    }