示例#1
0
    public static void setBoundingBoxCoordinates(ref Improbable.Controller.NoFlyZone nfz)
    {
        Vector3f BoundingBoxBottomLeft = nfz.vertices[0];
        Vector3f BoundingBoxTopRight   = nfz.vertices[0];

        foreach (Improbable.Vector3f vertex in nfz.vertices)
        {
            if (vertex.x > BoundingBoxTopRight.x)
            {
                BoundingBoxTopRight.x = vertex.x;
            }
            if (vertex.x < BoundingBoxBottomLeft.x)
            {
                BoundingBoxBottomLeft.x = vertex.x;
            }
            if (vertex.z > BoundingBoxTopRight.z)
            {
                BoundingBoxTopRight.z = vertex.z;
            }
            if (vertex.z < BoundingBoxBottomLeft.z)
            {
                BoundingBoxBottomLeft.z = vertex.z;
            }
        }

        nfz.boundingBoxBottomLeft = BoundingBoxBottomLeft;
        nfz.boundingBoxTopRight   = BoundingBoxTopRight;
    }
示例#2
0
    public static Improbable.Controller.NoFlyZone CreateCustomNoFlyZone(Improbable.Collections.List <Vector3f> vertices)
    {
        Improbable.Controller.NoFlyZone nfz = new Improbable.Controller.NoFlyZone();
        nfz.vertices = vertices;
        NoFlyZone.setBoundingBoxCoordinates(ref nfz);

        return(nfz);
    }
示例#3
0
    public void AddNoFlyZone(Improbable.Controller.NoFlyZone zone, bool sendUpdate = true)
    {
        zones.Add(zone);
        bitmap.addNoFlyZone(zone, sendUpdate);

        if (sendUpdate)
        {
            SendZonesUpdate();
        }
    }
示例#4
0
        private static int ShowNoFlyZones(Improbable.Controller.NoFlyZone noFlyZone, Dictionary <EntityId, Entity> snapshotEntities, int currentEntityId)
        {
            foreach (Vector3f vertex in noFlyZone.vertices)
            {
                snapshotEntities.Add(
                    new EntityId(currentEntityId++),
                    EntityTemplateFactory.CreateNfzNodeTemplate(vertex.ToCoordinates())
                    );
            }

            return(currentEntityId);
        }
示例#5
0
    public static bool isPointInTheBoundingBox(Improbable.Controller.NoFlyZone nfz, Improbable.Vector3f point)
    {
        bool res = false;

        if (point.x >= nfz.boundingBoxBottomLeft.x & point.x <= nfz.boundingBoxTopRight.x)
        {
            if (point.z >= nfz.boundingBoxBottomLeft.z & point.z <= nfz.boundingBoxTopRight.z)
            {
                res = true;
            }
        }
        return(res);
    }
示例#6
0
    public static Improbable.Controller.NoFlyZone GetNoFlyZone(NFZTemplate template)
    {
        Improbable.Controller.NoFlyZone nfz = new Improbable.Controller.NoFlyZone();
        nfz.vertices = new Improbable.Collections.List <Improbable.Vector3f>();

        float[] coords = getPoints(template);
        for (int i = 0; i < coords.Length; i += 2)
        {
            nfz.vertices.Add(new Improbable.Vector3f(coords[i], 0, coords[i + 1]));
        }

        NoFlyZone.setBoundingBoxCoordinates(ref nfz);

        return(nfz);
    }
示例#7
0
    private static bool isInPolygon(Improbable.Controller.NoFlyZone nfz, Improbable.Vector3f point)
    {
        bool isInside = false;

        for (int i = 0, j = nfz.vertices.Count - 1; i < nfz.vertices.Count; j = i++)
        {
            bool isInZRange = ((nfz.vertices[i].z > point.z) != (nfz.vertices[j].z > point.z));

            if (isInZRange &&
                (point.x < (nfz.vertices[j].x - nfz.vertices[i].x) * (point.z - nfz.vertices[i].z)
                 / (nfz.vertices[j].z - nfz.vertices[i].z) + nfz.vertices[i].x))
            {
                isInside = !isInside;
            }
        }
        return(isInside);
    }
示例#8
0
    public void addNoFlyZone(Improbable.Controller.NoFlyZone noFlyZone, bool sendUpdate = true)
    {
        Improbable.Vector3f[] vertices         = noFlyZone.vertices.ToArray();
        Improbable.Vector3f   previousWaypoint = vertices[0];
        for (int i = 1; i < vertices.Length; i++)
        {
            Improbable.Vector3f currentWaypoint = vertices[i];
            setLine(previousWaypoint, currentWaypoint);
            previousWaypoint = currentWaypoint;
        }

        setLine(previousWaypoint, vertices[0]); // setting the final line

        if (sendUpdate)
        {
            sendGridUpdate();
        }
    }
示例#9
0
 public static bool hasCollidedWith(Improbable.Controller.NoFlyZone nfz, Improbable.Vector3f point)
 {
     return(isInPolygon(nfz, point));
 }