Ejemplo n.º 1
0
        /**
         *  @brief Create the internal shape used to represent a PolygonCollider.
         **/
        public override TrueSync.Physics2D.Shape[] CreateShapes()
        {
            if (_points == null || _points.Length == 0)
            {
                return(null);
            }


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

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

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

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

            return(result);
        }
Ejemplo n.º 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(TSVector2 pointA, TSVector2 pointB, Physics2D.BodySpecialSensor sensorType, int layerMask = UnityEngine.Physics.DefaultRaycastLayers)
        {
            TSVector2 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 TSVector2(pointA.x, pointA.y) - center);
            vertices.Add(new TSVector2(pointB.x, pointA.y) - center);
            vertices.Add(new TSVector2(pointB.x, pointB.y) - center);
            vertices.Add(new TSVector2(pointA.x, pointB.y) - center);

            return(OverlapGeneric(new Physics2D.PolygonShape(vertices, 1), center, sensorType, layerMask));
        }
        public static object _OverlapArea(TSVector2 i_PointA, TSVector2 i_PointB, Physics2D.BodySpecialSensor i_SensorType, int i_Mask)
        {
            TSVector2 center;

            center.x = (i_PointA.x + i_PointB.x) * FP.Half;
            center.y = (i_PointA.y + i_PointB.y) * FP.Half;

            Physics2D.Vertices vertices = new Physics2D.Vertices(4);
            vertices.Add(new TSVector2(i_PointA.x, i_PointA.y) - center);
            vertices.Add(new TSVector2(i_PointB.x, i_PointA.y) - center);
            vertices.Add(new TSVector2(i_PointB.x, i_PointB.y) - center);
            vertices.Add(new TSVector2(i_PointA.x, i_PointB.y) - center);

            return(OverlapGeneric(new Physics2D.PolygonShape(vertices, 1), center, i_SensorType, i_Mask));
        }
Ejemplo n.º 4
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.
         **/
        public static object _OverlapArea(TSVector2 pointA, TSVector2 pointB, Physics2D.BodySpecialSensor sensorType)
        {
            TSVector2 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 TSVector2(pointA.x, pointA.y) - center);
            vertices.Add(new TSVector2(pointB.x, pointA.y) - center);
            vertices.Add(new TSVector2(pointB.x, pointB.y) - center);
            vertices.Add(new TSVector2(pointA.x, pointB.y) - center);

            return(OverlapGeneric(new Physics2D.PolygonShape(vertices, 1), center, sensorType));
        }
Ejemplo n.º 5
0
        /**
         *  @brief Create the internal shape used to represent a TSBoxCollider.
         **/
        public override TrueSync.Physics2D.Shape CreateShape()
        {
            if (_points == null || _points.Length == 0)
            {
                return(null);
            }

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

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

            return(new TrueSync.Physics2D.PolygonShape(v, 1));
        }
Ejemplo n.º 6
0
        private static object _OverlapCapsule(TSVector2 point, TSVector2 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));
        }
        /**
         *  @brief Create the internal shape used to represent a TSBoxCollider.
         **/
        public override Physics2D.Shape[] CreateShapes()
        {
            if (m_Points == null || m_Points.Length == 0)
            {
                return(null);
            }

            Physics2D.Vertices v = new Physics2D.Vertices();
            for (int index = 0, length = m_Points.Length; index < length; index++)
            {
                v.Add(m_Points[index]);
            }

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

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

            return(result);
        }