From 902f3ab2b449a9c41bd86266b75042f4bdfae147 Mon Sep 17 00:00:00 2001 From: "chappuis.daniel" Date: Wed, 23 Dec 2009 10:06:10 +0000 Subject: [PATCH] git-svn-id: https://reactphysics3d.googlecode.com/svn/trunk@232 92aac97c-a6ce-11dd-a772-7fcde58d38e6 --- sources/reactphysics3d/body/BodyState.h | 2 +- sources/reactphysics3d/body/OBB.cpp | 36 ++++++++++++++++++------- sources/reactphysics3d/body/OBB.h | 8 +++--- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/sources/reactphysics3d/body/BodyState.h b/sources/reactphysics3d/body/BodyState.h index e67c4b87..1efdab3e 100644 --- a/sources/reactphysics3d/body/BodyState.h +++ b/sources/reactphysics3d/body/BodyState.h @@ -162,7 +162,7 @@ inline Vector3D BodyState::getForce() const { // Set the force over the body inline void BodyState::setForce(const Vector3D& force) { - this->force; + this->force = force; } // Return the current torque of the body diff --git a/sources/reactphysics3d/body/OBB.cpp b/sources/reactphysics3d/body/OBB.cpp index d7f3819f..a014ae57 100644 --- a/sources/reactphysics3d/body/OBB.cpp +++ b/sources/reactphysics3d/body/OBB.cpp @@ -134,30 +134,46 @@ void OBB::draw() const { // Return all the vertices that are projected at the extreme of the projection of the bouding volume on the axis. // Be careful when this method returns vertices of a polygonal face because vertices are not necessarly ordered. -std::vector OBB::getExtremeVertices(const Vector3D axis) const { - assert(axis.length() != 0); +std::vector OBB::getExtremeVertices(const Vector3D& directionAxis) const { + assert(directionAxis.length() != 0); std::vector extremeVertices; // Check if the given axis is parallel to an axis on the OBB - if (axis[0].isParallelWith(axis)) { - // TODO : Complete this + if (axis[0].isParallelWith(directionAxis)) { + if (axis[0].scalarProduct(directionAxis) >= 0) { // If both axis are in the same direction + extremeVertices = getFace(0); // The extreme is the face 0 + } + else { + extremeVertices = getFace(1); // The extreme is the face 1 + } } - else if(axis[1].isParallelWith(axis) { - // TODO : Complete this + else if(axis[1].isParallelWith(directionAxis)) { + if (axis[1].scalarProduct(directionAxis) >= 0) { // If both axis are in the same direction + extremeVertices = getFace(2); // The extreme is the face 2 + } + else { + extremeVertices = getFace(3); // The extreme is the face 3 + } + } - else if(axis[2].isParallelWith(axis) { - // TODO : Complete this + else if(axis[2].isParallelWith(directionAxis)) { + if (axis[2].scalarProduct(directionAxis) >= 0) { // If both axis are in the same direction + extremeVertices = getFace(4); // The extreme is the face 4 + } + else { + extremeVertices = getFace(5); // The extreme is the face 5 + } } else { // The extreme is made of an unique vertex or an edge - double maxProjectionLength = 0.0; // Longest projection length of a vertex onto the projection axis + double maxProjectionLength = 0.0; // Longest projection length of a vertex onto the projection axis // For each vertex of the OBB for (unsigned int i=0; i<8; ++i) { Vector3D vertex = getVertex(i); // Compute the projection length of the current vertex onto the projection axis - double projectionLength = axis.scalarProduct(vertex-center) / axis.length(); + double projectionLength = directionAxis.scalarProduct(vertex-center) / directionAxis.length(); // If we found a bigger projection length if (projectionLength > maxProjectionLength + EPSILON) { diff --git a/sources/reactphysics3d/body/OBB.h b/sources/reactphysics3d/body/OBB.h index e9b3284d..27d44218 100644 --- a/sources/reactphysics3d/body/OBB.h +++ b/sources/reactphysics3d/body/OBB.h @@ -58,7 +58,7 @@ class OBB : public BoundingVolume { std::vector getFace(int index) const throw(std::invalid_argument); // Return the 4 vertices the OBB's face in the direction of a given axis double getExtent(unsigned int index) const throw(std::invalid_argument); // Return an extent value void setExtent(unsigned int index, double extent) throw(std::invalid_argument); // Set an extent value - virtual std::vector getExtremeVertices(const Vector3D axis) const; // Return all the vertices that are projected at the extreme of the projection of the bouding volume on the axis + virtual std::vector getExtremeVertices(const Vector3D& axis) const; // Return all the vertices that are projected at the extreme of the projection of the bouding volume on the axis virtual void updateOrientation(const Vector3D& newCenter, const Quaternion& rotationQuaternion); // Update the oriented bounding box orientation according to a new orientation of the rigid body virtual void draw() const; // Draw the OBB (only for testing purpose) }; @@ -74,7 +74,7 @@ inline void OBB::setCenter(const Vector3D& center) { } // Return an axis of the OBB -inline Vector3D OBB::getAxis(unsigned int index) const throw(std::invalid_argument) const { +inline Vector3D OBB::getAxis(unsigned int index) const throw(std::invalid_argument) { // Check if the index value is valid if (index >= 0 && index <3) { return axis[index]; @@ -98,7 +98,7 @@ inline void OBB::setAxis(unsigned int index, const Vector3D& axis) throw(std::in } // Return a vertex of the OBB -inline Vector3D OBB::getVertex(unsigned int index) const throw (std::invalid_argument) const { +inline Vector3D OBB::getVertex(unsigned int index) const throw (std::invalid_argument) { // Check if the index value is valid if (index >= 0 && index <8) { Vector3D vertex; @@ -133,7 +133,7 @@ inline Vector3D OBB::getVertex(unsigned int index) const throw (std::invalid_arg // Return an extent value -inline double OBB::getExtent(unsigned int index) const throw(std::invalid_argument) const { +inline double OBB::getExtent(unsigned int index) const throw(std::invalid_argument) { // Check if the index value is valid if (index >= 0 && index <3) { return extent[index];