Some modifications in the collision detection.

git-svn-id: https://reactphysics3d.googlecode.com/svn/trunk@374 92aac97c-a6ce-11dd-a772-7fcde58d38e6
This commit is contained in:
chappuis.daniel 2010-08-18 14:49:29 +00:00
parent 619c70dc48
commit 859d8e409b
5 changed files with 9 additions and 6 deletions

View File

@ -25,9 +25,11 @@
#include "../body/OBB.h" #include "../body/OBB.h"
#include "../body/RigidBody.h" #include "../body/RigidBody.h"
#include <cassert> #include <cassert>
#include <complex>
// We want to use the ReactPhysics3D namespace // We want to use the ReactPhysics3D namespace
using namespace reactphysics3d; using namespace reactphysics3d;
using namespace std;
// Constructor // Constructor
CollisionDetection::CollisionDetection(PhysicsWorld* world) { CollisionDetection::CollisionDetection(PhysicsWorld* world) {
@ -243,4 +245,4 @@ void CollisionDetection::computeContact(const ContactInfo* const contactInfo) {
world->addConstraint(new Contact(obb1->getBodyPointer(), obb2->getBodyPointer(), normal, penetrationDepth, clippedFace.at(i))); world->addConstraint(new Contact(obb1->getBodyPointer(), obb2->getBodyPointer(), normal, penetrationDepth, clippedFace.at(i)));
} }
} }
} }

View File

@ -51,6 +51,7 @@ class CollisionDetection {
void computeNarrowPhase(); // Compute the narrow-phase collision detection void computeNarrowPhase(); // Compute the narrow-phase collision detection
void computeAllContacts(); // Compute all the contacts from the collision info list void computeAllContacts(); // Compute all the contacts from the collision info list
void computeContact(const ContactInfo* const contactInfo); // Compute a contact (and add it to the physics world) for two colliding bodies void computeContact(const ContactInfo* const contactInfo); // Compute a contact (and add it to the physics world) for two colliding bodies
void computeContact2(const ContactInfo* const contactInfo); // Compute a contact (and add it to the physics world) for two colliding bodies
public : public :
CollisionDetection(PhysicsWorld* physicsWorld); // Constructor CollisionDetection(PhysicsWorld* physicsWorld); // Constructor

View File

@ -42,8 +42,8 @@ struct ContactInfo {
const OBB* const obb2; // Body pointer of the second bounding volume const OBB* const obb2; // Body pointer of the second bounding volume
const Vector3D normal; // Normal vector the the collision contact const Vector3D normal; // Normal vector the the collision contact
const double penetrationDepth; // Penetration depth of the contact const double penetrationDepth; // Penetration depth of the contact
ContactInfo(const OBB* const obb1, const OBB* const obb2, const Vector3D& normal, double penetrationDepth); // Constructor ContactInfo(const OBB* const obb1, const OBB* const obb2, const Vector3D& normal, double penetrationDepth); // Constructor
}; };
} // End of the ReactPhysics3D namespace } // End of the ReactPhysics3D namespace

View File

@ -27,6 +27,7 @@
#include <cmath> #include <cmath>
#include <cassert> #include <cassert>
// We want to use the ReactPhysics3D namespace // We want to use the ReactPhysics3D namespace
using namespace reactphysics3d; using namespace reactphysics3d;
@ -95,7 +96,7 @@ bool SATAlgorithm::computeCollisionTest(const OBB* const obb1, const OBB* const
double absC[3][3]; // absC[i][j] = abs(DotProduct(obb1.Ai, obb2.Bj)) double absC[3][3]; // absC[i][j] = abs(DotProduct(obb1.Ai, obb2.Bj))
double udc1[3]; // DotProduct(obb1.Ai, obb2.center - obb1.center) double udc1[3]; // DotProduct(obb1.Ai, obb2.center - obb1.center)
double udc2[3]; // DotProduct(obb2.Ai, obb2.center - obb1.center) double udc2[3]; // DotProduct(obb2.Ai, obb2.center - obb1.center)
Vector3D boxDistance = obb2->getCenter() - obb1->getCenter(); // Vector between the centers of the OBBs Vector3D boxDistance = obb2->getCenter() - obb1->getCenter(); // Vector between the centers of the OBBs
// Axis A0 // Axis A0
@ -170,7 +171,6 @@ bool SATAlgorithm::computeCollisionTest(const OBB* const obb1, const OBB* const
} }
else if (penetrationDepth < minPenetrationDepth) { // Interval 1 and 2 overlap with a smaller penetration depth on this axis else if (penetrationDepth < minPenetrationDepth) { // Interval 1 and 2 overlap with a smaller penetration depth on this axis
minPenetrationDepth = penetrationDepth; // Update the minimum penetration depth minPenetrationDepth = penetrationDepth; // Update the minimum penetration depth
normal = computeContactNormal(obb1->getAxis(2), boxDistance); // Compute the contact normal with the correct sign
} }
// Axis B0 // Axis B0

View File

@ -30,7 +30,7 @@ namespace reactphysics3d {
// Constants // Constants
const double FRICTION_COEFFICIENT = 0.1; // Friction coefficient const double FRICTION_COEFFICIENT = 0.1; // Friction coefficient
const double PENETRATION_FACTOR = 0.6; // Penetration factor (between 0 and 1) which specify the importance of the const double PENETRATION_FACTOR = 1.0; // Penetration factor (between 0 and 1) which specify the importance of the
// penetration depth in order to calculate the correct impulse for the contact // penetration depth in order to calculate the correct impulse for the contact
/* ------------------------------------------------------------------- /* -------------------------------------------------------------------