예제 #1
0
    /** Adds an obstacle with the specified vertices.
     * The vertices array might be changed by this function. */
    private void AddObstacle(Vector3[] vertices, float height, Pathfinding.RVO.Simulator sim, ref List <ObstacleVertex> obstacles)
    {
        if (vertices == null)
        {
            throw new System.ArgumentNullException("Vertices Must Not Be Null");
        }
        if (height < 0)
        {
            throw new System.ArgumentOutOfRangeException("Height must be non-negative");
        }
        if (vertices.Length < 2)
        {
            throw new System.ArgumentException("An obstacle must have at least two vertices");
        }

        if (null == obstacles)
        {
            obstacles = new List <ObstacleVertex>();
        }
        obstacles.Clear();

        if (vertices.Length > 2)
        {
            WindCorrectly(vertices);
        }

        for (int vert = 0; vert < vertices.Length; ++vert)
        {
            Vector3 v1          = vertices[vert];
            Vector3 v2          = vertices[(vert + 1) % vertices.Length];
            Vector3 dir         = v2 - v1;
            Vector3 pushAwayDir = new Vector3(dir.z, 0f, -dir.x);
            obstacles.Add(sim.CreateObstacle(v1, v2, pushAwayDir, height, _isActive));
        }
    }