Refactor some methods in ContactPoint

This commit is contained in:
Daniel Chappuis 2016-11-05 19:20:54 +01:00
parent 16d27f40b9
commit f82777bd3b
4 changed files with 25 additions and 36 deletions

View File

@ -439,6 +439,9 @@ void CollisionDetection::createContact(OverlappingPair* overlappingPair,
ContactPoint* contact = new (mWorld->mPoolAllocator.allocate(sizeof(ContactPoint)))
ContactPoint(contactInfo);
contact->updateWorldContactPoints(overlappingPair->getShape1()->getLocalToWorldTransform(),
overlappingPair->getShape2()->getLocalToWorldTransform());
// Add the contact to the contact manifold set of the corresponding overlapping pair
overlappingPair->addContact(contact);

View File

@ -110,12 +110,9 @@ void ContactManifold::update(const Transform& transform1, const Transform& trans
// Update the world coordinates and penetration depth of the contact points in the manifold
for (uint i=0; i<mNbContactPoints; i++) {
mContactPoints[i]->setWorldPointOnBody1(transform1 *
mContactPoints[i]->getLocalPointOnBody1());
mContactPoints[i]->setWorldPointOnBody2(transform2 *
mContactPoints[i]->getLocalPointOnBody2());
mContactPoints[i]->setPenetrationDepth((mContactPoints[i]->getWorldPointOnBody1() -
mContactPoints[i]->getWorldPointOnBody2()).dot(mContactPoints[i]->getNormal()));
mContactPoints[i]->updateWorldContactPoints(transform1, transform2);
mContactPoints[i]->updatePenetrationDepth();
}
const decimal squarePersistentContactThreshold = PERSISTENT_CONTACT_DIST_THRESHOLD *

View File

@ -36,12 +36,6 @@ ContactPoint::ContactPoint(const ContactPointInfo& contactInfo)
mPenetrationDepth(contactInfo.penetrationDepth),
mLocalPointOnBody1(contactInfo.localPoint1),
mLocalPointOnBody2(contactInfo.localPoint2),
mWorldPointOnBody1(contactInfo.shape1->getBody()->getTransform() *
contactInfo.shape1->getLocalToBodyTransform() *
contactInfo.localPoint1),
mWorldPointOnBody2(contactInfo.shape2->getBody()->getTransform() *
contactInfo.shape2->getLocalToBodyTransform() *
contactInfo.localPoint2),
mIsRestingContact(false) {
assert(mPenetrationDepth > decimal(0.0));

View File

@ -53,6 +53,8 @@ struct ContactPointInfo {
// -------------------- Attributes -------------------- //
// TODO : Check if we really need the shape1, shape2, collisionShape1 and collisionShape2 fields
/// First proxy shape of the contact
ProxyShape* shape1;
@ -141,12 +143,15 @@ class ContactPoint {
/// Deleted assignment operator
ContactPoint& operator=(const ContactPoint& contact) = delete;
/// Update the world contact points
void updateWorldContactPoints(const Transform& body1Transform, const Transform& body2Transform);
/// Update the penetration depth
void updatePenetrationDepth();
/// Return the normal vector of the contact
Vector3 getNormal() const;
/// Set the penetration depth of the contact
void setPenetrationDepth(decimal penetrationDepth);
/// Return the contact local point on body 1
Vector3 getLocalPointOnBody1() const;
@ -165,12 +170,6 @@ class ContactPoint {
/// Set the cached penetration impulse
void setPenetrationImpulse(decimal impulse);
/// Set the contact world point on body 1
void setWorldPointOnBody1(const Vector3& worldPoint);
/// Set the contact world point on body 2
void setWorldPointOnBody2(const Vector3& worldPoint);
/// Return true if the contact is a resting contact
bool getIsRestingContact() const;
@ -184,16 +183,22 @@ class ContactPoint {
size_t getSizeInBytes() const;
};
// Update the world contact points
inline void ContactPoint::updateWorldContactPoints(const Transform& body1Transform, const Transform& body2Transform) {
mWorldPointOnBody1 = body1Transform * mLocalPointOnBody1;
mWorldPointOnBody2 = body2Transform * mLocalPointOnBody2;
}
// Update the penetration depth
inline void ContactPoint::updatePenetrationDepth() {
mPenetrationDepth = (mWorldPointOnBody1 - mWorldPointOnBody2).dot(mNormal);
}
// Return the normal vector of the contact
inline Vector3 ContactPoint::getNormal() const {
return mNormal;
}
// Set the penetration depth of the contact
inline void ContactPoint::setPenetrationDepth(decimal penetrationDepth) {
this->mPenetrationDepth = penetrationDepth;
}
// Return the contact point on body 1
inline Vector3 ContactPoint::getLocalPointOnBody1() const {
return mLocalPointOnBody1;
@ -224,16 +229,6 @@ inline void ContactPoint::setPenetrationImpulse(decimal impulse) {
mPenetrationImpulse = impulse;
}
// Set the contact world point on body 1
inline void ContactPoint::setWorldPointOnBody1(const Vector3& worldPoint) {
mWorldPointOnBody1 = worldPoint;
}
// Set the contact world point on body 2
inline void ContactPoint::setWorldPointOnBody2(const Vector3& worldPoint) {
mWorldPointOnBody2 = worldPoint;
}
// Return true if the contact is a resting contact
inline bool ContactPoint::getIsRestingContact() const {
return mIsRestingContact;