Пример #1
0
        /**
         *  @brief Create the internal shape used to represent a PolygonCollider.
         **/
        public override KBEngine.Physics2D.Shape[] CreateShapes()
        {
            if (_points == null || _points.Length == 0)
            {
                return(null);
            }


            FPVector2 lossy2D = new FPVector2(lossyScale.x, lossyScale.y);

            KBEngine.Physics2D.Vertices v = new Physics2D.Vertices();
            for (int index = 0, length = _points.Length; index < length; index++)
            {
                v.Add(FPVector2.Scale(_points[index], lossy2D));
            }

            List <KBEngine.Physics2D.Vertices> convexShapeVs = KBEngine.Physics2D.BayazitDecomposer.ConvexPartition(v);

            KBEngine.Physics2D.Shape[] result = new Physics2D.Shape[convexShapeVs.Count];
            for (int index = 0, length = result.Length; index < length; index++)
            {
                result[index] = new KBEngine.Physics2D.PolygonShape(convexShapeVs[index], 1);
            }

            return(result);
        }
Пример #2
0
        /**
         *  @brief Returns the first {@link TSCollider2D} within a rectangular area. Returns null if there is none.
         *
         *  @param pointA Top-left corner of the rectangle.
         *  @param radius Bottom-right corner of the rectangle.
         *  @param layerMask Unity's layer mask to filter objects.
         **/
        public static object _OverlapArea(FPVector2 pointA, FPVector2 pointB, Physics2D.BodySpecialSensor sensorType, int layerMask = UnityEngine.Physics.DefaultRaycastLayers)
        {
            FPVector2 center;

            center.x = (pointA.x + pointB.x) * FP.Half;
            center.y = (pointA.y + pointB.y) * FP.Half;

            Physics2D.Vertices vertices = new Physics2D.Vertices(4);
            vertices.Add(new FPVector2(pointA.x, pointA.y) - center);
            vertices.Add(new FPVector2(pointB.x, pointA.y) - center);
            vertices.Add(new FPVector2(pointB.x, pointB.y) - center);
            vertices.Add(new FPVector2(pointA.x, pointB.y) - center);

            return(OverlapGeneric(new Physics2D.PolygonShape(vertices, 1), center, sensorType, layerMask));
        }
Пример #3
0
        private static object _OverlapCapsule(FPVector2 point, FPVector2 size, TSCapsuleDirection2D direction, FP angle, Physics2D.BodySpecialSensor sensorType, int layerMask = UnityEngine.Physics.DefaultRaycastLayers)
        {
            if (direction == TSCapsuleDirection2D.HORIZONTAL)
            {
                FP aux = size.y;
                size.y = size.x;
                size.x = aux;

                angle += 90;
            }

            FP radius = size.x * FP.Half;

            Physics2D.Vertices capVerts = Physics2D.PolygonTools.CreateCapsule(size.y, radius, 8, radius, 8);

            Physics2D.PolygonTools.TransformVertices(capVerts, point, angle * FP.Deg2Rad * -1);

            return(OverlapGeneric(new Physics2D.PolygonShape(capVerts, 1), point, sensorType, layerMask));
        }