Esempio n. 1
0
            public void RecordContact <TManifold>(BepuPhysicsComponent A, BepuPhysicsComponent B, ref TManifold manifold) where TManifold : struct, IContactManifold <TManifold>
            {
                // sanity checking
                if (A == null || B == null || manifold.Count == 0)
                {
                    return;
                }

                BepuRigidbodyComponent ar = (A as BepuRigidbodyComponent);
                BepuRigidbodyComponent br = (B as BepuRigidbodyComponent);

                // do we want to store this collision?
                if ((ar?.CollectCollisions ?? false))
                {
                    int index = Interlocked.Increment(ref ar.processingPhysicalContactCount) - 1;
                    if (index < ar.CurrentPhysicalContacts.Length)
                    {
                        ar.CurrentPhysicalContacts[index].A      = A;
                        ar.CurrentPhysicalContacts[index].B      = B;
                        ar.CurrentPhysicalContacts[index].Normal = BepuHelpers.ToXenko(manifold.SimpleGetNormal());
                        ar.CurrentPhysicalContacts[index].Offset = BepuHelpers.ToXenko(manifold.SimpleGetOffset());
                    }
                }
                if ((br?.CollectCollisions ?? false))
                {
                    int index = Interlocked.Increment(ref br.processingPhysicalContactCount) - 1;
                    if (index < br.CurrentPhysicalContacts.Length)
                    {
                        br.CurrentPhysicalContacts[index].A      = B;
                        br.CurrentPhysicalContacts[index].B      = A;
                        br.CurrentPhysicalContacts[index].Normal = -BepuHelpers.ToXenko(manifold.SimpleGetNormal());
                        br.CurrentPhysicalContacts[index].Offset = B.Position - (A.Position + BepuHelpers.ToXenko(manifold.SimpleGetOffset()));
                    }
                }
            }
Esempio n. 2
0
 public void OnPairCompleted <TManifold>(int pairId, ref TManifold manifold) where TManifold : struct, IContactManifold <TManifold>
 {
     if (manifold.Count > 0)
     {
         contactList.Add(new BepuContact()
         {
             Normal = BepuHelpers.ToXenko(manifold.SimpleGetNormal()),
             Offset = BepuHelpers.ToXenko(manifold.SimpleGetOffset())
         });
     }
 }
Esempio n. 3
0
        private static void PrepareDelegates()
        {
            CachedDelegates[(int)RB_ACTION.CcdMotionThreshold] = (rb) =>
            {
                rb.InternalBody.Collidable.Continuity = rb.bodyDescription.Collidable.Continuity;
            };

            CachedDelegates[(int)RB_ACTION.SleepThreshold] = (rb) =>
            {
                rb.InternalBody.Activity.SleepThreshold = rb.bodyDescription.Activity.SleepThreshold;
            };

            CachedDelegates[(int)RB_ACTION.UpdateInertia] = (rb) =>
            {
                rb.InternalBody.LocalInertia = rb.bodyDescription.LocalInertia;
            };

            CachedDelegates[(int)RB_ACTION.SpeculativeMargin] = (rb) =>
            {
                rb.InternalBody.Collidable.SpeculativeMargin = rb.bodyDescription.Collidable.SpeculativeMargin;
            };

            CachedDelegates[(int)RB_ACTION.ApplyImpulse] = (rb) =>
            {
                rb.IsActive = true;
                lock (rb.impulsesToApply)
                {
                    while (rb.impulsesToApply.Count > 0)
                    {
                        rb.InternalBody.ApplyLinearImpulse(BepuHelpers.ToBepu(rb.impulsesToApply.Dequeue()));
                    }

                    // update changed velocity
                    rb.bodyDescription.Velocity.Linear = rb.InternalBody.Velocity.Linear;
                }
            };

            CachedDelegates[(int)RB_ACTION.ApplyImpulseOffset] = (rb) =>
            {
                rb.IsActive = true;
                lock (rb.impulsesToApply)
                {
                    while (rb.impulsePairs.Count > 0)
                    {
                        Vector3[] pair = rb.impulsePairs.Dequeue();
                        rb.InternalBody.ApplyImpulse(BepuHelpers.ToBepu(pair[0]), BepuHelpers.ToBepu(pair[1]));
                    }

                    // update changed velocities
                    rb.bodyDescription.Velocity.Linear  = rb.InternalBody.Velocity.Linear;
                    rb.bodyDescription.Velocity.Angular = rb.InternalBody.Velocity.Angular;
                }
            };

            CachedDelegates[(int)RB_ACTION.ApplyTorqueImpulse] = (rb) =>
            {
                rb.IsActive = true;
                lock (rb.impulsesToApply)
                {
                    while (rb.torquesToApply.Count > 0)
                    {
                        rb.InternalBody.ApplyAngularImpulse(BepuHelpers.ToBepu(rb.torquesToApply.Dequeue()));
                    }

                    // update changed velocity
                    rb.bodyDescription.Velocity.Angular = rb.InternalBody.Velocity.Angular;
                }
            };

            CachedDelegates[(int)RB_ACTION.AngularVelocity] = rb =>
            {
                if (rb.bodyDescription.Velocity.Angular != System.Numerics.Vector3.Zero)
                {
                    rb.IsActive = true;
                }

                ref BodyVelocity v = ref rb.InternalBody.Velocity;

                v.Angular.X = rb.bodyDescription.Velocity.Angular.X;
                v.Angular.Y = rb.bodyDescription.Velocity.Angular.Y;
                v.Angular.Z = rb.bodyDescription.Velocity.Angular.Z;
            };