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; }
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); }
public void AddNoFlyZone(Improbable.Controller.NoFlyZone zone, bool sendUpdate = true) { zones.Add(zone); bitmap.addNoFlyZone(zone, sendUpdate); if (sendUpdate) { SendZonesUpdate(); } }
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); }
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); }
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); }
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); }
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(); } }
public static bool hasCollidedWith(Improbable.Controller.NoFlyZone nfz, Improbable.Vector3f point) { return(isInPolygon(nfz, point)); }