From 4b6e2cd22bb955f8dbf4adb1f91f0881008bdf92 Mon Sep 17 00:00:00 2001 From: "chappuis.daniel" Date: Fri, 27 Aug 2010 10:00:25 +0000 Subject: [PATCH] Cosmetic modifications to the code git-svn-id: https://reactphysics3d.googlecode.com/svn/trunk@382 92aac97c-a6ce-11dd-a772-7fcde58d38e6 --- sources/reactphysics3d/body/AABB.cpp | 4 ++-- sources/reactphysics3d/body/Body.cpp | 4 ++++ sources/reactphysics3d/body/OBB.cpp | 16 ++++++++-------- sources/reactphysics3d/body/RigidBody.cpp | 5 ----- .../collision/CollisionDetection.cpp | 18 +++++++++--------- .../reactphysics3d/collision/SAPAlgorithm.cpp | 2 +- sources/reactphysics3d/constraint/Contact.h | 4 ++-- 7 files changed, 26 insertions(+), 27 deletions(-) diff --git a/sources/reactphysics3d/body/AABB.cpp b/sources/reactphysics3d/body/AABB.cpp index d2310529..bd90eeef 100644 --- a/sources/reactphysics3d/body/AABB.cpp +++ b/sources/reactphysics3d/body/AABB.cpp @@ -23,8 +23,8 @@ #include // TODO : Remove this in the final version #include -// We want to use the ReactPhysics3D namespace using namespace reactphysics3d; +using namespace std; // Constructor 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 // This method allocates a new AABB object and return a pointer to the new allocated AABB object -AABB* AABB::computeFromVertices(const std::vector& vertices, const Vector3D& center) { +AABB* AABB::computeFromVertices(const vector& vertices, const Vector3D& center) { // TODO : Implement this method; return 0; } diff --git a/sources/reactphysics3d/body/Body.cpp b/sources/reactphysics3d/body/Body.cpp index b4beb5fa..8d19ad7e 100644 --- a/sources/reactphysics3d/body/Body.cpp +++ b/sources/reactphysics3d/body/Body.cpp @@ -32,6 +32,10 @@ Body::Body(double mass, BoundingVolume* broadBoundingVolume, BoundingVolume* nar // We throw an exception 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 diff --git a/sources/reactphysics3d/body/OBB.cpp b/sources/reactphysics3d/body/OBB.cpp index 2a4a3347..84beee31 100644 --- a/sources/reactphysics3d/body/OBB.cpp +++ b/sources/reactphysics3d/body/OBB.cpp @@ -24,12 +24,12 @@ #include // TODO : Remove this in the final version #include -// We want to use the ReactPhysics3D namespace using namespace reactphysics3d; +using namespace std; // Constructor OBB::OBB(const Vector3D& center, const Vector3D& axis1, const Vector3D& axis2, - const Vector3D& axis3, double extent1, double extent2, double extent3) { + const Vector3D& axis3, double extent1, double extent2, double extent3) { this->center = center; oldAxis[0] = axis1.getUnit(); @@ -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. // If the extreme vertices are part of a face of the OBB, the returned vertices will be ordered according to the face. -std::vector OBB::getExtremeVertices(const Vector3D& directionAxis) const { +vector OBB::getExtremeVertices(const Vector3D& directionAxis) const { assert(directionAxis.length() != 0); - std::vector extremeVertices; + vector extremeVertices; // Check if the given axis is parallel to an axis on the OBB if (axis[0].isParallelWith(directionAxis)) { @@ -179,10 +179,10 @@ std::vector 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 // 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. -std::vector OBB::getFace(unsigned int index) const throw(std::invalid_argument) { +vector OBB::getFace(unsigned int index) const throw(invalid_argument) { // Check the argument if (index >=0 && index <6) { - std::vector vertices; + vector vertices; switch(index) { 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])); @@ -222,13 +222,13 @@ std::vector OBB::getFace(unsigned int index) const throw(std::invalid_ } else { // 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 // This method allocates a new OBB object and return a pointer to the new allocated OBB object -OBB* OBB::computeFromVertices(const std::vector& vertices, const Vector3D& center) { +OBB* OBB::computeFromVertices(const vector& vertices, const Vector3D& center) { // TODO : Implement this method; return 0; } diff --git a/sources/reactphysics3d/body/RigidBody.cpp b/sources/reactphysics3d/body/RigidBody.cpp index 945da5fb..d337d3d9 100644 --- a/sources/reactphysics3d/body/RigidBody.cpp +++ b/sources/reactphysics3d/body/RigidBody.cpp @@ -39,11 +39,6 @@ assert(broadBoundingVolume); assert(narrowBoundingVolume); - - // Set the body pointer to the bounding volumes - // TODO : Move this in the Body constructor - broadBoundingVolume->setBodyPointer(this); - narrowBoundingVolume->setBodyPointer(this); } // Destructor diff --git a/sources/reactphysics3d/collision/CollisionDetection.cpp b/sources/reactphysics3d/collision/CollisionDetection.cpp index 1ca1d194..24253321 100644 --- a/sources/reactphysics3d/collision/CollisionDetection.cpp +++ b/sources/reactphysics3d/collision/CollisionDetection.cpp @@ -115,8 +115,8 @@ void CollisionDetection::computeContact(const ContactInfo* const contactInfo) { Vector3D normal = contactInfo->normal; double penetrationDepth = contactInfo->penetrationDepth; - const std::vector obb1ExtremePoints = obb1->getExtremeVertices(normal); - const std::vector obb2ExtremePoints = obb2->getExtremeVertices(normal.getOpposite()); + const vector obb1ExtremePoints = obb1->getExtremeVertices(normal); + const vector obb2ExtremePoints = obb2->getExtremeVertices(normal.getOpposite()); unsigned int nbVerticesExtremeOBB1 = obb1ExtremePoints.size(); unsigned int nbVerticesExtremeOBB2 = obb2ExtremePoints.size(); assert(nbVerticesExtremeOBB1==1 || nbVerticesExtremeOBB1==2 || nbVerticesExtremeOBB1==4); @@ -138,7 +138,7 @@ void CollisionDetection::computeContact(const ContactInfo* const contactInfo) { Vector3D d2 = obb2ExtremePoints[1] - obb2ExtremePoints[0]; double alpha, beta; - std::vector contactSet; + vector contactSet; // If the two edges are parallel 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 // Compute the projection of the edge of OBB1 onto the same plane of the face of OBB2 - std::vector edge = projectPointsOntoPlane(obb1ExtremePoints, obb2ExtremePoints[0], normal); + vector edge = projectPointsOntoPlane(obb1ExtremePoints, obb2ExtremePoints[0], normal); // Clip the edge of OBB1 using the face of OBB2 - std::vector clippedEdge = clipSegmentWithRectangleInPlane(edge, obb2ExtremePoints); + vector clippedEdge = clipSegmentWithRectangleInPlane(edge, obb2ExtremePoints); // TODO : Correct this bug // 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 // Compute the projection of the edge of OBB2 onto the same plane of the face of OBB1 - std::vector edge = projectPointsOntoPlane(obb2ExtremePoints, obb1ExtremePoints[0], normal); + vector edge = projectPointsOntoPlane(obb2ExtremePoints, obb1ExtremePoints[0], normal); // Clip the edge of OBB2 using the face of OBB1 - std::vector clippedEdge = clipSegmentWithRectangleInPlane(edge, obb1ExtremePoints); + vector clippedEdge = clipSegmentWithRectangleInPlane(edge, obb1ExtremePoints); // TODO : Correct this bug // 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 // Compute the projection of the face vertices of OBB2 onto the plane of the face of OBB1 - std::vector faceOBB2 = projectPointsOntoPlane(obb2ExtremePoints, obb1ExtremePoints[0], normal); + vector faceOBB2 = projectPointsOntoPlane(obb2ExtremePoints, obb1ExtremePoints[0], normal); // Clip the face of OBB2 using the face of OBB1 - std::vector clippedFace = clipPolygonWithRectangleInPlane(faceOBB2, obb1ExtremePoints); + vector clippedFace = clipPolygonWithRectangleInPlane(faceOBB2, obb1ExtremePoints); // Move the clipped face halfway between the face of OBB1 and the face of OBB2 clippedFace = movePoints(clippedFace, penetrationDepth/2.0 * normal); diff --git a/sources/reactphysics3d/collision/SAPAlgorithm.cpp b/sources/reactphysics3d/collision/SAPAlgorithm.cpp index 53105129..2197a67b 100644 --- a/sources/reactphysics3d/collision/SAPAlgorithm.cpp +++ b/sources/reactphysics3d/collision/SAPAlgorithm.cpp @@ -55,7 +55,7 @@ void SAPAlgorithm::removeBodiesAABB(vector bodies) { } // Add the AABB representation of a given body in the sortedAABBs set -void SAPAlgorithm::addBodiesAABB(std::vector bodies) { +void SAPAlgorithm::addBodiesAABB(vector bodies) { const AABB* aabb; for (vector::iterator it = bodies.begin(); it != bodies.end(); it++) { diff --git a/sources/reactphysics3d/constraint/Contact.h b/sources/reactphysics3d/constraint/Contact.h index 28bd07ce..2e515481 100644 --- a/sources/reactphysics3d/constraint/Contact.h +++ b/sources/reactphysics3d/constraint/Contact.h @@ -29,8 +29,8 @@ namespace reactphysics3d { // Constants -const double FRICTION_COEFFICIENT = 0.5; // Friction coefficient -const double PENETRATION_FACTOR = 1.0; // Penetration factor (between 0 and 1) which specify the importance of the +const double FRICTION_COEFFICIENT = 0.3; // Friction coefficient +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 /* -------------------------------------------------------------------