diff --git a/src/collision/CollisionDetection.cpp b/src/collision/CollisionDetection.cpp index 9c16ac02..f4e911e8 100644 --- a/src/collision/CollisionDetection.cpp +++ b/src/collision/CollisionDetection.cpp @@ -728,8 +728,8 @@ void CollisionDetection::initContactsWithPreviousOnes() { assert(m < mCurrentContactManifolds->size()); ContactManifold& currentContactManifold = (*mCurrentContactManifolds)[m]; - assert(currentContactManifold.mNbContactPoints > 0); - ContactPoint& currentContactPoint = (*mCurrentContactPoints)[currentContactManifold.mContactPointsIndex]; + assert(currentContactManifold.nbContactPoints > 0); + ContactPoint& currentContactPoint = (*mCurrentContactPoints)[currentContactManifold.contactPointsIndex]; const Vector3& currentContactPointNormal = currentContactPoint.getNormal(); // Find a similar contact manifold among the contact manifolds from the previous frame (for warmstarting) @@ -738,19 +738,19 @@ void CollisionDetection::initContactsWithPreviousOnes() { for (uint p=previousContactManifoldIndex; p < previousContactManifoldIndex + previousNbContactManifolds; p++) { ContactManifold& previousContactManifold = (*mPreviousContactManifolds)[p]; - assert(previousContactManifold.mNbContactPoints > 0); - ContactPoint& previousContactPoint = (*mPreviousContactPoints)[previousContactManifold.mContactPointsIndex]; + assert(previousContactManifold.nbContactPoints > 0); + ContactPoint& previousContactPoint = (*mPreviousContactPoints)[previousContactManifold.contactPointsIndex]; // If the previous contact manifold has a similar contact normal with the current manifold if (previousContactPoint.getNormal().dot(currentContactPointNormal) >= mWorld->mConfig.cosAngleSimilarContactManifold) { // Transfer data from the previous contact manifold to the current one - currentContactManifold.mFrictionVector1 = previousContactManifold.mFrictionVector1; - currentContactManifold.mFrictionVector2 = previousContactManifold.mFrictionVector2; - currentContactManifold.mFrictionImpulse1 = previousContactManifold.mFrictionImpulse1; - currentContactManifold.mFrictionImpulse2 = previousContactManifold.mFrictionImpulse2; - currentContactManifold.mFrictionTwistImpulse = previousContactManifold.mFrictionTwistImpulse; - currentContactManifold.mRollingResistanceImpulse = previousContactManifold.mRollingResistanceImpulse; + currentContactManifold.frictionVector1 = previousContactManifold.frictionVector1; + currentContactManifold.frictionVector2 = previousContactManifold.frictionVector2; + currentContactManifold.frictionImpulse1 = previousContactManifold.frictionImpulse1; + currentContactManifold.frictionImpulse2 = previousContactManifold.frictionImpulse2; + currentContactManifold.frictionTwistImpulse = previousContactManifold.frictionTwistImpulse; + currentContactManifold.rollingResistanceImpulse = previousContactManifold.rollingResistanceImpulse; break; } diff --git a/src/collision/ContactManifold.cpp b/src/collision/ContactManifold.cpp index 05232626..7c39b1b0 100644 --- a/src/collision/ContactManifold.cpp +++ b/src/collision/ContactManifold.cpp @@ -33,13 +33,10 @@ using namespace reactphysics3d; // Constructor ContactManifold::ContactManifold(Entity bodyEntity1, Entity bodyEntity2, Entity proxyShapeEntity1, Entity proxyShapeEntity2, uint contactPointsIndex, int8 nbContactPoints) - :mContactPointsIndex(0), bodyEntity1(bodyEntity1), bodyEntity2(bodyEntity2), - proxyShapeEntity1(proxyShapeEntity1), proxyShapeEntity2(proxyShapeEntity2), mFrictionImpulse1(0), mFrictionImpulse2(0), - mFrictionTwistImpulse(0), mIsAlreadyInIsland(false) { + :contactPointsIndex(contactPointsIndex), bodyEntity1(bodyEntity1), bodyEntity2(bodyEntity2), + proxyShapeEntity1(proxyShapeEntity1), proxyShapeEntity2(proxyShapeEntity2), nbContactPoints(nbContactPoints), frictionImpulse1(0), frictionImpulse2(0), + frictionTwistImpulse(0), isAlreadyInIsland(false) { - - mContactPointsIndex = contactPointsIndex; - mNbContactPoints = nbContactPoints; } // Destructor diff --git a/src/collision/ContactManifold.h b/src/collision/ContactManifold.h index e0c86f19..4f7df13f 100644 --- a/src/collision/ContactManifold.h +++ b/src/collision/ContactManifold.h @@ -53,8 +53,7 @@ class PoolAllocator; */ class ContactManifold { - // TODO : Check if we can use public fields in this class (maybe this class is used by users directly) - private: + public: // -------------------- Constants -------------------- // @@ -63,10 +62,8 @@ class ContactManifold { // -------------------- Attributes -------------------- // - // TODO : For each of the attributes, check if we need to keep it or not - /// Index of the first contact point of the manifold in the list of contact points - uint mContactPointsIndex; + uint contactPointsIndex; /// Entity of the first body in contact Entity bodyEntity1; @@ -81,66 +78,28 @@ class ContactManifold { Entity proxyShapeEntity2; /// Number of contacts in the cache - int8 mNbContactPoints; + int8 nbContactPoints; /// First friction vector of the contact manifold - Vector3 mFrictionVector1; + Vector3 frictionVector1; /// Second friction vector of the contact manifold - Vector3 mFrictionVector2; + Vector3 frictionVector2; /// First friction constraint accumulated impulse - decimal mFrictionImpulse1; + decimal frictionImpulse1; /// Second friction constraint accumulated impulse - decimal mFrictionImpulse2; + decimal frictionImpulse2; /// Twist friction constraint accumulated impulse - decimal mFrictionTwistImpulse; + decimal frictionTwistImpulse; /// Accumulated rolling resistance impulse - Vector3 mRollingResistanceImpulse; + Vector3 rollingResistanceImpulse; /// True if the contact manifold has already been added into an island - bool mIsAlreadyInIsland; - - // -------------------- Methods -------------------- // - - /// Return true if the contact manifold has already been added into an island - bool isAlreadyInIsland() const; - - /// set the first friction vector at the center of the contact manifold - void setFrictionVector1(const Vector3& mFrictionVector1); - - /// set the second friction vector at the center of the contact manifold - void setFrictionVector2(const Vector3& mFrictionVector2); - - /// Set the first friction accumulated impulse - void setFrictionImpulse1(decimal frictionImpulse1); - - /// Set the second friction accumulated impulse - void setFrictionImpulse2(decimal frictionImpulse2); - - /// Set the friction twist accumulated impulse - void setFrictionTwistImpulse(decimal frictionTwistImpulse); - - /// Set the accumulated rolling resistance impulse - void setRollingResistanceImpulse(const Vector3& rollingResistanceImpulse); - - /// Return the first friction vector at the center of the contact manifold - const Vector3& getFrictionVector1() const; - - /// Return the second friction vector at the center of the contact manifold - const Vector3& getFrictionVector2() const; - - /// Return the first friction accumulated impulse - decimal getFrictionImpulse1() const; - - /// Return the second friction accumulated impulse - decimal getFrictionImpulse2() const; - - /// Return the friction twist accumulated impulse - decimal getFrictionTwistImpulse() const; + bool isAlreadyInIsland; public: @@ -159,9 +118,6 @@ class ContactManifold { /// Assignment operator ContactManifold& operator=(const ContactManifold& contactManifold) = default; - /// Return the number of contact points in the manifold - int8 getNbContactPoints() const; - // -------------------- Friendship -------------------- // friend class DynamicsWorld; @@ -172,71 +128,6 @@ class ContactManifold { friend class CollisionDetection; }; -// Return the number of contact points in the manifold -inline int8 ContactManifold::getNbContactPoints() const { - return mNbContactPoints; -} - -// Return the first friction vector at the center of the contact manifold -inline const Vector3& ContactManifold::getFrictionVector1() const { - return mFrictionVector1; -} - -// set the first friction vector at the center of the contact manifold -inline void ContactManifold::setFrictionVector1(const Vector3& frictionVector1) { - mFrictionVector1 = frictionVector1; -} - -// Return the second friction vector at the center of the contact manifold -inline const Vector3& ContactManifold::getFrictionVector2() const { - return mFrictionVector2; -} - -// set the second friction vector at the center of the contact manifold -inline void ContactManifold::setFrictionVector2(const Vector3& frictionVector2) { - mFrictionVector2 = frictionVector2; -} - -// Return the first friction accumulated impulse -inline decimal ContactManifold::getFrictionImpulse1() const { - return mFrictionImpulse1; -} - -// Set the first friction accumulated impulse -inline void ContactManifold::setFrictionImpulse1(decimal frictionImpulse1) { - mFrictionImpulse1 = frictionImpulse1; -} - -// Return the second friction accumulated impulse -inline decimal ContactManifold::getFrictionImpulse2() const { - return mFrictionImpulse2; -} - -// Set the second friction accumulated impulse -inline void ContactManifold::setFrictionImpulse2(decimal frictionImpulse2) { - mFrictionImpulse2 = frictionImpulse2; -} - -// Return the friction twist accumulated impulse -inline decimal ContactManifold::getFrictionTwistImpulse() const { - return mFrictionTwistImpulse; -} - -// Set the friction twist accumulated impulse -inline void ContactManifold::setFrictionTwistImpulse(decimal frictionTwistImpulse) { - mFrictionTwistImpulse = frictionTwistImpulse; -} - -// Set the accumulated rolling resistance impulse -inline void ContactManifold::setRollingResistanceImpulse(const Vector3& rollingResistanceImpulse) { - mRollingResistanceImpulse = rollingResistanceImpulse; -} - -// Return true if the contact manifold has already been added into an island -inline bool ContactManifold::isAlreadyInIsland() const { - return mIsAlreadyInIsland; -} - } #endif diff --git a/src/components/Components.h b/src/components/Components.h index a7a04fb8..af721f5c 100644 --- a/src/components/Components.h +++ b/src/components/Components.h @@ -63,7 +63,7 @@ class Components { /// Current number of components uint32 mNbComponents; - // Size (in bytes) of a single component + /// Size (in bytes) of a single component size_t mComponentDataSize; /// Number of allocated components diff --git a/src/engine/ContactSolver.cpp b/src/engine/ContactSolver.cpp index 09a8b7c3..fe43473f 100644 --- a/src/engine/ContactSolver.cpp +++ b/src/engine/ContactSolver.cpp @@ -116,7 +116,7 @@ void ContactSolver::initializeForIsland(uint islandIndex) { ContactManifold& externalManifold = (*mAllContactManifolds)[m]; - assert(externalManifold.getNbContactPoints() > 0); + assert(externalManifold.nbContactPoints > 0); // Get the two bodies of the contact RigidBody* body1 = static_cast(mBodyComponents.getBody(externalManifold.bodyEntity1)); @@ -144,7 +144,7 @@ void ContactSolver::initializeForIsland(uint islandIndex) { mContactConstraints[mNbContactManifolds].inverseInertiaTensorBody2 = body2->getInertiaTensorInverseWorld(); mContactConstraints[mNbContactManifolds].massInverseBody1 = mRigidBodyComponents.getMassInverse(body1->getEntity()); mContactConstraints[mNbContactManifolds].massInverseBody2 = mRigidBodyComponents.getMassInverse(body2->getEntity()); - mContactConstraints[mNbContactManifolds].nbContacts = externalManifold.getNbContactPoints(); + mContactConstraints[mNbContactManifolds].nbContacts = externalManifold.nbContactPoints; mContactConstraints[mNbContactManifolds].frictionCoefficient = computeMixedFrictionCoefficient(body1, body2); mContactConstraints[mNbContactManifolds].rollingResistanceFactor = computeMixedRollingResistance(body1, body2); mContactConstraints[mNbContactManifolds].externalContactManifold = &externalManifold; @@ -159,9 +159,9 @@ void ContactSolver::initializeForIsland(uint islandIndex) { const Vector3& w2 = mRigidBodyComponents.getAngularVelocity(externalManifold.bodyEntity2); // For each contact point of the contact manifold - assert(externalManifold.getNbContactPoints() > 0); - uint contactPointsStartIndex = externalManifold.mContactPointsIndex; - uint nbContactPoints = externalManifold.mNbContactPoints; + assert(externalManifold.nbContactPoints > 0); + uint contactPointsStartIndex = externalManifold.contactPointsIndex; + uint nbContactPoints = externalManifold.nbContactPoints; for (uint c=contactPointsStartIndex; c < contactPointsStartIndex + nbContactPoints; c++) { ContactPoint& externalContact = (*mAllContactPoints)[c]; @@ -254,13 +254,13 @@ void ContactSolver::initializeForIsland(uint islandIndex) { mContactConstraints[mNbContactManifolds].r2Friction.x = mContactConstraints[mNbContactManifolds].frictionPointBody2.x - x2.x; mContactConstraints[mNbContactManifolds].r2Friction.y = mContactConstraints[mNbContactManifolds].frictionPointBody2.y - x2.y; mContactConstraints[mNbContactManifolds].r2Friction.z = mContactConstraints[mNbContactManifolds].frictionPointBody2.z - x2.z; - mContactConstraints[mNbContactManifolds].oldFrictionVector1 = externalManifold.getFrictionVector1(); - mContactConstraints[mNbContactManifolds].oldFrictionVector2 = externalManifold.getFrictionVector2(); + mContactConstraints[mNbContactManifolds].oldFrictionVector1 = externalManifold.frictionVector1; + mContactConstraints[mNbContactManifolds].oldFrictionVector2 = externalManifold.frictionVector2; // Initialize the accumulated impulses with the previous step accumulated impulses - mContactConstraints[mNbContactManifolds].friction1Impulse = externalManifold.getFrictionImpulse1(); - mContactConstraints[mNbContactManifolds].friction2Impulse = externalManifold.getFrictionImpulse2(); - mContactConstraints[mNbContactManifolds].frictionTwistImpulse = externalManifold.getFrictionTwistImpulse(); + mContactConstraints[mNbContactManifolds].friction1Impulse = externalManifold.frictionImpulse1; + mContactConstraints[mNbContactManifolds].friction2Impulse = externalManifold.frictionImpulse2; + mContactConstraints[mNbContactManifolds].frictionTwistImpulse = externalManifold.frictionTwistImpulse; // Compute the inverse K matrix for the rolling resistance constraint bool isBody1DynamicType = body1->getType() == BodyType::DYNAMIC; @@ -805,12 +805,12 @@ void ContactSolver::storeImpulses() { contactPointIndex++; } - mContactConstraints[c].externalContactManifold->setFrictionImpulse1(mContactConstraints[c].friction1Impulse); - mContactConstraints[c].externalContactManifold->setFrictionImpulse2(mContactConstraints[c].friction2Impulse); - mContactConstraints[c].externalContactManifold->setFrictionTwistImpulse(mContactConstraints[c].frictionTwistImpulse); - mContactConstraints[c].externalContactManifold->setRollingResistanceImpulse(mContactConstraints[c].rollingResistanceImpulse); - mContactConstraints[c].externalContactManifold->setFrictionVector1(mContactConstraints[c].frictionVector1); - mContactConstraints[c].externalContactManifold->setFrictionVector2(mContactConstraints[c].frictionVector2); + mContactConstraints[c].externalContactManifold->frictionImpulse1 = mContactConstraints[c].friction1Impulse; + mContactConstraints[c].externalContactManifold->frictionImpulse2 = mContactConstraints[c].friction2Impulse; + mContactConstraints[c].externalContactManifold->frictionTwistImpulse = mContactConstraints[c].frictionTwistImpulse; + mContactConstraints[c].externalContactManifold->rollingResistanceImpulse = mContactConstraints[c].rollingResistanceImpulse; + mContactConstraints[c].externalContactManifold->frictionVector1 = mContactConstraints[c].frictionVector1; + mContactConstraints[c].externalContactManifold->frictionVector2 = mContactConstraints[c].frictionVector2; } }