예제 #1
0
    /*
     * Sets a joint point as the new start position. Removes all saved virtual paths and intersections.
     * */
    public void setStartPosition(JointPoint joint)
    {
        startJoint    = joint;
        intersections = new List <VirtualIntersection>();
        paths         = new List <VirtualPath>();

        VirtualIntersection intersection = CreateInstance <VirtualIntersection>();

        intersection.init(joint.getPosition(), joint, "" + intersections.Count);
        intersections.Add(intersection);

        intersection.setWalkingStartPosition(0, joint.getWalkingStartPosition(0));
        intersection.setWalkingStartPosition(1, joint.getWalkingStartPosition(1));
        intersection.setWalkingStartPosition(2, joint.getWalkingStartPosition(2));
        intersection.setWalkingStartPosition(3, joint.getWalkingStartPosition(3));

#if UNITY_EDITOR
        SceneView.RepaintAll();
        AssetDatabase.AddObjectToAsset(intersection, this);
        EditorUtility.SetDirty(this);
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
#endif
        Debug.Log("Set new start position");
    }
예제 #2
0
    /*
     * Creates a curve from joint1 to joint2 with the center between both points (plus offset for real walking area at joint point).
     * */
    private Curve createSmallCurve(JointPoint joint1, JointPoint joint2)
    {
        Vector3 circleCenter = Vector3.Lerp(joint1.getPosition(), joint2.getPosition(), 0.5f);

        float             radius    = 0.5f * Vector3.Magnitude(joint1.getPosition() - joint2.getPosition());
        List <JointPoint> endPoints = new List <JointPoint>();

        endPoints.Add(joint1);
        endPoints.Add(joint2);
        Curve curve = CreateInstance <Curve>();

        curve.init(circleCenter, radius, endPoints, true);

#if UNITY_EDITOR
        AssetDatabase.AddObjectToAsset(curve, this);
        EditorUtility.SetDirty(this);
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
#endif

        return(curve);
    }
예제 #3
0
    /*
     * Calculates walking start positions for new intersection
     * */
    private void calculateWalkingStartPositions(int pathIndex, JointPoint endJointPoint, VirtualIntersection endIntersection, Vector3 circleCenter, Vector3 directionToEndPath)
    {
        endIntersection.setWalkingStartPosition(pathIndex, circleCenter + directionToEndPath);

        Vector3 directionToCurve0 = endJointPoint.getWalkingStartPosition(0) - endJointPoint.getPosition();
        Vector3 directionToCurve1 = endJointPoint.getWalkingStartPosition(1) - endJointPoint.getPosition();
        Vector3 directionToCurve2 = endJointPoint.getWalkingStartPosition(2) - endJointPoint.getPosition();
        Vector3 directionToCurve3 = endJointPoint.getWalkingStartPosition(3) - endJointPoint.getPosition();

        float angleBetweenCurves01 = angle360(directionToCurve0, directionToCurve1);
        float angleBetweenCurves02 = angle360(directionToCurve0, directionToCurve2);
        float angleBetweenCurves03 = angle360(directionToCurve0, directionToCurve3);

        float angleBetweenCurves12 = angle360(directionToCurve1, directionToCurve2);
        float angleBetweenCurves13 = angle360(directionToCurve1, directionToCurve3);
        float angleBetweenCurves10 = angle360(directionToCurve1, directionToCurve0);

        float angleBetweenCurves23 = angle360(directionToCurve2, directionToCurve3);
        float angleBetweenCurves20 = angle360(directionToCurve2, directionToCurve0);
        float angleBetweenCurves21 = angle360(directionToCurve2, directionToCurve1);

        float angleBetweenCurves30 = angle360(directionToCurve3, directionToCurve0);
        float angleBetweenCurves31 = angle360(directionToCurve3, directionToCurve1);
        float angleBetweenCurves32 = angle360(directionToCurve3, directionToCurve2);

        Vector3 directionToFirstStartPosition = (circleCenter + directionToEndPath) - endIntersection.getPosition();
        Vector3 directionToOtherStartPosition = new Vector3();

        switch (pathIndex)
        {
        case 0:
            endIntersection.setWalkingStartPosition(0, circleCenter + directionToEndPath);

            directionToOtherStartPosition = Quaternion.AngleAxis(angleBetweenCurves01, Vector3.up) * directionToFirstStartPosition;
            endIntersection.setWalkingStartPosition(1, endIntersection.getPosition() + directionToOtherStartPosition);
            directionToOtherStartPosition = Quaternion.AngleAxis(angleBetweenCurves02, Vector3.up) * directionToFirstStartPosition;
            endIntersection.setWalkingStartPosition(2, endIntersection.getPosition() + directionToOtherStartPosition);
            directionToOtherStartPosition = Quaternion.AngleAxis(angleBetweenCurves03, Vector3.up) * directionToFirstStartPosition;
            endIntersection.setWalkingStartPosition(3, endIntersection.getPosition() + directionToOtherStartPosition);
            break;

        case 1:
            endIntersection.setWalkingStartPosition(1, circleCenter + directionToEndPath);

            directionToOtherStartPosition = Quaternion.AngleAxis(angleBetweenCurves12, Vector3.up) * directionToFirstStartPosition;
            endIntersection.setWalkingStartPosition(2, endIntersection.getPosition() + directionToOtherStartPosition);
            directionToOtherStartPosition = Quaternion.AngleAxis(angleBetweenCurves13, Vector3.up) * directionToFirstStartPosition;
            endIntersection.setWalkingStartPosition(3, endIntersection.getPosition() + directionToOtherStartPosition);
            directionToOtherStartPosition = Quaternion.AngleAxis(angleBetweenCurves10, Vector3.up) * directionToFirstStartPosition;
            endIntersection.setWalkingStartPosition(0, endIntersection.getPosition() + directionToOtherStartPosition);
            break;

        case 2:
            endIntersection.setWalkingStartPosition(2, circleCenter + directionToEndPath);

            directionToOtherStartPosition = Quaternion.AngleAxis(angleBetweenCurves23, Vector3.up) * directionToFirstStartPosition;
            endIntersection.setWalkingStartPosition(3, endIntersection.getPosition() + directionToOtherStartPosition);
            directionToOtherStartPosition = Quaternion.AngleAxis(angleBetweenCurves20, Vector3.up) * directionToFirstStartPosition;
            endIntersection.setWalkingStartPosition(0, endIntersection.getPosition() + directionToOtherStartPosition);
            directionToOtherStartPosition = Quaternion.AngleAxis(angleBetweenCurves21, Vector3.up) * directionToFirstStartPosition;
            endIntersection.setWalkingStartPosition(1, endIntersection.getPosition() + directionToOtherStartPosition);
            break;

        case 3:
            endIntersection.setWalkingStartPosition(3, circleCenter + directionToEndPath);

            directionToOtherStartPosition = Quaternion.AngleAxis(angleBetweenCurves30, Vector3.up) * directionToFirstStartPosition;
            endIntersection.setWalkingStartPosition(0, endIntersection.getPosition() + directionToOtherStartPosition);
            directionToOtherStartPosition = Quaternion.AngleAxis(angleBetweenCurves31, Vector3.up) * directionToFirstStartPosition;
            endIntersection.setWalkingStartPosition(1, endIntersection.getPosition() + directionToOtherStartPosition);
            directionToOtherStartPosition = Quaternion.AngleAxis(angleBetweenCurves32, Vector3.up) * directionToFirstStartPosition;
            endIntersection.setWalkingStartPosition(2, endIntersection.getPosition() + directionToOtherStartPosition);
            break;
        }
    }