Пример #1
0
        public static bool IsPointInside(Polygon3D poly, Vec3D p)
        {
            if (p.Z < poly.bottom || p.Z > poly.top)
            {
                return(false);
            }

            return(Polygon2D.IsPointInside(poly.footprint, new Vec2D(p.X, p.Y)));
        }
Пример #2
0
        public static bool IsPointInside(Polygon3D poly, Vec3D p)
        {
            if (p.Z < poly.bottom || p.Z > poly.top)
            {
                return false;
            }

            return Polygon2D.IsPointInside(poly.footprint, new Vec2D(p.X, p.Y));
        }
Пример #3
0
 public static bool DoesLineCross(Polygon3D poly, Vec3D fromP, Vec3D toP)
 {
     if (fromP.Z < poly.bottom || fromP.Z > poly.top)
     {
         return false;
     }
     if (toP.Z < poly.bottom || toP.Z > poly.top)
     {
         return false;
     }
     return Polygon2D.DoesLineCross(poly.footprint, new Vec2D(fromP.X, fromP.Y), new Vec2D(toP.X, toP.Y));
 }
Пример #4
0
 public static bool SensorDoesLineCross(Polygon3D poly, Vec3D fromP, Vec3D toP)
 {
     if (fromP.Z < poly.bottom || fromP.Z > poly.top)
     {
         return(false);
     }
     if (toP.Z < poly.bottom || toP.Z > poly.top)
     {
         return(false);
     }
     return(Polygon2D.SensorDoesLineCross(poly.footprint, new Vec2D(fromP.X, fromP.Y), new Vec2D(toP.X, toP.Y)));
 }
Пример #5
0
        public static Vec3D FindIntersect(Polygon3D poly, Vec3D fromP, Vec3D toP)
        {
            Vec2D intersect = Polygon2D.FindIntersect(poly.footprint,
                                                      new Vec2D(fromP.X, fromP.Y),
                                                      new Vec2D(toP.X, toP.Y));

            if (intersect != null)
            {
                return new Vec3D(intersect.X, intersect.Y, fromP.Z);
            }
            else
            {
                return null;
            }
        }
Пример #6
0
        public static Vec3D FindIntersect(Polygon3D poly, Vec3D fromP, Vec3D toP)
        {
            Vec2D intersect = Polygon2D.FindIntersect(poly.footprint,
                                                      new Vec2D(fromP.X, fromP.Y),
                                                      new Vec2D(toP.X, toP.Y));

            if (intersect != null)
            {
                return(new Vec3D(intersect.X, intersect.Y, fromP.Z));
            }
            else
            {
                return(null);
            }
        }
Пример #7
0
        private void SendViewProActiveRegionUpdate(string objectID, bool isVisible, int displayColor, Polygon3D poly)
        {
            SimulationEvent vpmu = null;
            vpmu = SimulationEventFactory.BuildEvent(ref simModel, "ViewProActiveRegionUpdate");

            vpmu["ObjectID"] = DataValueFactory.BuildString(objectID);
            vpmu["IsVisible"] = DataValueFactory.BuildBoolean(isVisible);
            vpmu["DisplayColor"] = DataValueFactory.BuildInteger(displayColor);
            vpmu["Shape"] = poly.Footprint.GetPolygonValue();

            distClient.PutEvent(vpmu);
        }
Пример #8
0
        /// <summary>
        /// Calculates the absolute polygon of a region given a new location,
        /// using the region's reference point and relative polygon
        /// </summary>
        /// <param name="location"></param>
        /// <param name="region"></param>
        /// <returns></returns>
        private Polygon3D GetAbsolutePolygon(Vec2D refPoint, Polygon2D relativePolygon)
        {
            //Vec2D difference = refPoint.VectorDistanceTo(location);
            Polygon3D absolute = new Polygon3D(0,0);

            foreach (Vec2D vertex in relativePolygon.getVertices())
            {
                absolute.AddVertex(vertex.Add(refPoint));
            }
            return absolute;
        }
Пример #9
0
        Polygon3D createAbsoluteCollisionShape(Polygon3D relShape, LocationValue loc)
        {
            Polygon3D absShape = new Polygon3D(relShape.BottomZ + loc.Z, relShape.TopZ + loc.Z);
            foreach (Vec2D v in relShape.Footprint.getVertices())
            {
                v.X += loc.X;
                v.Y += loc.Y;
                absShape.AddVertex(v);
            }
            return absShape;

        }
Пример #10
0
        Polygon3D createRelativeCollisionShape(Double size)
        {
            Polygon3D shape = new Polygon3D(-size, size);
            for (int i = 0; i < 8; i++)
            {
                Double theta = (2 * Math.PI / 8) * i;
                double x = size * Math.Cos(theta);
                double y = size * Math.Sin(theta);
                shape.AddVertex(new Vec2D(x, y));
            }
            return shape;

        }
Пример #11
0
        private void NewObject(SimulationEvent e)
        {
            //objectProxies = bbClient.GetObjectProxies();

            string id = ((StringValue)e["ID"]).value;
            string type = ((StringValue)e["ObjectType"]).value;

            if (objectProxies == null)
            {
                objectProxies = new Dictionary<string, SimulationObjectProxy>();
            }
            SimulationObjectProxy prox = bbClient.GetObjectProxy(id);
            if (prox != null)
            {
                if (!objectProxies.ContainsKey(id))
                {
                    objectProxies.Add(id, prox);
                }
                else
                {
                    objectProxies[id] = prox;
                }
            }

            if (((StringValue)e["ObjectType"]).value == "LandRegion")
            {
                StateDB.LandRegion l = new StateDB.LandRegion(((StringValue)e["ID"]).value, null);
                Polygon2D poly = new Polygon2D();
                foreach (PolygonValue.PolygonPoint pp in ((PolygonValue)((AttributeCollectionValue)e["Attributes"]).attributes["Polygon"]).points)
                {
                    poly.AddVertex(new Vec2D(pp.X, pp.Y));
                }
                l.poly = poly;
                StateDB.landRegions[l.id] = l;
            }
            else if (((StringValue)e["ObjectType"]).value == "ActiveRegion")
            {
                StateDB.ActiveRegion b = new StateDB.ActiveRegion(((StringValue)e["ID"]).value, null);
                double start = ((DoubleValue)((AttributeCollectionValue)e["Attributes"]).attributes["StartHeight"]).value;
                double end = ((DoubleValue)((AttributeCollectionValue)e["Attributes"]).attributes["EndHeight"]).value;
                Polygon3D poly2 = new Polygon3D(start, end);
                foreach (PolygonValue.PolygonPoint pp in ((PolygonValue)((AttributeCollectionValue)e["Attributes"]).attributes["Polygon"]).points)
                {
                    poly2.AddVertex(new Vec2D(pp.X, pp.Y));
                }
                b.poly = poly2;
                if (((BooleanValue)((AttributeCollectionValue)e["Attributes"]).attributes["BlocksMovement"]).value)
                {
                    b.blockingRegion = true;
                }
                else
                {
                    b.blockingRegion = false;
                }
                if (((AttributeCollectionValue)e["Attributes"]).attributes.ContainsKey("SpeedMultiplier"))
                {
                    b.speedMultiplier = ((DoubleValue)((AttributeCollectionValue)e["Attributes"]).attributes["SpeedMultiplier"]).value;
                }
                else
                {
                    b.speedMultiplier = 1;
                }

                if (((AttributeCollectionValue)e["Attributes"]).attributes.ContainsKey("IsVisible"))
                {
                    b.isVisible = ((BooleanValue)((AttributeCollectionValue)e["Attributes"]).attributes["IsVisible"]).value;
                }
                else
                {
                    b.isVisible = false;
                }

                if (((AttributeCollectionValue)e["Attributes"]).attributes.ContainsKey("DisplayColor"))
                {
                    b.displayColor = ((IntegerValue)((AttributeCollectionValue)e["Attributes"]).attributes["DisplayColor"]).value;
                }
                else
                {
                    b.displayColor = -10185235;
                }


                //b.displayColor = -10185235;
                //b.isVisible = true;
                StateDB.activeRegions[b.id] = b;
            }
        }
Пример #12
0
        private void NewObject(SimulationEvent e)
        {
            //objectProxies = bbClient.GetObjectProxies();

            string id = ((StringValue)e["ID"]).value;
            string type = ((StringValue)e["ObjectType"]).value;

            if (objectProxies == null)
            {
                objectProxies = new Dictionary<string, SimulationObjectProxy>();
            }
            SimulationObjectProxy prox = bbClient.GetObjectProxy(id);
            if (prox != null)
            {
                if (!objectProxies.ContainsKey(id))
                {
                    objectProxies.Add(id, prox);
                }
                else
                {
                    objectProxies[id] = prox;
                }
            }

            if (((StringValue)e["ObjectType"]).value == "LandRegion")
            {
                StateDB.LandRegion l = new StateDB.LandRegion(((StringValue)e["ID"]).value, null);
                Polygon2D poly = new Polygon2D();
                foreach (PolygonValue.PolygonPoint pp in ((PolygonValue)((AttributeCollectionValue)e["Attributes"]).attributes["Polygon"]).points)
                {
                    poly.AddVertex(new Vec2D(pp.X, pp.Y));
                }
                l.poly = poly;
                StateDB.landRegions[l.id] = l;
            }
            else if (((StringValue)e["ObjectType"]).value == "ActiveRegion")
            {
                StateDB.ActiveRegion b = new StateDB.ActiveRegion(((StringValue)e["ID"]).value, null);
                double start = ((DoubleValue)((AttributeCollectionValue)e["Attributes"]).attributes["StartHeight"]).value;
                double end = ((DoubleValue)((AttributeCollectionValue)e["Attributes"]).attributes["EndHeight"]).value;
                Polygon3D poly2 = new Polygon3D(start, end);
                foreach (PolygonValue.PolygonPoint pp in ((PolygonValue)((AttributeCollectionValue)e["Attributes"]).attributes["Polygon"]).points)
                {
                    poly2.AddVertex(new Vec2D(pp.X, pp.Y));
                }
                b.poly = poly2;
                b.currentAbsolutePolygon = poly2;
                if (((BooleanValue)((AttributeCollectionValue)e["Attributes"]).attributes["BlocksMovement"]).value)
                {
                    b.blockingRegion = true;
                }
                else
                {
                    b.blockingRegion = false;
                }
                if (((AttributeCollectionValue)e["Attributes"]).attributes.ContainsKey("SpeedMultiplier"))
                {
                    b.speedMultiplier = ((DoubleValue)((AttributeCollectionValue)e["Attributes"]).attributes["SpeedMultiplier"]).value;
                }
                else
                {
                    b.speedMultiplier = 1;
                }

                if (((AttributeCollectionValue)e["Attributes"]).attributes.ContainsKey("IsVisible"))
                {
                    b.isVisible = ((BooleanValue)((AttributeCollectionValue)e["Attributes"]).attributes["IsVisible"]).value;
                }
                else
                {
                    b.isVisible = false;
                }

                if (((AttributeCollectionValue)e["Attributes"]).attributes.ContainsKey("DisplayColor"))
                {
                    b.displayColor = ((IntegerValue)((AttributeCollectionValue)e["Attributes"]).attributes["DisplayColor"]).value;
                }
                else
                {
                    b.displayColor = -10185235;
                }

                if (((AttributeCollectionValue)e["Attributes"]).attributes.ContainsKey("IsDynamicRegion"))
                {
                    b.isDynamicRegion = ((BooleanValue)((AttributeCollectionValue)e["Attributes"]).attributes["IsDynamicRegion"]).value;
                } else {
                    b.isDynamicRegion = false;
                }
                if (((AttributeCollectionValue)e["Attributes"]).attributes.ContainsKey("ReferencePoint") && !b.isDynamicRegion) //if isDynamic, will use its LinkedObject as Ref.
                {
                    b.referencePoint = new Vec2D(((LocationValue)((AttributeCollectionValue)e["Attributes"]).attributes["ReferencePoint"]));
                    b.currentAbsolutePolygon = GetAbsolutePolygon(b.referencePoint, poly2.Footprint);
                } else {
                    b.referencePoint = new Vec2D(0,0);
                }


                //Make separate lists for dynamic and active regions in StateDB
                if (b.isDynamicRegion) {
                    StateDB.dynamicRegions[b.id] = b;
                } else {
                    StateDB.activeRegions[b.id] = b;
                }

            }
        }
Пример #13
0
            public ActiveRegion(string id, Polygon3D poly)
            {
                this.id = id;
                this.poly = poly;
                this.sensorsBlocked = new List<string>();
                this.blockingRegion = false;
                this.speedMultiplier = 1;
                this.isVisible = true;
                this.displayColor = 0;
                this.linkedObject = "";
                this.isDynamicRegion = false;
                this.referencePoint = new Vec2D(0,0);
                this.currentAbsolutePolygon = new Polygon3D(0, 0);

            }
Пример #14
0
 public DynamicRegion(string id, Polygon3D poly, Vec2D refPoint)
 {
     this.id = id;
     this.poly = poly;
     this.sensorsBlocked = new List<string>();
     this.blockingRegion = false;
     this.speedMultiplier = 1;
     this.isVisible = true;
     this.displayColor = 0;
     this.referencePoint = refPoint;
 }