Beispiel #1
0
        public override PShape2D CreateShape(GameObject root)
        {
            Fix64Vec2 s = CalculateSize();

            if (s != Fix64Vec2.zero)
            {
                Fix64     angle  = Fix64.zero;
                Fix64Vec2 center = Fix64Vec2.zero;

                if (gameObject != root)
                {
                    angle  = Fix64.DegToRad(_pTransform.localEulerAngles.z);
                    center = (Fix64Vec2)_pTransform.localPosition;
                }

                return(Parallel2D.CreateBox(s.x, s.y, center, angle));
            }
            else
            {
                return(null);
            }
        }
        public override PShape2D CreateShape(GameObject root)
        {
            Fix64Vec2 s = CalculateSize();

            if (s != Fix64Vec2.zero)
            {
                Fix64     angle  = Fix64.zero;
                Fix64Vec2 center = Fix64Vec2.zero;

                if (gameObject != root)
                {
                    angle  = Fix64.DegToRad(_pTransform.localEulerAngles.z);
                    center = (Fix64Vec2)_pTransform.localPosition;
                }

                if (s == Fix64Vec2.one)
                {
                    return(Parallel2D.CreatePolygon(convexVerts, convexVertsCount, center, angle));
                }
                else
                {
                    Fix64Vec2[] scaled = new Fix64Vec2[convexVertsCount];

                    for (int i = 0; i < convexVertsCount; i++)
                    {
                        scaled[i] = convexVerts[i] * s;
                    }

                    return(Parallel2D.CreatePolygon(scaled, convexVertsCount, center, angle));
                }
            }
            else
            {
                return(null);
            }
        }
Beispiel #3
0
        public static void Step(Fix64 time, int velocityIterations, int positionIterations)
        {
            if (!initialized)
            {
                Initialize();
            }

            //using (new SProfiler($"==========STEP========"))
            {
                ResetEnterContacts();
                ResetExitContacts();
                ResetAllContacts();

                //using (new SProfiler($"Physics"))
                {
                    NativeParallel3D.Step(internalWorld.IntPointer, time, velocityIterations, positionIterations);
                }

                //using (new SProfiler($"Export"))
                {
                    ExportFromEngine();
                }
            }
        }
Beispiel #4
0
        //2D body
        public static PBody2D AddBody
            (int bodyType,
            Fix64Vec2 position,
            Fix64 angle,
            Fix64 linearDamping,
            Fix64 angularDamping,
            bool fixedRotation,
            Fix64 gravityScale,
            IParallelRigidbody2D rigidBody2D)
        {
            if (!initialized)
            {
                Initialize();
            }

            UInt16 bodyID = 0;

            IntPtr m_NativeObject = NativeParallel2D.CreateBody(
                internalWorld.IntPointer,
                bodyType,
                position,
                angle,
                linearDamping,
                angularDamping,
                fixedRotation,
                gravityScale,
                ref bodyID);

            PBody2D body2D = new PBody2D(m_NativeObject, bodyID, rigidBody2D as ParallelRigidbody2D, bodyExportSize);

            bodySortedList[bodyID] = body2D;

            ReadNativeBody(body2D);

            return(body2D);
        }
Beispiel #5
0
 //Fix64
 public static Fix64 Max(Fix64 a, Fix64 b)
 {
     return(a > b ? a : b);
 }
Beispiel #6
0
 public static Fix64 LerpUnClamped(Fix64 a, Fix64 b, Fix64 t)
 {
     return(a + (b - a) * t);
 }
Beispiel #7
0
 public static bool CircleCast(Fix64Vec2 center, Fix64 radius, Fix64Vec2 translation, ref PShapecastHit2D shapecastHit2D)
 {
     return(CircleCast(center, radius, translation, -1, ref shapecastHit2D));
 }
Beispiel #8
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));
        }
Beispiel #9
0
 internal static extern void Step(IntPtr worldHandle, Fix64 time, int velocityIterations, int positionIterations);
Beispiel #10
0
 internal static extern void GetTransform(IntPtr bodyHandle, ref Fix64Vec2 pos, ref Fix64 angle);
Beispiel #11
0
 internal static extern void GetVelocity(IntPtr bodyHandle, ref Fix64Vec2 linearVelocity, ref Fix64 rz);
Beispiel #12
0
 internal static extern void ApplyTorque(IntPtr bodyHandle, Fix64 torque);
Beispiel #13
0
 internal static extern void ApplyAngularImpulse(IntPtr bodyHandle, Fix64 impulse);
Beispiel #14
0
 internal static extern void UpdateBodyProperties(IntPtr bodyHandle,
                                                  int bodyType,
                                                  Fix64 linearDamping,
                                                  Fix64 angularDamping,
                                                  bool fixedRotation,
                                                  Fix64 gravityScale);
Beispiel #15
0
 internal static extern void UpdateBodyVelocity(IntPtr bodyHandle, Fix64Vec2 linearVelocity, Fix64 angularVelocity);
Beispiel #16
0
 internal static extern void UpdateBodyTransform(IntPtr bodyHandle, Fix64Vec2 position, Fix64 angle);
Beispiel #17
0
        public static void ExcuteUserCallbacks(Fix64 time)
        {
            //call contact exit callback

            PContact2DWrapper currentWrapper = _exitContactWrapperHead;

            for (int i = 0; i < _exitContactCount; i++)
            {
                PContact2D contact = currentWrapper.contact;

                PBody2D body1 = bodySortedList[contact.Body1ID];
                PBody2D body2 = bodySortedList[contact.Body2ID];

                if (contact.IsTrigger)
                {
                    body1.RigidBody.OnParallelTriggerExit(body2.RigidBody);
                    body2.RigidBody.OnParallelTriggerExit(body1.RigidBody);
                }
                else
                {
                    _tempCollision.SetContact(contact, body2.RigidBody);
                    body1.RigidBody.OnParallelCollisionExit(_tempCollision);

                    _tempCollision.SetContact(contact, body1.RigidBody);
                    body2.RigidBody.OnParallelCollisionExit(_tempCollision);
                }

                contact.state  = ContactState.Inactive;
                currentWrapper = currentWrapper.next;
            }

            //call contact stay callback
            currentWrapper = _allContactWrapperHead;

            for (int i = 0; i < _allContactCount; i++)
            {
                PContact2D contact = currentWrapper.contact;

                if (contact.state == ContactState.Active)
                {
                    PBody2D body1 = bodySortedList[contact.Body1ID];
                    PBody2D body2 = bodySortedList[contact.Body2ID];

                    if (contact.IsTrigger)
                    {
                        body1.RigidBody.OnParallelTriggerStay(body2.RigidBody);
                        body2.RigidBody.OnParallelTriggerStay(body1.RigidBody);
                    }
                    else
                    {
                        _tempCollision.SetContact(contact, body2.RigidBody);
                        body1.RigidBody.OnParallelCollisionStay(_tempCollision);

                        _tempCollision.SetContact(contact, body1.RigidBody);
                        body2.RigidBody.OnParallelCollisionStay(_tempCollision);
                    }
                }

                currentWrapper = currentWrapper.next;
            }

            //call contact enter callback
            currentWrapper = _enterContactWrapperHead;

            for (int i = 0; i < _enterContactCount; i++)
            {
                PContact2D contact = currentWrapper.contact;
                PBody2D    body1   = bodySortedList[contact.Body1ID];
                PBody2D    body2   = bodySortedList[contact.Body2ID];

                if (contact.IsTrigger)
                {
                    body1.RigidBody.OnParallelTriggerEnter(body2.RigidBody);
                    body2.RigidBody.OnParallelTriggerEnter(body1.RigidBody);
                }
                else
                {
                    _tempCollision.SetContact(contact, body2.RigidBody);
                    body1.RigidBody.OnParallelCollisionEnter(_tempCollision);

                    _tempCollision.SetContact(contact, body1.RigidBody);
                    body2.RigidBody.OnParallelCollisionEnter(_tempCollision);
                }

                contact.state  = ContactState.Active;
                currentWrapper = currentWrapper.next;
            }
        }
Beispiel #18
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));
        }
Beispiel #19
0
        public static void SetFixtureProperties(PFixture2D fixture, bool isTrigger, Fix64 friction, Fix64 bounciness)
        {
            if (!initialized)
            {
                Initialize();
            }

            NativeParallel2D.SetFixtureProperties(fixture.IntPointer, isTrigger, friction, bounciness);
        }
Beispiel #20
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));
        }
Beispiel #21
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);
        }
Beispiel #22
0
 internal static extern void Vec2Length64(Fix64Vec2 a, ref Fix64 result);
Beispiel #23
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);
        }
Beispiel #24
0
 public static Fix64 Max(Fix64 a, Fix64 b, Fix64 c)
 {
     return(Max(a, Max(b, c)));
 }
Beispiel #25
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);
        }
Beispiel #26
0
 public static Fix64 Min(Fix64 a, Fix64 b)
 {
     return(a < b ? a : b);
 }
Beispiel #27
0
        public static void UpdateBodyVelocity(PBody2D body, Fix64Vec2 linearVelocity, Fix64 angularVelocity)
        {
            if (!initialized)
            {
                Initialize();
            }

            NativeParallel2D.UpdateBodyVelocity(body.IntPointer, linearVelocity, angularVelocity);
        }
Beispiel #28
0
 public static Fix64 Clamp(Fix64 a, Fix64 low, Fix64 high)
 {
     return(Max(low, Min(a, high)));
 }
Beispiel #29
0
 //overlap
 public static bool OverlapCircle(Fix64Vec2 center, Fix64 radius, PShapeOverlapResult2D shapeOverlapResult)
 {
     return(OverlapCircle(center, radius, -1, shapeOverlapResult));
 }
Beispiel #30
0
 public static Fix64 Lerp(Fix64 a, Fix64 b, Fix64 t)
 {
     t = Clamp(t, Fix64.zero, Fix64.one);
     return(a + (b - a) * t);
 }