Esempio n. 1
0
        public static bool OverlapCircle(Fix64Vec2 center, Fix64 radius, int mask, PShapeOverlapResult2D shapeOverlapResult)
        {
            if (!initialized)
            {
                Initialize();
            }

            int  count = 0;
            bool hit   = NativeParallel2D.CircleOverlap(internalWorld.IntPointer, center, radius, mask, _queryBodyIDs, ref count);

            shapeOverlapResult.count = count;

            for (int i = 0; i < count; i++)
            {
                UInt16 bodyID = _queryBodyIDs[i];
                if (bodySortedList.ContainsKey(bodyID))
                {
                    shapeOverlapResult.rigidbodies[i] = bodySortedList[bodyID].RigidBody;
                }
                else
                {
                    Debug.LogError($"Rigibody not found: {bodyID}");
                }
            }

            return(hit);
        }
Esempio n. 2
0
        public Fix64 Length()
        {
            Fix64 result = Fix64.zero;

            NativeParallel2D.Vec2Length64(this, ref result);
            return(result);
        }
Esempio n. 3
0
        public static bool CircleCast(Fix64Vec2 center, Fix64 radius, Fix64Vec2 translation, int mask, ref PShapecastHit2D shapecastHit2D)
        {
            if (!initialized)
            {
                Initialize();
            }

            UInt16    bodyID   = 0;
            Fix64Vec2 point    = Fix64Vec2.zero;
            Fix64Vec2 normal   = Fix64Vec2.zero;
            Fix64     fraction = Fix64.zero;
            bool      hit      = NativeParallel2D.CircleCast(center, radius, mask, translation, ref point, ref normal, ref fraction, out bodyID, internalWorld.IntPointer);

            if (hit)
            {
                shapecastHit2D.point    = point;
                shapecastHit2D.normal   = normal;
                shapecastHit2D.fraction = fraction;

                if (bodySortedList.ContainsKey(bodyID))
                {
                    shapecastHit2D.rigidbody = bodySortedList[bodyID].RigidBody;
                }
                else
                {
                    Debug.LogError($"Rigibody not found: {bodyID}");
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 4
0
 //common
 public static void Initialize()
 {
     ReadCollisionLayerMatrix();
     NativeParallel2D.Initialize();
     internalWorld = CreateWorld(gravity);
     initialized   = true;
 }
Esempio n. 5
0
        public static bool RayCast(Fix64Vec2 p1, Fix64Vec2 p2, int mask, out PRaycastHit2D raycastHit2D)
        {
            if (!initialized)
            {
                Initialize();
            }

            raycastHit2D = new PRaycastHit2D();
            UInt16    bodyID = 0;
            Fix64Vec2 point  = Fix64Vec2.zero;
            Fix64Vec2 normal = Fix64Vec2.zero;

            bool hit = NativeParallel2D.RayCast(p1, p2, mask, ref point, ref normal, out bodyID, internalWorld.IntPointer);

            if (hit)
            {
                raycastHit2D.point  = point;
                raycastHit2D.normal = normal;

                if (bodySortedList.ContainsKey(bodyID))
                {
                    raycastHit2D.rigidbody = bodySortedList[bodyID].RigidBody;
                }
                else
                {
                    Debug.LogError($"Rigibody not found: {bodyID}");
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 6
0
 public static void AppleEngineInternalState(PInternalState2D internalState)
 {
     for (int i = 0; i < internalState.contactCount; i++)
     {
         PContactExport2D export = internalState.contactExports[i];
         NativeParallel2D.AddExternalContactData(export);
     }
 }
Esempio n. 7
0
 public static void ReadNativeBody(PBody2D body2D)
 {
     if (!initialized)
     {
         Initialize();
     }
     NativeParallel2D.GetTransform(body2D.IntPointer, ref body2D.position, ref body2D.angle);
     NativeParallel2D.GetVelocity(body2D.IntPointer, ref body2D.linearVelocity, ref body2D.angularVelocity);
 }
Esempio n. 8
0
        public static void UpdateCapsule(PShape2D shape, PFixture2D fixture, Fix64Vec2 v1, Fix64Vec2 v2, Fix64 radius, Fix64Vec2 center, Fix64 angle)
        {
            if (!initialized)
            {
                Initialize();
            }

            NativeParallel2D.UpdateCapsule(shape.IntPointer, fixture.IntPointer, v1, v2, radius, center, angle);
        }
Esempio n. 9
0
        public static void ApplyForceToCenter(PBody2D body, Fix64Vec2 force)
        {
            if (!initialized)
            {
                Initialize();
            }

            NativeParallel2D.ApplyForceToCenter(body.IntPointer, force);
        }
Esempio n. 10
0
        public static void UpdateBodyVelocity(PBody2D body, Fix64Vec2 linearVelocity, Fix64 angularVelocity)
        {
            if (!initialized)
            {
                Initialize();
            }

            NativeParallel2D.UpdateBodyVelocity(body.IntPointer, linearVelocity, angularVelocity);
        }
Esempio n. 11
0
        public static void ApplyLinearImpulseToCenter(PBody2D body, Fix64Vec2 impulse)
        {
            if (!initialized)
            {
                Initialize();
            }

            NativeParallel2D.ApplyLinearImpulseToCenter(body.IntPointer, impulse);
        }
Esempio n. 12
0
        public static void SetFixtureProperties(PFixture2D fixture, bool isTrigger, Fix64 friction, Fix64 bounciness)
        {
            if (!initialized)
            {
                Initialize();
            }

            NativeParallel2D.SetFixtureProperties(fixture.IntPointer, isTrigger, friction, bounciness);
        }
Esempio n. 13
0
        public static void UpdateBodyTransForm(PBody2D body, Fix64Vec2 pos, Fix64 angle)
        {
            if (!initialized)
            {
                Initialize();
            }

            NativeParallel2D.UpdateBodyTransform(body.IntPointer, pos, angle);
        }
Esempio n. 14
0
        public static void UpdateBox(PShape2D shape, PFixture2D fixture, Fix64 width, Fix64 height, Fix64Vec2 center, Fix64 angle)
        {
            if (!initialized)
            {
                Initialize();
            }

            NativeParallel2D.UpdateBox(shape.IntPointer, fixture.IntPointer, width, height, center, angle);
        }
Esempio n. 15
0
        public static void ApplyAngularImpulse(PBody2D body, Fix64 impulse)
        {
            if (!initialized)
            {
                Initialize();
            }

            NativeParallel2D.ApplyAngularImpulse(body.IntPointer, impulse);
        }
Esempio n. 16
0
        public static void UpdateCircle(PShape2D shape, PFixture2D fixture, Fix64 radius, Fix64Vec2 center)
        {
            if (!initialized)
            {
                Initialize();
            }

            NativeParallel2D.UpdateCircle(shape.IntPointer, fixture.IntPointer, radius, center);
        }
Esempio n. 17
0
        public static void ApplyTorque(PBody2D body, Fix64 torque)
        {
            if (!initialized)
            {
                Initialize();
            }

            NativeParallel2D.ApplyTorque(body.IntPointer, torque);
        }
Esempio n. 18
0
        //2D fixture
        public static PFixture2D AddFixture(PBody2D body2D, PShape2D shape2D, Fix64 density)
        {
            if (!initialized)
            {
                Initialize();
            }

            IntPtr m_NativeObject = NativeParallel2D.AddFixtureToBody(body2D.IntPointer, shape2D.IntPointer, density);

            return(new PFixture2D(m_NativeObject));
        }
Esempio n. 19
0
        public static PShape2D GetShapeOfFixture(PFixture2D fixture2D)
        {
            if (!initialized)
            {
                Initialize();
            }

            IntPtr m_NativeObject = NativeParallel2D.GetShapeOfFixture(fixture2D.IntPointer);

            return(new PShape2D(m_NativeObject));
        }
Esempio n. 20
0
        public static PShape2D CreateBox(Fix64 width, Fix64 height, Fix64Vec2 center, Fix64 angle)
        {
            if (!initialized)
            {
                Initialize();
            }

            IntPtr m_NativeObject = NativeParallel2D.CreateBox(width, height, center, angle);

            return(new PShape2D(m_NativeObject));
        }
Esempio n. 21
0
        //2D shapes
        public static PShape2D CreateCircle(Fix64 radius, Fix64Vec2 center)
        {
            if (!initialized)
            {
                Initialize();
            }

            IntPtr m_NativeObject = NativeParallel2D.CreateCircle(radius, center);

            return(new PShape2D(m_NativeObject));
        }
Esempio n. 22
0
        public static PShape2D CreateCapsule(Fix64Vec2 v1, Fix64Vec2 v2, Fix64 radius, Fix64Vec2 center, Fix64 angle)
        {
            if (!initialized)
            {
                Initialize();
            }

            IntPtr m_NativeObject = NativeParallel2D.CreateCapsule(v1, v2, radius, center, angle);

            return(new PShape2D(m_NativeObject));
        }
Esempio n. 23
0
        public static void UpdatePolygon(PShape2D shape, PFixture2D fixture, Fix64Vec2[] verts, int count, Fix64Vec2 center, Fix64 angle)
        {
            if (!initialized)
            {
                Initialize();
            }

            ParallelVec2List parallelVec2List = new ParallelVec2List();

            parallelVec2List.count  = count;
            parallelVec2List.points = verts;
            NativeParallel2D.UpdatePolygon(shape.IntPointer, fixture.IntPointer, ref parallelVec2List, center, angle);
        }
Esempio n. 24
0
        public static void SetLayer(PFixture2D fixture, int layer, bool refilter)
        {
            if (!initialized)
            {
                Initialize();
            }

            int mask = masksByLayer[layer];
            //shift layer
            int shiftedLayer = 1 << layer;

            NativeParallel2D.SetLayer(fixture.IntPointer, shiftedLayer, mask, refilter);
        }
Esempio n. 25
0
        public static void DestoryBody(PBody2D body2D, IParallelRigidbody2D rigidBody2D)
        {
            if (!initialized)
            {
                Initialize();
            }

            if (bodySortedList.ContainsKey(body2D.BodyID))
            {
                bodySortedList.Remove(body2D.BodyID);
            }

            NativeParallel2D.DestroyBody(internalWorld.IntPointer, body2D.IntPointer);
        }
Esempio n. 26
0
        public static void UpdateBodyProperties(PBody2D body,
                                                int bodyType,
                                                Fix64 linearDamping,
                                                Fix64 angularDamping,
                                                bool fixedRotation,
                                                Fix64 gravityScale)
        {
            if (!initialized)
            {
                Initialize();
            }

            NativeParallel2D.UpdateBodyProperties(body.IntPointer, bodyType, linearDamping, angularDamping, fixedRotation, gravityScale);
        }
Esempio n. 27
0
        public static void Step(Fix64 time, int velocityIterations, int positionIterations)
        {
            if (!initialized)
            {
                Initialize();
            }

            ResetEnterContacts();
            ResetExitContacts();
            ResetAllContacts();


            NativeParallel2D.Step(internalWorld.IntPointer, time, velocityIterations, positionIterations);

            ExportFromEngine();
        }
Esempio n. 28
0
        //polygon
        public static PShape2D CreatePolygon(Fix64Vec2[] verts, int count, Fix64Vec2 center, Fix64 angle)
        {
            if (!initialized)
            {
                Initialize();
            }

            ParallelVec2List parallelVec2List = new ParallelVec2List();

            parallelVec2List.count  = count;
            parallelVec2List.points = verts;

            IntPtr m_NativeObject = NativeParallel2D.CreatePolygon(ref parallelVec2List, center, angle);

            return(new PShape2D(m_NativeObject));
        }
Esempio n. 29
0
        public static void GetContactDetail(IntPtr contactHandler, ref PContactPoints2D contactPoints2D)
        {
            if (!initialized)
            {
                Initialize();
            }

            contactPoints2D.contactPointCount = 0;


            contactPoints2D.contactPointCount = NativeParallel2D.GetContactDetail(
                contactHandler,
                ref contactPoints2D.point1,
                ref contactPoints2D.point2,
                ref contactPoints2D.penetration1,
                ref contactPoints2D.penetration2,
                ref contactPoints2D.contactNormal);
        }
Esempio n. 30
0
        // convex hull
        public static ParallelVec2List ConvexHull2D(Fix64Vec2[] verts, int count, int limit)
        {
            if (!initialized)
            {
                Initialize();
            }

            ParallelVec2List parallelVec2List = new ParallelVec2List();

            parallelVec2List.count  = count;
            parallelVec2List.points = verts;

            ParallelVec2List parallelVec2ListOutput = new ParallelVec2List();

            parallelVec2ListOutput.count  = count;
            parallelVec2ListOutput.points = new Fix64Vec2[count];

            NativeParallel2D.ConvexHull2D(ref parallelVec2List, ref parallelVec2ListOutput, limit);

            return(parallelVec2ListOutput);
        }