git-svn-id: https://reactphysics3d.googlecode.com/svn/trunk@262 92aac97c-a6ce-11dd-a772-7fcde58d38e6

This commit is contained in:
chappuis.daniel 2010-02-06 18:42:04 +00:00
parent d5c7822c84
commit b70e418bd7
3 changed files with 17 additions and 18 deletions

View File

@ -20,7 +20,7 @@
// Libraries
#include "CollisionDetection.h"
#include "NoBroadPhaseAlgorithm.h"
#include "NarrowPhaseSATAlgorithm.h"
#include "SATAlgorithm.h"
#include "../body/OBB.h"
#include "../body/RigidBody.h"
#include <cassert>
@ -35,7 +35,7 @@ CollisionDetection::CollisionDetection() {
broadPhaseAlgorithm = new NoBroadPhaseAlgorithm();
// Construct the narrow-phase algorithm that will be used (Separating axis with OBB)
narrowPhaseAlgorithm = new NarrowPhaseSATAlgorithm();
narrowPhaseAlgorithm = new SATAlgorithm();
}
// Destructor

View File

@ -18,13 +18,12 @@
***************************************************************************/
// Libraries
#include "NarrowPhaseSATAlgorithm.h"
#include "SATAlgorithm.h"
#include "../body/OBB.h"
#include "../body/RigidBody.h"
#include "../constraint/Contact.h"
#include <algorithm>
#include <cfloat>
#include <iostream> // TODO : Delete this
#include <cassert>
// We want to use the ReactPhysics3D namespace
@ -36,18 +35,18 @@ using namespace reactphysics3d;
//  everything have to do with the new SAT algorithm
// Constructor
NarrowPhaseSATAlgorithm::NarrowPhaseSATAlgorithm() {
SATAlgorithm::SATAlgorithm() {
}
// Destructor
NarrowPhaseSATAlgorithm::~NarrowPhaseSATAlgorithm() {
SATAlgorithm::~SATAlgorithm() {
}
// Return true and compute a collision contact if the two bounding volume collide.
// The method returns false if there is no collision between the two bounding volumes.
bool NarrowPhaseSATAlgorithm::testCollision(const BoundingVolume* const boundingVolume1, const BoundingVolume* const boundingVolume2, Contact** contact) {
bool SATAlgorithm::testCollision(const BoundingVolume* const boundingVolume1, const BoundingVolume* const boundingVolume2, Contact** contact) {
assert(boundingVolume1 != boundingVolume2);
assert(*contact == 0);
@ -74,7 +73,7 @@ bool NarrowPhaseSATAlgorithm::testCollision(const BoundingVolume* const bounding
// OBB are the six face normals (3 for each OBB) and the nine vectors V = Ai x Bj where Ai is the ith face normal
// vector of OBB 1 and Bj is the jth face normal vector of OBB 2. We will use the notation Ai for the ith face
// normal of OBB 1 and Bj for the jth face normal of OBB 2.
bool NarrowPhaseSATAlgorithm::computeCollisionTest(const OBB* const obb1, const OBB* const obb2, Contact** contact) const {
bool SATAlgorithm::computeCollisionTest(const OBB* const obb1, const OBB* const obb2, Contact** contact) const {
double center; // Center of a projection interval
double radius1; // Radius of projection interval [min1, max1]
@ -456,7 +455,7 @@ bool NarrowPhaseSATAlgorithm::computeCollisionTest(const OBB* const obb1, const
// penetration depth (note that it could return a negative penetration depth if the intervals are separated. This
// method also find which interval is at the left of the other in order to know which extreme of interval 1 collides with
// which extreme of interval 2 if a collision occur.
double NarrowPhaseSATAlgorithm::computePenetrationDepth(double min1, double max1, double min2, double max2, bool& side) const {
double SATAlgorithm::computePenetrationDepth(double min1, double max1, double min2, double max2, bool& side) const {
// Compute the length of both intervals
double lengthInterval1 = max1 - min1;
@ -485,7 +484,7 @@ double NarrowPhaseSATAlgorithm::computePenetrationDepth(double min1, double max1
}
// Compute a new collision contact between two OBBs
void NarrowPhaseSATAlgorithm::computeContact(const OBB* const obb1, const OBB* const obb2, const Vector3D normal, double penetrationDepth,
void SATAlgorithm::computeContact(const OBB* const obb1, const OBB* const obb2, const Vector3D normal, double penetrationDepth,
const std::vector<Vector3D>& obb1ExtremePoints, const std::vector<Vector3D>& obb2ExtremePoints, Contact** contact) const {
unsigned int nbVerticesExtremeOBB1 = obb1ExtremePoints.size();

View File

@ -17,8 +17,8 @@
* along with ReactPhysics3D. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#ifndef NARROWPHASESATALGORITHM_H
#define NARROWPHASESATALGORITHM_H
#ifndef SATALGORITHM_H
#define SATALGORITHM_H
// Libraries
#include "NarrowPhaseAlgorithm.h"
@ -29,7 +29,7 @@
namespace reactphysics3d {
/* -------------------------------------------------------------------
Class NarrowPhaseSATAlgorithm :
Class SATAlgorithm :
This class implements a narrow-phase algorithm. This algorithm
uses a separating axis theorem (SAT) to check if two bounding
volumes collide or not. If the
@ -42,7 +42,7 @@ namespace reactphysics3d {
intersect.
-------------------------------------------------------------------
*/
class NarrowPhaseSATAlgorithm : public NarrowPhaseAlgorithm {
class SATAlgorithm : public NarrowPhaseAlgorithm {
private :
bool computeCollisionTest(const OBB* const obb1, const OBB* const obb2, Contact** contact) const; // Return true and compute a collision contact if the two OBB collide
double computePenetrationDepth(double min1, double max1, double min2, double max2, bool& side) const; // Compute the penetration depth of two projection intervals
@ -51,8 +51,8 @@ class NarrowPhaseSATAlgorithm : public NarrowPhaseAlgorithm {
Vector3D computeContactNormal(const Vector3D& axis, const Vector3D& distanceOfOBBs) const; // Compute a contact normal
public :
NarrowPhaseSATAlgorithm(); // Constructor
~NarrowPhaseSATAlgorithm(); // Destructor
SATAlgorithm(); // Constructor
~SATAlgorithm(); // Destructor
virtual bool testCollision(const BoundingVolume* const boundingVolume1, const BoundingVolume* const boundingVolume2, Contact** contact); // Return true and compute a collision contact if the two bounding volume collide
};
@ -61,7 +61,7 @@ class NarrowPhaseSATAlgorithm : public NarrowPhaseAlgorithm {
// Return the contact normal with the correct sign (from obb1 toward obb2). "axis" is the axis vector direction where the
// collision occur and "distanceOfOBBs" is the vector (obb2.center - obb1.center).
inline Vector3D NarrowPhaseSATAlgorithm::computeContactNormal(const Vector3D& axis, const Vector3D& distanceOfOBBs) const {
inline Vector3D SATAlgorithm::computeContactNormal(const Vector3D& axis, const Vector3D& distanceOfOBBs) const {
if (distanceOfOBBs.scalarProduct(axis) >= 0.0) {
return axis;
}