コード例 #1
0
 // -----------------------
 // --- Package Methods ---
 // -----------------------
 public void Print()
 {
     for (int i = 0; i < m_List.Count; i++)
     {
         IPoly p = GetInnerPoly(i);
         Console.WriteLine("InnerPoly(" + i + ").hole=" + p.IsHole());
         for (int j = 0; j < p.PointCount; j++)
         {
             Console.WriteLine(p.GetX(j) + "  " + p.GetY(j));
         }
     }
 }
コード例 #2
0
ファイル: Junction.cs プロジェクト: dmoonfire/running-bomb
        /// <summary>
        /// Recursively process the polygon to attempt to find a
        /// single polygon element that could be added to the physics
        /// layer without any holes or additional physics.
        /// </summary>
        private void CreateJunctionPhysics(
			int depth, IPoly poly, RectangleF bounds)
        {
            // Ignore empty polygons
            if (poly.InnerPolygonCount == 0)
                return;

            // See if we are a solid polygon
            double areaDifference = bounds.Width * bounds.Height - poly.Area;

            if (poly.InnerPolygonCount == 1)
            {
                if (poly.IsHole())
                    // Don't add holes
                    return;

                if (poly.PointCount == 4 && areaDifference <= 0.1f)
                    // We appear to be at least mostly solid, drop it
                    return;
            }

            // If we have more than one polygon, split it
            if (poly.InnerPolygonCount > 1 ||
                bounds.Width > Constants.MaximumJunctionPhysicsBlock ||
                bounds.Height > Constants.MaximumJunctionPhysicsBlock)
            {
                // We split the polygon into quads and process each
                // one to add it recursively.
                CreateJunctionPhysics(depth + 1, poly, bounds, 0, 0);
                CreateJunctionPhysics(depth + 1, poly, bounds, 0, 1);
                CreateJunctionPhysics(depth + 1, poly, bounds, 1, 1);
                CreateJunctionPhysics(depth + 1, poly, bounds, 1, 0);
                return;
            }

            // We should never get a hole
            if (poly.IsHole())
            {
                // We shouldn't get this
                Log.Error("Got a top-level polygon hole");
                return;
            }

            // Create a polygon shape as vectors
            LinkedList<Vector2D> vectors = new LinkedList<Vector2D>();

            for (int i = 0; i < poly.PointCount; i++)
            {
                // Get the coordinates
                float x = (float) poly.GetX(i);
                float y = (float) poly.GetY(i);

                // Create the vector
                vectors.Add(new Vector2D(x, y));
            }

            // Convert it into a physics2d polygon shape. Making the
            // PolygonShape second parameter too small makes the game
            // basically unusable in terms of stage generation but
            // more accurate for impacts with the side.
            Vector2D [] array = vectors.ToArray();
            IShape ps = new PolygonShape(array, 5f);
            physicsShapes.Add(ps);
        }