Esempio n. 1
0
 public void Clone(Contact contact)
 {
     this.settings                  = contact.settings;
     this.body1                     = contact.body1;
     this.body2                     = contact.body2;
     this.normal                    = contact.normal;
     this.tangent                   = contact.tangent;
     this.realRelPos1               = contact.realRelPos1;
     this.realRelPos2               = contact.realRelPos2;
     this.relativePos1              = contact.relativePos1;
     this.relativePos2              = contact.relativePos2;
     this.p1                        = contact.p1;
     this.p2                        = contact.p2;
     this.accumulatedNormalImpulse  = contact.accumulatedNormalImpulse;
     this.accumulatedTangentImpulse = contact.accumulatedTangentImpulse;
     this.penetration               = contact.penetration;
     this.initialPen                = contact.initialPen;
     this.staticFriction            = contact.staticFriction;
     this.dynamicFriction           = contact.dynamicFriction;
     this.restitution               = contact.restitution;
     this.friction                  = contact.friction;
     this.massNormal                = contact.massNormal;
     this.massTangent               = contact.massTangent;
     this.restitutionBias           = contact.restitutionBias;
     this.newContact                = contact.newContact;
     this.treatBody1AsStatic        = contact.treatBody1AsStatic;
     this.treatBody2AsStatic        = contact.treatBody2AsStatic;
     this.body1IsMassPoint          = contact.body1IsMassPoint;
     this.body2IsMassPoint          = contact.body2IsMassPoint;
     this.lostSpeculativeBounce     = contact.lostSpeculativeBounce;
     this.speculativeVelocity       = contact.speculativeVelocity;
     this.lastTimeStep              = contact.lastTimeStep;
 }
Esempio n. 2
0
        public void Initialize(RigidBody body1, RigidBody body2, ref TSVector point1, ref TSVector point2, ref TSVector n, FP penetration, bool newContact, ContactSettings settings)
        {
            this.body1  = body1;
            this.body2  = body2;
            this.normal = n;
            this.normal.Normalize();
            this.p1         = point1;
            this.p2         = point2;
            this.newContact = newContact;
            TSVector.Subtract(ref this.p1, ref body1.position, out this.relativePos1);
            TSVector.Subtract(ref this.p2, ref body2.position, out this.relativePos2);
            TSVector.Transform(ref this.relativePos1, ref body1.invOrientation, out this.realRelPos1);
            TSVector.Transform(ref this.relativePos2, ref body2.invOrientation, out this.realRelPos2);
            this.initialPen       = penetration;
            this.penetration      = penetration;
            this.body1IsMassPoint = body1.isParticle;
            this.body2IsMassPoint = body2.isParticle;
            if (newContact)
            {
                this.treatBody1AsStatic        = body1.isStatic;
                this.treatBody2AsStatic        = body2.isStatic;
                this.accumulatedNormalImpulse  = FP.Zero;
                this.accumulatedTangentImpulse = FP.Zero;
                this.lostSpeculativeBounce     = FP.Zero;
                switch (settings.MaterialCoefficientMixing)
                {
                case ContactSettings.MaterialCoefficientMixingType.TakeMaximum:
                    this.staticFriction  = TSMath.Max(body1.material.staticFriction, body2.material.staticFriction);
                    this.dynamicFriction = TSMath.Max(body1.material.kineticFriction, body2.material.kineticFriction);
                    this.restitution     = TSMath.Max(body1.material.restitution, body2.material.restitution);
                    break;

                case ContactSettings.MaterialCoefficientMixingType.TakeMinimum:
                    this.staticFriction  = TSMath.Min(body1.material.staticFriction, body2.material.staticFriction);
                    this.dynamicFriction = TSMath.Min(body1.material.kineticFriction, body2.material.kineticFriction);
                    this.restitution     = TSMath.Min(body1.material.restitution, body2.material.restitution);
                    break;

                case ContactSettings.MaterialCoefficientMixingType.UseAverage:
                    this.staticFriction  = (body1.material.staticFriction + body2.material.staticFriction) / (2 * FP.One);
                    this.dynamicFriction = (body1.material.kineticFriction + body2.material.kineticFriction) / (2 * FP.One);
                    this.restitution     = (body1.material.restitution + body2.material.restitution) / (2 * FP.One);
                    break;
                }
            }
            this.settings = settings;
        }
Esempio n. 3
0
        public Contact AddContact(TSVector point1, TSVector point2, TSVector normal, FP penetration, ContactSettings contactSettings)
        {
            TSVector tSVector;

            TSVector.Subtract(ref point1, ref this.body1.position, out tSVector);
            ContactList obj = this.contactList;
            Contact     result;

            lock (obj)
            {
                bool flag = this.contactList.Count == 4;
                if (flag)
                {
                    int num = this.SortCachedPoints(ref tSVector, penetration);
                    this.ReplaceContact(ref point1, ref point2, ref normal, penetration, num, contactSettings);
                    result = null;
                }
                else
                {
                    int  num   = this.GetCacheEntry(ref tSVector, contactSettings.breakThreshold);
                    bool flag2 = num >= 0;
                    if (flag2)
                    {
                        this.ReplaceContact(ref point1, ref point2, ref normal, penetration, num, contactSettings);
                        result = null;
                    }
                    else
                    {
                        Contact @new = Contact.Pool.GetNew();
                        @new.Initialize(this.body1, this.body2, ref point1, ref point2, ref normal, penetration, true, contactSettings);
                        this.contactList.Add(@new);
                        result = @new;
                    }
                }
            }
            return(result);
        }
Esempio n. 4
0
        private void ReplaceContact(ref TSVector point1, ref TSVector point2, ref TSVector n, FP p, int index, ContactSettings contactSettings)
        {
            Contact contact = this.contactList[index];

            Debug.Assert(this.body1 == contact.body1, "Body1 and Body2 not consistent.");
            contact.Initialize(this.body1, this.body2, ref point1, ref point2, ref n, p, false, contactSettings);
        }