Exemplo n.º 1
0
        public static JGeometry.Polygon Polygon2JG(SimplePolygon simplePolygon)
        {
            var rings = (from ring in simplePolygon.rings select Polyline2JG(ring)).ToList();

            JGeometry.Polygon polygon = new JGeometry.Polygon(rings);
            return(polygon);
        }
Exemplo n.º 2
0
        public void TestNonSimple()
        {
            var polylist = new List <Vector>
            {
                new Vector(0, 0),
                new Vector(4, 0),
                new Vector(2, 1),
                new Vector(5, 2),
                new Vector(1, 2),
                new Vector(3, 1),
            };

            Assert.IsFalse(SimplePolygon.FTestSimplePolygon(polylist));

            // Just barely touching the line
            polylist = new List <Vector>
            {
                new Vector(0, 0),
                new Vector(1, 1),
                new Vector(0, 1),
                new Vector(1, 2),
                new Vector(0, 2)
            };
            Assert.IsFalse(SimplePolygon.FTestSimplePolygon(polylist));
        }
 // Update is called once per frame
 void Update()
 {
     if (transform.hasChanged)
     {
         poly = SimplePolygon.boxCollider2DToSimplePolygon(coll);
     }
 }
Exemplo n.º 4
0
        public Boolean Evaluate(Feature feature)
        {
            if (feature.geometry == null)
            {
                return(false);
            }
            switch (feature.geometry.geometryType)
            {
            case OSGeo.OGR.wkbGeometryType.wkbPoint:
                PointD point_data = (PointD)feature.geometry;
                PointD point_map  = this.rsTransfrom.sourceToTarget(point_data);
                return(SpatialTopology.IsPointInRectangle(point_map, this.rect));

            case OSGeo.OGR.wkbGeometryType.wkbPolygon:
                SimplePolygon polygon_data = (SimplePolygon)feature.geometry;
                return(checksimplepolygon(polygon_data));

            case OSGeo.OGR.wkbGeometryType.wkbLineString:
                SimplePolyline line_data = (SimplePolyline)feature.geometry;
                return(checkpolyline(line_data));

            case OSGeo.OGR.wkbGeometryType.wkbMultiPolygon:
                Polygon mutipolygon_data = (Polygon)feature.geometry;
                return(checkmutipolygon(mutipolygon_data));

            case OSGeo.OGR.wkbGeometryType.wkbMultiLineString:
                break;
            }
            //to do
            return(false);
        }
Exemplo n.º 5
0
 private void btn_GRB_Click(object sender, RoutedEventArgs e)
 {
     simplePolygon = new SimplePolygon();
     simplePolygon.Initialize(10, 30, 570, 30, 370);
     drawPoints();
     drawingLine();
     drawingEmitLine();
     resizeCanvas();
 }
Exemplo n.º 6
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        SimplePolygon myScript = (SimplePolygon)target;

        if (GUILayout.Button("Rebuild mesh"))
        {
            myScript.Rebuild();
        }
    }
Exemplo n.º 7
0
 public bool checkmutipolygon(Polygon mutipolygon_data)
 {
     for (int i = 0; i < mutipolygon_data.childPolygons.Count; i++)
     {
         SimplePolygon simple = mutipolygon_data.childPolygons[i];
         if (checksimplepolygon(simple))
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 8
0
        //判断多边形与矩形是否相交
        public static bool IsSimplePolygonIntersectRect(SimplePolygon polygon, Rectangle rect)
        {
            Rectangle polyrect = polygon.getEnvelop();

            if (!IsRectangleIntersect(polyrect, rect))
            {
                return(false);
            }

            List <PointD> points     = polygon.rings[0].points;
            int           pointcount = points.Count;

            for (int i = 0; i < pointcount - 1; i++)
            {
                if (IsSegmentIntersectsegment(points[i], points[i + 1], new PointD(rect.minX, rect.minY), new PointD(rect.minX, rect.maxY)))
                {
                    return(true);
                }
                if (IsSegmentIntersectsegment(points[i], points[i + 1], new PointD(rect.minX, rect.minY), new PointD(rect.maxX, rect.minY)))
                {
                    return(true);
                }
                if (IsSegmentIntersectsegment(points[i], points[i + 1], new PointD(rect.maxX, rect.minY), new PointD(rect.maxX, rect.maxY)))
                {
                    return(true);
                }
                if (IsSegmentIntersectsegment(points[i], points[i + 1], new PointD(rect.minX, rect.maxY), new PointD(rect.maxX, rect.maxY)))
                {
                    return(true);
                }
            }
            //判断点是否在矩形内,若一个点在矩形内,则该多边形在矩形内
            if (pointcount > 0)
            {
                PointD polygonpoint = polygon.rings[0].points.First();
                if (IsPointInRectangle(polygonpoint, rect))
                {
                    return(true);
                }
            }
            //判断矩形框是否在多边形内
            PointD point_rect = new PointD((rect.minX + rect.maxX) / 2, (rect.maxY + rect.minY) / 2);

            if (IsPointInPolygon(point_rect, points))
            {
                return(true);
            }
            return(false);
        }
Exemplo n.º 9
0
        public bool checksimplepolygon(SimplePolygon polygon_data)
        {
            List <PointD> ring0_points_data = polygon_data.rings[0].points;
            List <PointD> ring0_points_map  = new List <PointD>();

            for (int i = 0; i < ring0_points_data.Count; i++)
            {
                ring0_points_map.Add(this.rsTransfrom.sourceToTarget(ring0_points_data[i]));
            }
            SimplePolyline        ring0       = new SimplePolyline(ring0_points_map);
            List <SimplePolyline> temp        = new List <SimplePolyline>(); temp.Add(ring0);
            SimplePolygon         polygon_map = new SimplePolygon(temp);

            return(SpatialTopology.IsSimplePolygonIntersectRect(polygon_map, this.rect));
        }
Exemplo n.º 10
0
        public static string SimplePolygon2String(SimplePolygon geom)
        {
            string s = "(";
            List <SimplePolyline> rings = geom.rings;

            for (int i = 0; i < rings.Count; i++)
            {
                if (i > 0)
                {
                    s += ",";
                }
                s += SimplePolyline2String(rings[i]);
            }
            return(s + ")");
        }
Exemplo n.º 11
0
        public bool CheckIsPointSelectedofSelectedFeatureCollection(PointD mouselocation, double interval)
        {
            if (selectedFeatureCollection == null || selectedFeatureCollection.featureList.Count == 0)
            {
                return(false);
            }
            foreach (Feature feature in selectedFeatureCollection.featureList)
            {
                switch (feature.geometry.geometryType)
                {
                case OSGeo.OGR.wkbGeometryType.wkbPoint:
                    if (SpatialTopology.GetDistanceBetweenPoints((PointD)feature.geometry, mouselocation) < interval)
                    {
                        this.selectedPoint = (PointD)feature.geometry;
                        return(true);
                    }
                    break;

                case OSGeo.OGR.wkbGeometryType.wkbLineString:
                    SimplePolyline simpleline = (SimplePolyline)feature.geometry;
                    foreach (PointD linepoint in simpleline.points)
                    {
                        if (SpatialTopology.GetDistanceBetweenPoints(linepoint, mouselocation) < interval)
                        {
                            this.selectedPoint = linepoint;
                            return(true);
                        }
                    }
                    break;

                case OSGeo.OGR.wkbGeometryType.wkbPolygon:
                    SimplePolygon simplepolygon = (SimplePolygon)feature.geometry;
                    foreach (SimplePolyline ring in simplepolygon.rings)
                    {
                        foreach (PointD linepoint in ring.points)
                        {
                            if (SpatialTopology.GetDistanceBetweenPoints(linepoint, mouselocation) < interval)
                            {
                                this.selectedPoint = linepoint;
                                return(true);
                            }
                        }
                    }
                    break;
                }
            }
            this.selectedPoint = null; return(false);
        }
Exemplo n.º 12
0
    private void Update()
    {
        var _childCount = transform.childCount;

        if (_childCount >= 4)
        {
            var _p0      = GetChildPos(0);
            var _p1      = GetChildPos(1);
            var _p2      = GetChildPos(2);
            var _p3      = GetChildPos(3);
            var _crossed = SimplePolygon.SegmenetCross(_p0, _p1, _p2, _p3);
            if (m_showText != null)
            {
                m_showText.text = _crossed?"Cross":"Not Cross";
            }
        }
    }
Exemplo n.º 13
0
        public void FinishEdit()
        {
            lists.Add(editingpoints);
            switch (geometrytype)
            {
            case OSGeo.OGR.wkbGeometryType.wkbPoint:
                foreach (List <PointD> onelist in lists)
                {
                    for (int i = 0; i < onelist.Count; i++)
                    {
                        Feature pointfeature = new Feature(EditingFeaturesource.GetNextFeatureID(), EditingFeaturesource.schema, onelist[i]);
                        LogItem_CreateFeature logitem_create_point = new LogItem_CreateFeature(this.layername, pointfeature.featureID);
                        Utils.gislog.AddLog(logitem_create_point);
                        EditingFeaturesource.features.InsertFeature(pointfeature);
                    }
                }
                break;

            case OSGeo.OGR.wkbGeometryType.wkbLineString:
                foreach (List <PointD> onelist in lists)
                {
                    SimplePolyline        simplepolyline      = new SimplePolyline(onelist);
                    Feature               linefeature         = new Feature(EditingFeaturesource.GetNextFeatureID(), EditingFeaturesource.schema, simplepolyline);
                    LogItem_CreateFeature logitem_create_line = new LogItem_CreateFeature(this.layername, linefeature.featureID);
                    Utils.gislog.AddLog(logitem_create_line);
                    EditingFeaturesource.features.InsertFeature(linefeature);
                }
                break;

            case OSGeo.OGR.wkbGeometryType.wkbPolygon:
                List <SimplePolyline> rings = new List <SimplePolyline>();
                foreach (List <PointD> onelist in lists)
                {
                    onelist.Add(onelist.First());
                    SimplePolyline onering = new SimplePolyline(onelist);
                    rings.Add(onering);
                }
                SimplePolygon         simplepolygon          = new SimplePolygon(rings);
                Feature               polygonfeature         = new Feature(EditingFeaturesource.GetNextFeatureID(), EditingFeaturesource.schema, simplepolygon);
                LogItem_CreateFeature logitem_create_polygon = new LogItem_CreateFeature(this.layername, polygonfeature.featureID);
                Utils.gislog.AddLog(logitem_create_polygon);
                EditingFeaturesource.features.InsertFeature(polygonfeature);
                break;
            }
            this.editstatus = EditStatus.finished;
        }
Exemplo n.º 14
0
        public override void _Ready()
        {
            var size = GetViewportRect().Size;

            var wall = new SimpleWall()
            {
                BodySize = new Vector2(size.x, 50),
                Position = new Vector2(size.x / 2, size.y)
            };

            AddChild(wall);

            var spawner = new SimpleTouchSpawner()
            {
                SpawnFunction = (position) =>
                {
                    var           chance  = MathUtils.RandRangef(0, 3);
                    SimplePolygon polygon = null;
                    if (chance < 1)
                    {
                        polygon = new Polygon1();
                    }
                    else if (chance < 2)
                    {
                        polygon = new Polygon2();
                    }
                    else
                    {
                        polygon = new Polygon3();
                    }

                    polygon.GlobalPosition = position;
                    return(polygon);
                }
            };

            AddChild(spawner);

            const int polygonCount = 10;

            for (int i = 0; i < polygonCount; ++i)
            {
                spawner.SpawnBody(MathUtils.RandVector2(0, size.x, 0, size.y));
            }
        }
Exemplo n.º 15
0
 protected void swapPolygon(SimplePolygon _polygon)
 {
     _polygon.Clear();
     _polygon.AddPoint(new Vector2(152, 115));
     _polygon.AddPoint(new Vector2(152, 103));
     // _polygon.AddPoint(new Vector2(164, 75));
     // _polygon.AddPoint(new Vector2(136, 60));
     // _polygon.AddPoint(new Vector2(136, 48));
     // _polygon.AddPoint(new Vector2(108, 25));
     _polygon.AddPoint(new Vector2(295, 26));//G
     // _polygon.AddPoint(new Vector2(282, 55));
     // _polygon.AddPoint(new Vector2(260, 60));
     _polygon.AddPoint(new Vector2(242, 70));
     _polygon.AddPoint(new Vector2(264, 88));
     _polygon.AddPoint(new Vector2(264, 114));
     _polygon.AddPoint(new Vector2(197, 127));
     _polygon.MakeCounterClockwise().LinkNeighbors();
 }
        private void Init()
        {
            Vector2 v1 = new Vector2(1, 1), v2 = new Vector2(3, 1), v3 = new Vector2(2, 3);
            var     vertices = new[] { v1, v2, v3 };
            var     polygon1 = new SimplePolygon(vertices);


            planner = new MotionPlanner(new[] { polygon1 });

            Vector2 start = new Vector2(0.5, 0.5),
                    goal  = new Vector2(3.5, 3.5);
            var path      = planner.CalculatePath(start, goal);

            DrawPolygon(polygon1);
            DrawPath(path);
            DrawBox();

            ResizeToFitContent();
        }
Exemplo n.º 17
0
        public void generateHull()
        {
            Hull.setConvexHull(dot_list);
            Hull.setConcaveHull(concavity, scaleFactor);
            SegementsLoop _loop = new SegementsLoop();

            for (int i = 0; i < Hull.hull_concave_edges.Count; i++)
            {
                Vector2 left  = new Vector2((float)Hull.hull_concave_edges[i].nodes[0].x, (float)Hull.hull_concave_edges[i].nodes[0].y);
                Vector2 right = new Vector2((float)Hull.hull_concave_edges[i].nodes[1].x, (float)Hull.hull_concave_edges[i].nodes[1].y);
                _loop.AddSegment(left, right);
            }
            var _pos3 = transform.position;
            var _pos2 = new Vector2((int)_pos3.x, (int)_pos3.y);

            m_polygon = _loop.ToPolygon().SetOriginal(_pos2).MakeCounterClockwise().LinkNeighbors();
            // m_polygon.ValidateLoop();
            Hull.Clear();
        }
        private void DrawPolygon(SimplePolygon polygon)
        {
            var pointCollection = new PointCollection();

            foreach (var vertex in polygon.Vertices)
            {
                var position = vertex.Position;
                pointCollection.Add(new Point(position.X, position.Y));
            }

            var polygonImage = new Polygon()
            {
                Fill            = Brushes.Pink,
                Stroke          = Brushes.Black,
                StrokeThickness = 3,
                Points          = pointCollection
            };

            mainCanvas.Children.Add(polygonImage);
        }
Exemplo n.º 19
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="offsetx"></param>
        /// <param name="offsety"></param>
        public void SelectedFeaturesPan(double offsetx, double offsety, FeatureCollection collection)
        {
            if (collection == null || collection.featureList.Count == 0)
            {
                return;
            }
            foreach (Feature feature in collection.featureList)
            {
                Geometry.Geometry geo = feature.geometry;
                switch (geo.geometryType)
                {
                case OSGeo.OGR.wkbGeometryType.wkbPoint:
                    PointD point = (PointD)geo;
                    point.X -= offsetx;
                    point.Y -= offsety;
                    break;

                case OSGeo.OGR.wkbGeometryType.wkbLineString:
                    SimplePolyline line = (SimplePolyline)geo;
                    foreach (PointD ringpoint in line.points)
                    {
                        ringpoint.X -= offsetx;
                        ringpoint.Y -= offsety;
                    }
                    break;

                case OSGeo.OGR.wkbGeometryType.wkbPolygon:
                    SimplePolygon simplegon = (SimplePolygon)geo;
                    foreach (SimplePolyline ring in simplegon.rings)
                    {
                        foreach (PointD ringpoint in ring.points)
                        {
                            ringpoint.X -= offsetx;
                            ringpoint.Y -= offsety;
                        }
                    }
                    break;
                }
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// 完成编辑并将当前编辑的图形作为要素加入列表
        /// </summary>
        public void Complete()
        {
            Feature tmpFeat = new Feature(this.maxFid + 1, this.editedLayer.featuresource.schema, null);

            switch (this.editedLayer.featuresource.schema.geometryType)
            {
            case OSGeo.OGR.wkbGeometryType.wkbPoint:
                if (this._inputTmp.Count > 0)
                {
                    tmpFeat.SetGeometry(this._inputTmp.ElementAt(0));
                }
                this._features.InsertFeature(tmpFeat);
                break;

            case OSGeo.OGR.wkbGeometryType.wkbLineString:
                if (this._inputTmp.Count < 2)
                {
                    break;
                }
                SimplePolyline tmpSL = new SimplePolyline(this._inputTmp);
                tmpFeat.SetGeometry(tmpSL);
                this._features.InsertFeature(tmpFeat);
                break;

            case OSGeo.OGR.wkbGeometryType.wkbPolygon:
                if (this._inputTmp.Count < 3)
                {
                    break;
                }
                List <SimplePolyline> tmpSLL = new List <SimplePolyline>();
                tmpSLL.Add(new SimplePolyline(this._inputTmp));
                SimplePolygon tmpSG = new SimplePolygon(tmpSLL);
                tmpFeat.SetGeometry(tmpSG);
                this._features.InsertFeature(tmpFeat);
                break;
            }
            //prepare for another input
            this._inputTmp = new List <PointD>();
        }
Exemplo n.º 21
0
        public void TestSimple()
        {
            var polylist = new List <Vector>
            {
                new Vector(0, 0),
                new Vector(4, 0),
                new Vector(3, 1),
                new Vector(5, 2),
                new Vector(1, 2),
                new Vector(2, 1)
            };

            Assert.IsTrue(SimplePolygon.FTestSimplePolygon(polylist));

            // Square
            polylist = new List <Vector>
            {
                new Vector(0, 0),
                new Vector(0, 1),
                new Vector(1, 1),
                new Vector(1, 0)
            };
            Assert.IsTrue(SimplePolygon.FTestSimplePolygon(polylist));

            // Almost the same as second case in TestNonSimple except we don't quite touch
            // the line
            polylist = new List <Vector>
            {
                new Vector(0, 0),
                new Vector(1, 1),
                // ReSharper disable once RedundantCast
                new Vector((T)0.01, 1),
                new Vector(1, 2),
                new Vector(0, 2)
            };
            Assert.IsTrue(SimplePolygon.FTestSimplePolygon(polylist));
        }
Exemplo n.º 22
0
        public Rectangle getEnvelop()
        {
            if (this.count == 0)
            {
                return(new Rectangle(0, 0, 0, 0));
            }
            Rectangle rect = new Rectangle(Utils.double_max, Utils.double_max, Utils.double_min, Utils.double_min);

            foreach (Feature feature in featureList)
            {
                OSGeo.OGR.wkbGeometryType featType = feature.geometry.geometryType;
                switch (featType)
                {
                case OSGeo.OGR.wkbGeometryType.wkbPoint:
                    PointD point = (PointD)feature.geometry;
                    if (point.X < rect.minX)
                    {
                        rect.minX = point.X;
                    }
                    if (point.X > rect.maxX)
                    {
                        rect.maxX = point.X;
                    }
                    if (point.Y < rect.minY)
                    {
                        rect.minY = point.Y;
                    }
                    if (point.Y > rect.maxY)
                    {
                        rect.maxY = point.Y;
                    }
                    break;

                case OSGeo.OGR.wkbGeometryType.wkbLineString:
                    SimplePolyline line = (SimplePolyline)feature.geometry;
                    if (line.minX < rect.minX)
                    {
                        rect.minX = line.minX;
                    }
                    if (line.maxX > rect.maxX)
                    {
                        rect.maxX = line.maxX;
                    }
                    if (line.minY < rect.minY)
                    {
                        rect.minY = line.minY;
                    }
                    if (line.maxY > rect.maxY)
                    {
                        rect.maxY = line.maxY;
                    }
                    break;

                case OSGeo.OGR.wkbGeometryType.wkbMultiLineString:
                    Polyline mline = (Polyline)feature.geometry;
                    if (mline.minX < rect.minX)
                    {
                        rect.minX = mline.minX;
                    }
                    if (mline.maxX > rect.maxX)
                    {
                        rect.maxX = mline.maxX;
                    }
                    if (mline.minY < rect.minY)
                    {
                        rect.minY = mline.minY;
                    }
                    if (mline.maxY > rect.maxY)
                    {
                        rect.maxY = mline.maxY;
                    }
                    break;

                case OSGeo.OGR.wkbGeometryType.wkbPolygon:
                    SimplePolygon polygon = (SimplePolygon)feature.geometry;
                    if (polygon.minX < rect.minX)
                    {
                        rect.minX = polygon.minX;
                    }
                    if (polygon.maxX > rect.maxX)
                    {
                        rect.maxX = polygon.maxX;
                    }
                    if (polygon.minY < rect.minY)
                    {
                        rect.minY = polygon.minY;
                    }
                    if (polygon.maxY > rect.maxY)
                    {
                        rect.maxY = polygon.maxY;
                    }
                    break;

                case OSGeo.OGR.wkbGeometryType.wkbMultiPolygon:
                    Polygon mpolygon = (Polygon)feature.geometry;
                    if (mpolygon.minX < rect.minX)
                    {
                        rect.minX = mpolygon.minX;
                    }
                    if (mpolygon.maxX > rect.maxX)
                    {
                        rect.maxX = mpolygon.maxX;
                    }
                    if (mpolygon.minY < rect.minY)
                    {
                        rect.minY = mpolygon.minY;
                    }
                    if (mpolygon.maxY > rect.maxY)
                    {
                        rect.maxY = mpolygon.maxY;
                    }
                    break;
                }
            }
            return(rect);
        }
Exemplo n.º 23
0
 void Start()
 {
     m_polygon = new SimplePolygon();
 }
Exemplo n.º 24
0
        public static string SimplePolygon2WKT(SimplePolygon geom)
        {
            string s = "POLYGON" + SimplePolygon2String(geom);

            return(s);
        }
Exemplo n.º 25
0
        /// <summary>
        /// 完成编辑并将当前图形作为一个子图形加入一个要素,只能加入此次编辑的要素中
        /// 这个过程中,被加入要素如果是SimplePolygon/line类型则会被转为MultiPolygon/line类型
        /// 如果被加入的是点要素,则只完成并新建一个点要素
        /// </summary>
        /// <param name="FID"></param>
        public void CompleteAndAddTo(int FID)
        {
            Feature tmpFeat;

            switch (this.editedLayer.featuresource.schema.geometryType)
            {
            case OSGeo.OGR.wkbGeometryType.wkbPoint:
                this.Complete();
                break;

            case OSGeo.OGR.wkbGeometryType.wkbLineString:
                if (this._inputTmp.Count < 2)
                {
                    this._inputTmp = new List <PointD>(); break;
                }
                SimplePolyline tmpSL = new SimplePolyline(this._inputTmp);
                tmpFeat = this._features.GetFeatureByID(FID);
                //if this id do not correspond to a feature, we'll give up the inputted data
                if (tmpFeat == null)
                {
                    this._inputTmp = new List <PointD>();
                    return;
                }
                Polyline tmpML;
                List <SimplePolyline> tmpSLs = new List <SimplePolyline>();
                switch (tmpFeat.geometry.geometryType)
                {
                case OSGeo.OGR.wkbGeometryType.wkbLineString:
                    tmpSLs.Add((SimplePolyline)tmpFeat.geometry);
                    break;

                case OSGeo.OGR.wkbGeometryType.wkbMultiLineString:
                    foreach (SimplePolyline pl in ((Polyline)tmpFeat.geometry).childPolylines)
                    {
                        tmpSLs.Add(pl);
                    }
                    break;
                }
                tmpSLs.Add(tmpSL);
                tmpML = new Polyline(tmpSLs);
                tmpFeat.SetGeometry(tmpML);
                break;

            case OSGeo.OGR.wkbGeometryType.wkbPolygon:
                if (this._inputTmp.Count < 3)
                {
                    this._inputTmp = new List <PointD>(); break;
                }
                List <SimplePolyline> tmpSLL = new List <SimplePolyline>();
                tmpSLL.Add(new SimplePolyline(this._inputTmp));
                SimplePolygon tmpSG = new SimplePolygon(tmpSLL);
                tmpFeat = this._features.GetFeatureByID(FID);
                //if this id do not correspond to a feature, we'll give up the inputted data
                if (tmpFeat == null)
                {
                    this._inputTmp = new List <PointD>();
                    return;
                }
                Polygon tmpMG;
                List <SimplePolygon> tmpSGs = new List <SimplePolygon>();
                switch (tmpFeat.geometry.geometryType)
                {
                case OSGeo.OGR.wkbGeometryType.wkbPolygon:
                    tmpSGs.Add((SimplePolygon)tmpFeat.geometry);
                    break;

                case OSGeo.OGR.wkbGeometryType.wkbMultiPolygon:
                    foreach (SimplePolygon pg in ((Polygon)tmpFeat.geometry).childPolygons)
                    {
                        tmpSGs.Add(pg);
                    }
                    break;
                }
                tmpSGs.Add(tmpSG);
                tmpMG = new Polygon(tmpSGs);
                tmpFeat.SetGeometry(tmpMG);
                //prepare for another input
                this._inputTmp = new List <PointD>();
                break;
            }
        }
 // Use this for initialization
 void Start()
 {
     coll = GetComponent <BoxCollider2D>();
     poly = SimplePolygon.boxCollider2DToSimplePolygon(coll);
 }
Exemplo n.º 27
0
    // Update is called once per frame
    public GameObject generate(int localSeed)
    {
        Random.InitState(localSeed);
        int height          = 0;
        int heightGenerated = 0;

        foreach (buildingStep step in steps)
        {
            step.initialise();
            height += (step.getFloors() * 2);
        }
        GameObject[] floors = new GameObject[steps.Length];
        for (int i = 0; i < steps.Length; i++)
        {
            if (steps[i].isPolygon)
            {
                Mesh polygon = SimplePolygon.polygon(steps[i].getRadius(), steps[i].getVertices());
                Mesh mesh;
                mesh = extrudeMesh(polygon, new Vector3(0, -height * 2, 0));
                mesh = moveMesh(mesh, new Vector3(
                                    Random.Range(-(gridGenerator.cellSize / 2 - steps[i].getRadius() * 2), gridGenerator.cellSize / 2 - steps[i].getRadius() * 2),
                                    -heightGenerated,
                                    Random.Range(-(gridGenerator.cellSize / 2 - steps[i].getRadius() * 2), gridGenerator.cellSize / 2 - steps[i].getRadius() * 2)
                                    ));
                mesh.RecalculateBounds();
                mesh.RecalculateNormals();
                mesh.RecalculateTangents();
                heightGenerated += steps[i].getFloors() * 2;
                floors[i]        = new GameObject("mesh", typeof(MeshFilter), typeof(MeshRenderer));
                floors[i].GetComponent <MeshFilter>().mesh = mesh;
                floors[i].transform.Rotate(new Vector3(0, steps[i].getRotation(), 0));
            }
            else
            {
                Mesh polygon = SimplePolygon.rectangle(steps[i].getWidth(), steps[i].getLength());
                Mesh mesh;
                mesh = extrudeMesh(polygon, new Vector3(0, -height * 2, 0));
                mesh = moveMesh(mesh, new Vector3(
                                    Random.Range(-(gridGenerator.cellSize / 2 - Mathf.Sqrt(steps[i].getLength() * steps[i].getLength() + steps[i].getWidth() * steps[i].getWidth())), gridGenerator.cellSize / 2 - Mathf.Sqrt(steps[i].getLength() * steps[i].getLength() + steps[i].getWidth() * steps[i].getWidth())),
                                    -heightGenerated,
                                    Random.Range(-(gridGenerator.cellSize / 2 - Mathf.Sqrt(steps[i].getLength() * steps[i].getLength() + steps[i].getWidth() * steps[i].getWidth())), gridGenerator.cellSize / 2 - Mathf.Sqrt(steps[i].getLength() * steps[i].getLength() + steps[i].getWidth() * steps[i].getWidth()))
                                    ));
                mesh.RecalculateBounds();
                mesh.RecalculateNormals();
                mesh.RecalculateTangents();
                heightGenerated += steps[i].getFloors() * 2;
                floors[i]        = new GameObject("mesh", typeof(MeshFilter), typeof(MeshRenderer));
                floors[i].GetComponent <MeshFilter>().mesh = mesh;
                floors[i].transform.Rotate(new Vector3(0, steps[i].getRotation(), 0));
            }
        }

        foreach (GameObject floor in floors)
        {
            for (int i = 0; i < floor.GetComponent <MeshFilter>().mesh.uv.Length / 2; i += 2)
            {
                floor.GetComponent <MeshFilter>().mesh.uv[i] = new Vector2(0, 0);
                floor.GetComponent <MeshFilter>().mesh.uv[i] = new Vector2(0, 1);
            }
            for (int i = floor.GetComponent <MeshFilter>().mesh.uv.Length / 2; i < floor.GetComponent <MeshFilter>().mesh.uv.Length; i += 2)
            {
                floor.GetComponent <MeshFilter>().mesh.uv[i] = new Vector2(1, 0);
                floor.GetComponent <MeshFilter>().mesh.uv[i] = new Vector2(1, 1);
            }
        }



        GameObject building = new GameObject("building", typeof(MeshFilter), typeof(MeshRenderer));

        CombMeshes(floors, building);
        building.GetComponent <MeshFilter>().mesh.RecalculateBounds();
        building.GetComponent <MeshFilter>().mesh.RecalculateNormals();
        building.GetComponent <MeshFilter>().mesh.RecalculateTangents();
        building.transform.position = new Vector3(0, building.transform.position.y + height, 0);
        building.GetComponent <Renderer>().material = material;
        building.AddComponent <MeshCollider>();

        //building.GetComponent<MeshFilter>().mesh.uv[0] = new Vector2(0, 0);
        //building.GetComponent<MeshFilter>().mesh.uv[building.GetComponent<MeshFilter>().mesh.uv.Length-1] = new Vector2(1, 1);

        return(building);
    }