コード例 #1
0
ファイル: PolygonTools.cs プロジェクト: yuruyigit/TrueSync
        public static Vertices CreateCapsule(FP height, FP endRadius, int edges)
        {
            bool flag = endRadius >= height / 2;

            if (flag)
            {
                throw new ArgumentException("The radius must be lower than height / 2. Higher values of radius would create a circle, and not a half circle.", "endRadius");
            }
            return(PolygonTools.CreateCapsule(height, endRadius, edges, endRadius, edges));
        }
コード例 #2
0
        /// <summary>
        /// Creates a capsule.
        /// Note: Automatically decomposes the capsule if it contains too many vertices (controlled by Settings.MaxPolygonVertices)
        /// </summary>
        /// <returns></returns>
        public static Body CreateCapsule(World world, FP height, FP topRadius, int topEdges, FP bottomRadius, int bottomEdges, FP density, TSVector2 position, object userData = null)
        {
            Vertices verts = PolygonTools.CreateCapsule(height, topRadius, topEdges, bottomRadius, bottomEdges);

            Body body;

            //There are too many vertices in the capsule. We decompose it.
            if (verts.Count >= Settings.MaxPolygonVertices)
            {
                List <Vertices> vertList = Triangulate.ConvexPartition(verts, TriangulationAlgorithm.Earclip, true, FP.EN3);
                body          = CreateCompoundPolygon(world, vertList, density, userData);
                body.Position = position;

                return(body);
            }

            body          = CreatePolygon(world, verts, density, userData);
            body.Position = position;

            return(body);
        }
コード例 #3
0
ファイル: BodyFactory.cs プロジェクト: zentia/TrueSync
        public static Body CreateCapsule(World world, FP height, FP topRadius, int topEdges, FP bottomRadius, int bottomEdges, FP density, TSVector2 position, object userData = null)
        {
            Vertices vertices = PolygonTools.CreateCapsule(height, topRadius, topEdges, bottomRadius, bottomEdges);
            bool     flag     = vertices.Count >= Settings.MaxPolygonVertices;
            Body     result;

            if (flag)
            {
                List <Vertices> list = Triangulate.ConvexPartition(vertices, TriangulationAlgorithm.Earclip, true, FP.EN3);
                Body            body = BodyFactory.CreateCompoundPolygon(world, list, density, userData);
                body.Position = position;
                result        = body;
            }
            else
            {
                Body body = BodyFactory.CreatePolygon(world, vertices, density, userData);
                body.Position = position;
                result        = body;
            }
            return(result);
        }