private void OnDrawGizmos()
        {
            Line3    line         = CreateLine3(Line);
            Plane3   polygonPlane = CreatePlane3(PolygonPlane);
            Polygon3 polygon      = new Polygon3(PolygonPoints.Length, polygonPlane);

            for (int i = 0; i < PolygonPoints.Length; ++i)
            {
                polygon.SetVertexProjected(i, PolygonPoints[i].position);
            }
            polygon.UpdateEdges();

            Line3Polygon3Intr info;
            bool find = Intersection.FindLine3Polygon3(ref line, polygon, out info);

            FiguresColor();
            DrawPolygon(polygon);
            DrawLine(ref line);

            if (find)
            {
                ResultsColor();
                DrawPoint(info.Point);
            }

            LogInfo(info.IntersectionType);
        }
 protected void DrawPolygon(Polygon3 polygon)
 {
     for (int i0 = 0, i1 = polygon.VertexCount - 1; i0 < polygon.VertexCount; i1 = i0, ++i0)
     {
         Gizmos.DrawLine(polygon[i0], polygon[i1]);
     }
 }
Beispiel #3
0
 public static Polygon3 Transform(this Polygon3 polygon, Func <Vector3, Vector3> transformFn)
 {
     return(new Polygon3
     {
         Points = polygon.Points.Select(transformFn).ToArray()
     });
 }
Beispiel #4
0
 public static Shape ToShape(this Polygon3 polygon)
 {
     return(new Shape
     {
         Points3 = polygon.Points,
         Convexes = new int[][] { polygon.Points.Index().ToArray() }
     });
 }
Beispiel #5
0
 private static void EnqueueAdjacentFacets(Polygon3 adjacentFacet, Queue <Polygon3> adjacentQueue, Point3Tree <List <Polygon3> > edgeFacetIndex, Point3Tree <bool> facetVisitedIndex)
 {
     foreach (Polygon3 facet in GetAdjacentFacets(adjacentFacet, edgeFacetIndex))
     {
         if (!facetVisitedIndex[facet.Centroid])
         {
             adjacentQueue.Enqueue(facet);
             facetVisitedIndex[facet.Centroid] = true;
         }
     }
 }
Beispiel #6
0
        private void OnDrawGizmos()
        {
            Plane3 plane = CreatePlane3(Plane);

            Polygon3 polygon = new Polygon3(Points.Length, plane);

            for (int i = 0; i < Points.Length; ++i)
            {
                polygon.SetVertexProjected(i, Points[i].position);
            }
            polygon.UpdateEdges();

            DrawPolygon(polygon);
        }
Beispiel #7
0
        private static List <Polygon3> GetAdjacentFacets(Polygon3 facet, Point3Tree <List <Polygon3> > edgeFacetIndex)
        {
            List <Polygon3> adjacentFacets = new List <Polygon3>(3);

            foreach (Point3 edgeMidPoint in facet.EdgeMidPoints)
            {
                foreach (Polygon3 adjacentFacet in edgeFacetIndex[edgeMidPoint])
                {
                    if (adjacentFacet != facet)
                    {
                        adjacentFacets.Add(adjacentFacet);
                    }
                }
            }
            return(adjacentFacets);
        }
Beispiel #8
0
        private static Polygon3[] GrowUnsupportedRegion(Polygon3 unsupportedFacet, Point3Tree <List <Polygon3> > edgeFacetIndex, Point3Tree <bool> facetVisitedIndex)
        {
            Queue <Polygon3> adjacentQueue = new Queue <Polygon3>();

            adjacentQueue.Enqueue(unsupportedFacet);
            facetVisitedIndex[unsupportedFacet.Centroid] = true;

            List <Polygon3> unsupportedRegion = new List <Polygon3>();

            while (adjacentQueue.Count != 0)
            {
                Polygon3 adjacentFacet = adjacentQueue.Dequeue();
                unsupportedRegion.Add(adjacentFacet);
                EnqueueAdjacentFacets(adjacentFacet, adjacentQueue, edgeFacetIndex, facetVisitedIndex);
            }
            return(unsupportedRegion.ToArray());
        }
Beispiel #9
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));
            }
        }
Beispiel #10
0
        /// <summary>
        /// Load existing unknown
        /// </summary>
        /// <param name="buffer"></param>
        public void Load(byte[] buffer)
        {
            try
            {
                using (BinaryReader b = new BinaryReader(new MemoryStream(buffer)))
                {
                    var nfpCount = b.ReadInt32();

                    for (int i = 0; i < nfpCount; i++)
                    {
                        var nfp = new RecordNfp();
                        nfp.Id = b.ReadInt32();
                        var polygonCount = b.ReadInt32();

                        for (int p = 0; p < polygonCount; p++)
                        {
                            var polygon  = new Polygon3();
                            var pointNum = b.ReadInt32();

                            for (int t = 0; t < pointNum; t++)
                            {
                                var point = new K3DPosition(b.ReadSingle(), b.ReadSingle(), b.ReadSingle());
                                polygon.Points.Add(point);
                            }

                            nfp.Polygons.Add(polygon);
                        }

                        var DescriptionCount = b.ReadInt32();
                        nfp.Description = Encoding.Default.GetString(b.ReadBytes(DescriptionCount));

                        Records.Add(nfp);
                    }
                }

                XLog.WriteLine(Levels.Good, "Ok");
            }
            catch (Exception exception)
            {
                Blank();
                XLog.WriteLine(Levels.Error, "Failed");
                XLog.WriteLine(Levels.Fatal, "NfpManager::Load<Exception> -> {0}", exception);
            }
        }
        public override Polygon3[] Read(string filePath)
        {
            int facetCount = GetFacetCount(filePath);

            using (BinaryReader reader = new BinaryReader(File.OpenRead(filePath))) {
                reader.ReadBytes(84);
                Polygon3[] facets = new Polygon3[facetCount];
                for (int f = 0; f != facetCount; f++)
                {
                    Vector3  normal   = new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                    Point3[] vertices = new Point3[3];
                    for (int v = 0; v != vertices.Length; v++)
                    {
                        vertices[v] = new Point3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                    }
                    facets[f] = new Polygon3(normal, vertices);
                    reader.ReadBytes(2);
                }
                return(facets);
            }
        }
Beispiel #12
0
 public static Polygon3 Move(this Polygon3 polygon, Vector3 size)
 {
     return(polygon.Transform(p => p + size));
 }
Beispiel #13
0
 public void AddPolygon3(Polygon3 item)
 {
     p.Add(item);
 }
Beispiel #14
0
 private static bool DoesFacetNeedSupported(Polygon3 facet, double criticalAngle)
 {
     return(AngleConverter.RadToDeg(Vector3.CalculateAngle(facet.Normal, XYNormal)) > 180 - criticalAngle);
 }
Beispiel #15
0
 public static Polygon3 Mult(this Polygon3 polygon, double k)
 {
     return(polygon.Transform(p => p * k));
 }
Beispiel #16
0
 public static Polygon3 Scale(this Polygon3 polygon, Vector3 aSize, Vector3 bSize)
 {
     return(polygon.Transform(p => p.Scale(aSize, bSize)));
 }
Beispiel #17
0
 public static Polygon3 ScaleToOne(this Polygon3 polygon, Vector3 aSize)
 {
     return(polygon.Scale(aSize, One3));
 }
Beispiel #18
0
 public static Polygon3 Scale(this Polygon3 polygon, Vector3 bSize)
 {
     return(polygon.Scale(One3, bSize));
 }
Beispiel #19
0
    public void AddBuildings(int x, int y)
    {
        string filePath;
        float  centerX = AreaSize * x;
        float  centerY = AreaSize * y;

        filePath = Application.dataPath + "/json/mapinfo_" + x.ToString() + "x" + y.ToString() + ".json";

        if (!File.Exists(filePath))
        {
            return;
        }

        JsonController mapinfoJson = GetComponent <JsonController>();

        mapinfo = mapinfoJson.LoadFromJson(filePath);

        for (int i = 0; i < mapinfo.Count(); i++)
        {
            GameObject buildObj = (GameObject)Instantiate(
                buildprefab,
                new Vector3(0, 0, 0),
                Quaternion.identity
                );
            GameObject emptyObject = new GameObject();
            emptyObject.transform.rotation   = transform.rotation;
            emptyObject.transform.parent     = transform;
            emptyObject.transform.localScale = new Vector3(0.001f, 10, 0.001f);
            buildObj.transform.parent        = emptyObject.transform;

            BuildInfo build = mapinfo.List[i];

            float minX = 10000, maxX = -10000;
            float minY = 10000, maxY = -10000;
            float minZ = 10000, maxZ = -10000;


            for (int j = 0; j < build.CountVertex3(); j++)
            {
                if (minX > build.getVertex3[j].x)
                {
                    minX = build.getVertex3[j].x;
                }
                if (maxX < build.getVertex3[j].x)
                {
                    maxX = build.getVertex3[j].x;
                }
                if (minY > build.getVertex3[j].y)
                {
                    minY = build.getVertex3[j].y;
                }
                if (maxY < build.getVertex3[j].y)
                {
                    maxY = build.getVertex3[j].y;
                }
                if (minZ > build.getVertex3[j].z)
                {
                    minZ = build.getVertex3[j].z;
                }
                if (maxZ < build.getVertex3[j].z)
                {
                    maxZ = build.getVertex3[j].z;
                }
            }

            float sizeX = maxX - minX;
            float sizeY = maxY - minY;
            float sizeZ = maxZ - minZ;
            buildObj.transform.localScale    = new Vector3(sizeX, sizeY, sizeZ);
            buildObj.transform.localPosition = new Vector3(minX - centerX + (sizeX / 2), (maxY + minY) / 2, minZ - centerY + (sizeZ / 2));

            var vertices  = new List <Vector3>();
            var triangles = new List <int>();

            for (int j = 0; j < build.CountVertex3(); j++)
            {
                vertices.Add(new Vector3(build.getVertex3[j].x, build.getVertex3[j].y, build.getVertex3[j].z));
            }

            for (int k = 0; k < build.CountPolygon3(); k++)
            {
                Polygon3 poly = build.getPolygon3[k];
                triangles.Add(poly.i1);
                triangles.Add(poly.i2);
                triangles.Add(poly.i3);
            }

            BuildScript bs = buildObj.GetComponent <BuildScript>();
            bs.SetPosition((int)AreaSize, new Vector3(minX - centerX + (sizeX / 2), maxY, minZ - centerY + (sizeZ / 2)), new Vector3(minX + (sizeX / 2), maxY, minZ + (sizeZ / 2)));
            bs.MakeObject(vertices, triangles);
        }

        transform.position = new Vector3(x * AreaSize, 0, y * AreaSize);
    }