From 14bfb0aca4160d8323760ccb8d77f0bbc37fc0a3 Mon Sep 17 00:00:00 2001 From: Daniel Chappuis Date: Mon, 17 Oct 2016 22:41:33 +0200 Subject: [PATCH] Some optimizations in contact solver --- src/collision/ContactManifold.h | 6 ++-- src/engine/ContactSolver.h | 58 ++++++++++++--------------------- 2 files changed, 23 insertions(+), 41 deletions(-) diff --git a/src/collision/ContactManifold.h b/src/collision/ContactManifold.h index 2f77e9b2..c36c1476 100644 --- a/src/collision/ContactManifold.h +++ b/src/collision/ContactManifold.h @@ -102,7 +102,7 @@ class ContactManifold { short int mNormalDirectionId; /// Number of contacts in the cache - uint mNbContactPoints; + int8 mNbContactPoints; /// First friction vector of the contact manifold Vector3 mFrictionVector1; @@ -187,7 +187,7 @@ class ContactManifold { void clear(); /// Return the number of contact points in the manifold - uint getNbContactPoints() const; + int8 getNbContactPoints() const; /// Return the first friction vector at the center of the contact manifold const Vector3& getFrictionVector1() const; @@ -264,7 +264,7 @@ inline short int ContactManifold::getNormalDirectionId() const { } // Return the number of contact points in the manifold -inline uint ContactManifold::getNbContactPoints() const { +inline int8 ContactManifold::getNbContactPoints() const { return mNbContactPoints; } diff --git a/src/engine/ContactSolver.h b/src/engine/ContactSolver.h index becd5529..089d8b53 100644 --- a/src/engine/ContactSolver.h +++ b/src/engine/ContactSolver.h @@ -119,11 +119,8 @@ class ContactSolver { */ struct ContactPointSolver { - /// Accumulated normal impulse - decimal penetrationImpulse; - - /// Accumulated split impulse for penetration correction - decimal penetrationSplitImpulse; + /// Pointer to the external contact + ContactPoint* externalContact; /// Normal vector of the contact Vector3 normal; @@ -134,41 +131,26 @@ class ContactSolver { /// Vector from the body 2 center to the contact point Vector3 r2; - /// Cross product of r1 with 1st friction vector - Vector3 r1CrossT1; - - /// Cross product of r1 with 2nd friction vector - Vector3 r1CrossT2; - - /// Cross product of r2 with 1st friction vector - Vector3 r2CrossT1; - - /// Cross product of r2 with 2nd friction vector - Vector3 r2CrossT2; - - /// Cross product of r1 with the contact normal - Vector3 r1CrossN; - - /// Cross product of r2 with the contact normal - Vector3 r2CrossN; - /// Penetration depth decimal penetrationDepth; /// Velocity restitution bias decimal restitutionBias; + /// Accumulated normal impulse + decimal penetrationImpulse; + + /// Accumulated split impulse for penetration correction + decimal penetrationSplitImpulse; + /// Inverse of the matrix K for the penenetration decimal inversePenetrationMass; - /// Inverse of the matrix K for the 1st friction - decimal inverseFriction1Mass; + /// Cross product of r1 with the contact normal + Vector3 r1CrossN; - /// Inverse of the matrix K for the 2nd friction - decimal inverseFriction2Mass; - - /// Pointer to the external contact - ContactPoint* externalContact; + /// Cross product of r2 with the contact normal + Vector3 r2CrossN; /// True if the contact was existing last time step bool isRestingContact; @@ -181,11 +163,14 @@ class ContactSolver { */ struct ContactManifoldSolver { + /// Pointer to the external contact manifold + ContactManifold* externalContactManifold; + /// Index of body 1 in the constraint solver - uint indexBody1; + int32 indexBody1; /// Index of body 2 in the constraint solver - uint indexBody2; + int32 indexBody2; /// Inverse of the mass of body 1 decimal massInverseBody1; @@ -199,18 +184,12 @@ class ContactSolver { /// Inverse inertia tensor of body 2 Matrix3x3 inverseInertiaTensorBody2; - /// Number of contact points - short int nbContacts; - /// Mix friction coefficient for the two bodies decimal frictionCoefficient; /// Rolling resistance factor between the two bodies decimal rollingResistanceFactor; - /// Pointer to the external contact manifold - ContactManifold* externalContactManifold; - // - Variables used when friction constraints are apply at the center of the manifold-// /// Average normal vector of the contact manifold @@ -275,6 +254,9 @@ class ContactSolver { /// Rolling resistance impulse Vector3 rollingResistanceImpulse; + + /// Number of contact points + int8 nbContacts; }; // -------------------- Constants --------------------- //