Cosmetic modifications to the code
git-svn-id: https://reactphysics3d.googlecode.com/svn/trunk@382 92aac97c-a6ce-11dd-a772-7fcde58d38e6
This commit is contained in:
parent
898e9ba6f3
commit
4b6e2cd22b
|
@ -23,8 +23,8 @@
|
||||||
#include <GL/gl.h> // TODO : Remove this in the final version
|
#include <GL/gl.h> // TODO : Remove this in the final version
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
// We want to use the ReactPhysics3D namespace
|
|
||||||
using namespace reactphysics3d;
|
using namespace reactphysics3d;
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
AABB::AABB(const Vector3D& center,double extentX, double extentY, double extentZ) {
|
AABB::AABB(const Vector3D& center,double extentX, double extentY, double extentZ) {
|
||||||
|
@ -102,7 +102,7 @@ void AABB::draw() const {
|
||||||
|
|
||||||
// Static method that computes an AABB from a set of vertices. The "center" argument corresponds to the center of the AABB
|
// Static method that computes an AABB from a set of vertices. The "center" argument corresponds to the center of the AABB
|
||||||
// This method allocates a new AABB object and return a pointer to the new allocated AABB object
|
// This method allocates a new AABB object and return a pointer to the new allocated AABB object
|
||||||
AABB* AABB::computeFromVertices(const std::vector<Vector3D>& vertices, const Vector3D& center) {
|
AABB* AABB::computeFromVertices(const vector<Vector3D>& vertices, const Vector3D& center) {
|
||||||
// TODO : Implement this method;
|
// TODO : Implement this method;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,10 @@ Body::Body(double mass, BoundingVolume* broadBoundingVolume, BoundingVolume* nar
|
||||||
// We throw an exception
|
// We throw an exception
|
||||||
throw std::invalid_argument("Exception in Body constructor : the mass has to be different larger than zero");
|
throw std::invalid_argument("Exception in Body constructor : the mass has to be different larger than zero");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set the body pointer to the bounding volumes
|
||||||
|
broadBoundingVolume->setBodyPointer(this);
|
||||||
|
narrowBoundingVolume->setBodyPointer(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
|
|
|
@ -24,8 +24,8 @@
|
||||||
#include <GL/gl.h> // TODO : Remove this in the final version
|
#include <GL/gl.h> // TODO : Remove this in the final version
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
// We want to use the ReactPhysics3D namespace
|
|
||||||
using namespace reactphysics3d;
|
using namespace reactphysics3d;
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
OBB::OBB(const Vector3D& center, const Vector3D& axis1, const Vector3D& axis2,
|
OBB::OBB(const Vector3D& center, const Vector3D& axis1, const Vector3D& axis2,
|
||||||
|
@ -114,10 +114,10 @@ void OBB::draw() const {
|
||||||
|
|
||||||
// Return all the vertices that are projected at the extreme of the projection of the bouding volume on the axis.
|
// Return all the vertices that are projected at the extreme of the projection of the bouding volume on the axis.
|
||||||
// If the extreme vertices are part of a face of the OBB, the returned vertices will be ordered according to the face.
|
// If the extreme vertices are part of a face of the OBB, the returned vertices will be ordered according to the face.
|
||||||
std::vector<Vector3D> OBB::getExtremeVertices(const Vector3D& directionAxis) const {
|
vector<Vector3D> OBB::getExtremeVertices(const Vector3D& directionAxis) const {
|
||||||
assert(directionAxis.length() != 0);
|
assert(directionAxis.length() != 0);
|
||||||
|
|
||||||
std::vector<Vector3D> extremeVertices;
|
vector<Vector3D> extremeVertices;
|
||||||
|
|
||||||
// Check if the given axis is parallel to an axis on the OBB
|
// Check if the given axis is parallel to an axis on the OBB
|
||||||
if (axis[0].isParallelWith(directionAxis)) {
|
if (axis[0].isParallelWith(directionAxis)) {
|
||||||
|
@ -179,10 +179,10 @@ std::vector<Vector3D> OBB::getExtremeVertices(const Vector3D& directionAxis) con
|
||||||
// Return the 4 vertices of a face of the OBB. The 4 vertices will be ordered. The convention is that the index 0 corresponds to
|
// Return the 4 vertices of a face of the OBB. The 4 vertices will be ordered. The convention is that the index 0 corresponds to
|
||||||
// the face in the direction of the axis[0], 1 corresponds to the face in the opposite direction of the axis[0], 2 corresponds to
|
// the face in the direction of the axis[0], 1 corresponds to the face in the opposite direction of the axis[0], 2 corresponds to
|
||||||
// the face in the direction of the axis[1], etc.
|
// the face in the direction of the axis[1], etc.
|
||||||
std::vector<Vector3D> OBB::getFace(unsigned int index) const throw(std::invalid_argument) {
|
vector<Vector3D> OBB::getFace(unsigned int index) const throw(invalid_argument) {
|
||||||
// Check the argument
|
// Check the argument
|
||||||
if (index >=0 && index <6) {
|
if (index >=0 && index <6) {
|
||||||
std::vector<Vector3D> vertices;
|
vector<Vector3D> vertices;
|
||||||
switch(index) {
|
switch(index) {
|
||||||
case 0: vertices.push_back(center + (axis[0]*extent[0]) + (axis[1]*extent[1]) - (axis[2]*extent[2]));
|
case 0: vertices.push_back(center + (axis[0]*extent[0]) + (axis[1]*extent[1]) - (axis[2]*extent[2]));
|
||||||
vertices.push_back(center + (axis[0]*extent[0]) + (axis[1]*extent[1]) + (axis[2]*extent[2]));
|
vertices.push_back(center + (axis[0]*extent[0]) + (axis[1]*extent[1]) + (axis[2]*extent[2]));
|
||||||
|
@ -222,13 +222,13 @@ std::vector<Vector3D> OBB::getFace(unsigned int index) const throw(std::invalid_
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Throw an exception
|
// Throw an exception
|
||||||
throw std::invalid_argument("Exception: The argument must be between 0 and 5");
|
throw invalid_argument("Exception: The argument must be between 0 and 5");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Static method that computes an OBB from a set of vertices. The "center" argument corresponds to the center of the OBB
|
// Static method that computes an OBB from a set of vertices. The "center" argument corresponds to the center of the OBB
|
||||||
// This method allocates a new OBB object and return a pointer to the new allocated OBB object
|
// This method allocates a new OBB object and return a pointer to the new allocated OBB object
|
||||||
OBB* OBB::computeFromVertices(const std::vector<Vector3D>& vertices, const Vector3D& center) {
|
OBB* OBB::computeFromVertices(const vector<Vector3D>& vertices, const Vector3D& center) {
|
||||||
// TODO : Implement this method;
|
// TODO : Implement this method;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,11 +39,6 @@
|
||||||
|
|
||||||
assert(broadBoundingVolume);
|
assert(broadBoundingVolume);
|
||||||
assert(narrowBoundingVolume);
|
assert(narrowBoundingVolume);
|
||||||
|
|
||||||
// Set the body pointer to the bounding volumes
|
|
||||||
// TODO : Move this in the Body constructor
|
|
||||||
broadBoundingVolume->setBodyPointer(this);
|
|
||||||
narrowBoundingVolume->setBodyPointer(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
|
|
|
@ -115,8 +115,8 @@ void CollisionDetection::computeContact(const ContactInfo* const contactInfo) {
|
||||||
Vector3D normal = contactInfo->normal;
|
Vector3D normal = contactInfo->normal;
|
||||||
double penetrationDepth = contactInfo->penetrationDepth;
|
double penetrationDepth = contactInfo->penetrationDepth;
|
||||||
|
|
||||||
const std::vector<Vector3D> obb1ExtremePoints = obb1->getExtremeVertices(normal);
|
const vector<Vector3D> obb1ExtremePoints = obb1->getExtremeVertices(normal);
|
||||||
const std::vector<Vector3D> obb2ExtremePoints = obb2->getExtremeVertices(normal.getOpposite());
|
const vector<Vector3D> obb2ExtremePoints = obb2->getExtremeVertices(normal.getOpposite());
|
||||||
unsigned int nbVerticesExtremeOBB1 = obb1ExtremePoints.size();
|
unsigned int nbVerticesExtremeOBB1 = obb1ExtremePoints.size();
|
||||||
unsigned int nbVerticesExtremeOBB2 = obb2ExtremePoints.size();
|
unsigned int nbVerticesExtremeOBB2 = obb2ExtremePoints.size();
|
||||||
assert(nbVerticesExtremeOBB1==1 || nbVerticesExtremeOBB1==2 || nbVerticesExtremeOBB1==4);
|
assert(nbVerticesExtremeOBB1==1 || nbVerticesExtremeOBB1==2 || nbVerticesExtremeOBB1==4);
|
||||||
|
@ -138,7 +138,7 @@ void CollisionDetection::computeContact(const ContactInfo* const contactInfo) {
|
||||||
Vector3D d2 = obb2ExtremePoints[1] - obb2ExtremePoints[0];
|
Vector3D d2 = obb2ExtremePoints[1] - obb2ExtremePoints[0];
|
||||||
|
|
||||||
double alpha, beta;
|
double alpha, beta;
|
||||||
std::vector<Vector3D> contactSet;
|
vector<Vector3D> contactSet;
|
||||||
|
|
||||||
// If the two edges are parallel
|
// If the two edges are parallel
|
||||||
if (d1.isParallelWith(d2)) {
|
if (d1.isParallelWith(d2)) {
|
||||||
|
@ -174,10 +174,10 @@ void CollisionDetection::computeContact(const ContactInfo* const contactInfo) {
|
||||||
}
|
}
|
||||||
else if(nbVerticesExtremeOBB1 == 2 && nbVerticesExtremeOBB2 == 4) { // If it's an edge-face contact
|
else if(nbVerticesExtremeOBB1 == 2 && nbVerticesExtremeOBB2 == 4) { // If it's an edge-face contact
|
||||||
// Compute the projection of the edge of OBB1 onto the same plane of the face of OBB2
|
// Compute the projection of the edge of OBB1 onto the same plane of the face of OBB2
|
||||||
std::vector<Vector3D> edge = projectPointsOntoPlane(obb1ExtremePoints, obb2ExtremePoints[0], normal);
|
vector<Vector3D> edge = projectPointsOntoPlane(obb1ExtremePoints, obb2ExtremePoints[0], normal);
|
||||||
|
|
||||||
// Clip the edge of OBB1 using the face of OBB2
|
// Clip the edge of OBB1 using the face of OBB2
|
||||||
std::vector<Vector3D> clippedEdge = clipSegmentWithRectangleInPlane(edge, obb2ExtremePoints);
|
vector<Vector3D> clippedEdge = clipSegmentWithRectangleInPlane(edge, obb2ExtremePoints);
|
||||||
|
|
||||||
// TODO : Correct this bug
|
// TODO : Correct this bug
|
||||||
// The following code is to correct a bug when the projected "edge" is not inside the clip rectangle
|
// The following code is to correct a bug when the projected "edge" is not inside the clip rectangle
|
||||||
|
@ -202,10 +202,10 @@ void CollisionDetection::computeContact(const ContactInfo* const contactInfo) {
|
||||||
}
|
}
|
||||||
else if(nbVerticesExtremeOBB1 == 4 && nbVerticesExtremeOBB2 == 2) { // If it's an edge-face contact
|
else if(nbVerticesExtremeOBB1 == 4 && nbVerticesExtremeOBB2 == 2) { // If it's an edge-face contact
|
||||||
// Compute the projection of the edge of OBB2 onto the same plane of the face of OBB1
|
// Compute the projection of the edge of OBB2 onto the same plane of the face of OBB1
|
||||||
std::vector<Vector3D> edge = projectPointsOntoPlane(obb2ExtremePoints, obb1ExtremePoints[0], normal);
|
vector<Vector3D> edge = projectPointsOntoPlane(obb2ExtremePoints, obb1ExtremePoints[0], normal);
|
||||||
|
|
||||||
// Clip the edge of OBB2 using the face of OBB1
|
// Clip the edge of OBB2 using the face of OBB1
|
||||||
std::vector<Vector3D> clippedEdge = clipSegmentWithRectangleInPlane(edge, obb1ExtremePoints);
|
vector<Vector3D> clippedEdge = clipSegmentWithRectangleInPlane(edge, obb1ExtremePoints);
|
||||||
|
|
||||||
// TODO : Correct this bug
|
// TODO : Correct this bug
|
||||||
// The following code is to correct a bug when the projected "edge" is not inside the clip rectangle
|
// The following code is to correct a bug when the projected "edge" is not inside the clip rectangle
|
||||||
|
@ -230,10 +230,10 @@ void CollisionDetection::computeContact(const ContactInfo* const contactInfo) {
|
||||||
}
|
}
|
||||||
else { // If it's a face-face contact
|
else { // If it's a face-face contact
|
||||||
// Compute the projection of the face vertices of OBB2 onto the plane of the face of OBB1
|
// Compute the projection of the face vertices of OBB2 onto the plane of the face of OBB1
|
||||||
std::vector<Vector3D> faceOBB2 = projectPointsOntoPlane(obb2ExtremePoints, obb1ExtremePoints[0], normal);
|
vector<Vector3D> faceOBB2 = projectPointsOntoPlane(obb2ExtremePoints, obb1ExtremePoints[0], normal);
|
||||||
|
|
||||||
// Clip the face of OBB2 using the face of OBB1
|
// Clip the face of OBB2 using the face of OBB1
|
||||||
std::vector<Vector3D> clippedFace = clipPolygonWithRectangleInPlane(faceOBB2, obb1ExtremePoints);
|
vector<Vector3D> clippedFace = clipPolygonWithRectangleInPlane(faceOBB2, obb1ExtremePoints);
|
||||||
|
|
||||||
// Move the clipped face halfway between the face of OBB1 and the face of OBB2
|
// Move the clipped face halfway between the face of OBB1 and the face of OBB2
|
||||||
clippedFace = movePoints(clippedFace, penetrationDepth/2.0 * normal);
|
clippedFace = movePoints(clippedFace, penetrationDepth/2.0 * normal);
|
||||||
|
|
|
@ -55,7 +55,7 @@ void SAPAlgorithm::removeBodiesAABB(vector<Body*> bodies) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the AABB representation of a given body in the sortedAABBs set
|
// Add the AABB representation of a given body in the sortedAABBs set
|
||||||
void SAPAlgorithm::addBodiesAABB(std::vector<Body*> bodies) {
|
void SAPAlgorithm::addBodiesAABB(vector<Body*> bodies) {
|
||||||
const AABB* aabb;
|
const AABB* aabb;
|
||||||
|
|
||||||
for (vector<Body*>::iterator it = bodies.begin(); it != bodies.end(); it++) {
|
for (vector<Body*>::iterator it = bodies.begin(); it != bodies.end(); it++) {
|
||||||
|
|
|
@ -29,8 +29,8 @@
|
||||||
namespace reactphysics3d {
|
namespace reactphysics3d {
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
const double FRICTION_COEFFICIENT = 0.5; // Friction coefficient
|
const double FRICTION_COEFFICIENT = 0.3; // Friction coefficient
|
||||||
const double PENETRATION_FACTOR = 1.0; // Penetration factor (between 0 and 1) which specify the importance of the
|
const double PENETRATION_FACTOR = 0.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
|
||||||
|
|
||||||
/* -------------------------------------------------------------------
|
/* -------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue
Block a user