git-svn-id: https://reactphysics3d.googlecode.com/svn/trunk@262 92aac97c-a6ce-11dd-a772-7fcde58d38e6
This commit is contained in:
parent
d5c7822c84
commit
b70e418bd7
|
@ -20,7 +20,7 @@
|
||||||
// Libraries
|
// Libraries
|
||||||
#include "CollisionDetection.h"
|
#include "CollisionDetection.h"
|
||||||
#include "NoBroadPhaseAlgorithm.h"
|
#include "NoBroadPhaseAlgorithm.h"
|
||||||
#include "NarrowPhaseSATAlgorithm.h"
|
#include "SATAlgorithm.h"
|
||||||
#include "../body/OBB.h"
|
#include "../body/OBB.h"
|
||||||
#include "../body/RigidBody.h"
|
#include "../body/RigidBody.h"
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
@ -35,7 +35,7 @@ CollisionDetection::CollisionDetection() {
|
||||||
broadPhaseAlgorithm = new NoBroadPhaseAlgorithm();
|
broadPhaseAlgorithm = new NoBroadPhaseAlgorithm();
|
||||||
|
|
||||||
// Construct the narrow-phase algorithm that will be used (Separating axis with OBB)
|
// Construct the narrow-phase algorithm that will be used (Separating axis with OBB)
|
||||||
narrowPhaseAlgorithm = new NarrowPhaseSATAlgorithm();
|
narrowPhaseAlgorithm = new SATAlgorithm();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
|
|
|
@ -18,13 +18,12 @@
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
// Libraries
|
// Libraries
|
||||||
#include "NarrowPhaseSATAlgorithm.h"
|
#include "SATAlgorithm.h"
|
||||||
#include "../body/OBB.h"
|
#include "../body/OBB.h"
|
||||||
#include "../body/RigidBody.h"
|
#include "../body/RigidBody.h"
|
||||||
#include "../constraint/Contact.h"
|
#include "../constraint/Contact.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cfloat>
|
#include <cfloat>
|
||||||
#include <iostream> // TODO : Delete this
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
// We want to use the ReactPhysics3D namespace
|
// We want to use the ReactPhysics3D namespace
|
||||||
|
@ -36,18 +35,18 @@ using namespace reactphysics3d;
|
||||||
// everything have to do with the new SAT algorithm
|
// everything have to do with the new SAT algorithm
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
NarrowPhaseSATAlgorithm::NarrowPhaseSATAlgorithm() {
|
SATAlgorithm::SATAlgorithm() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
NarrowPhaseSATAlgorithm::~NarrowPhaseSATAlgorithm() {
|
SATAlgorithm::~SATAlgorithm() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return true and compute a collision contact if the two bounding volume collide.
|
// 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.
|
// 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(boundingVolume1 != boundingVolume2);
|
||||||
assert(*contact == 0);
|
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
|
// 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
|
// 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.
|
// 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 center; // Center of a projection interval
|
||||||
double radius1; // Radius of projection interval [min1, max1]
|
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
|
// 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
|
// 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.
|
// 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
|
// Compute the length of both intervals
|
||||||
double lengthInterval1 = max1 - min1;
|
double lengthInterval1 = max1 - min1;
|
||||||
|
@ -485,8 +484,8 @@ double NarrowPhaseSATAlgorithm::computePenetrationDepth(double min1, double max1
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute a new collision contact between two OBBs
|
// 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 {
|
const std::vector<Vector3D>& obb1ExtremePoints, const std::vector<Vector3D>& obb2ExtremePoints, Contact** contact) const {
|
||||||
|
|
||||||
unsigned int nbVerticesExtremeOBB1 = obb1ExtremePoints.size();
|
unsigned int nbVerticesExtremeOBB1 = obb1ExtremePoints.size();
|
||||||
unsigned int nbVerticesExtremeOBB2 = obb2ExtremePoints.size();
|
unsigned int nbVerticesExtremeOBB2 = obb2ExtremePoints.size();
|
||||||
|
|
|
@ -17,8 +17,8 @@
|
||||||
* along with ReactPhysics3D. If not, see <http://www.gnu.org/licenses/>. *
|
* along with ReactPhysics3D. If not, see <http://www.gnu.org/licenses/>. *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
#ifndef NARROWPHASESATALGORITHM_H
|
#ifndef SATALGORITHM_H
|
||||||
#define NARROWPHASESATALGORITHM_H
|
#define SATALGORITHM_H
|
||||||
|
|
||||||
// Libraries
|
// Libraries
|
||||||
#include "NarrowPhaseAlgorithm.h"
|
#include "NarrowPhaseAlgorithm.h"
|
||||||
|
@ -29,7 +29,7 @@
|
||||||
namespace reactphysics3d {
|
namespace reactphysics3d {
|
||||||
|
|
||||||
/* -------------------------------------------------------------------
|
/* -------------------------------------------------------------------
|
||||||
Class NarrowPhaseSATAlgorithm :
|
Class SATAlgorithm :
|
||||||
This class implements a narrow-phase algorithm. This algorithm
|
This class implements a narrow-phase algorithm. This algorithm
|
||||||
uses a separating axis theorem (SAT) to check if two bounding
|
uses a separating axis theorem (SAT) to check if two bounding
|
||||||
volumes collide or not. If the
|
volumes collide or not. If the
|
||||||
|
@ -42,7 +42,7 @@ namespace reactphysics3d {
|
||||||
intersect.
|
intersect.
|
||||||
-------------------------------------------------------------------
|
-------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
class NarrowPhaseSATAlgorithm : public NarrowPhaseAlgorithm {
|
class SATAlgorithm : public NarrowPhaseAlgorithm {
|
||||||
private :
|
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
|
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
|
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
|
Vector3D computeContactNormal(const Vector3D& axis, const Vector3D& distanceOfOBBs) const; // Compute a contact normal
|
||||||
|
|
||||||
public :
|
public :
|
||||||
NarrowPhaseSATAlgorithm(); // Constructor
|
SATAlgorithm(); // Constructor
|
||||||
~NarrowPhaseSATAlgorithm(); // Destructor
|
~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
|
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
|
// 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).
|
// 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) {
|
if (distanceOfOBBs.scalarProduct(axis) >= 0.0) {
|
||||||
return axis;
|
return axis;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user