git-svn-id: https://reactphysics3d.googlecode.com/svn/trunk@227 92aac97c-a6ce-11dd-a772-7fcde58d38e6
This commit is contained in:
parent
c049fdd855
commit
a89fcb13fe
|
@ -133,50 +133,33 @@ 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.
|
||||||
// The function returns the number of extreme vertices and a set that contains thoses vertices.
|
std::vector<Vector3D> OBB::getExtremeVertices(const Vector3D axis) const {
|
||||||
int OBB::getExtremeVertices(const Vector3D projectionAxis, std::vector<Vector3D>& extremeVertices) const {
|
assert(axis.length() != 0);
|
||||||
assert(extremeVertices.size() == 0);
|
|
||||||
assert(projectionAxis.length() != 0);
|
|
||||||
|
|
||||||
double maxProjectionLength = 0.0; // Longest projection length of a vertex onto the projection axis
|
std::vector<Vector3D> extremeVertices;
|
||||||
|
double maxProjectionLength = 0.0; // Longest projection length of a vertex onto the projection axis
|
||||||
|
|
||||||
// Compute the vertices of the OBB
|
// For each vertex of the OBB
|
||||||
double e0 = extent[0];
|
for (unsigned int i=0; i<8; ++i) {
|
||||||
double e1 = extent[1];
|
Vector3D vertex = getVertex(i);
|
||||||
double e2 = extent[2];
|
|
||||||
Vector3D vertices[8];
|
|
||||||
vertices[0] = center + (axis[0]*e0) + (axis[1]*e1) - (axis[2]*e2);
|
|
||||||
vertices[1] = center + (axis[0]*e0) + (axis[1]*e1) + (axis[2]*e2);
|
|
||||||
vertices[2] = center - (axis[0]*e0) + (axis[1]*e1) + (axis[2]*e2);
|
|
||||||
vertices[3] = center - (axis[0]*e0) + (axis[1]*e1) - (axis[2]*e2);
|
|
||||||
vertices[4] = center + (axis[0]*e0) - (axis[1]*e1) - (axis[2]*e2);
|
|
||||||
vertices[5] = center + (axis[0]*e0) - (axis[1]*e1) + (axis[2]*e2);
|
|
||||||
vertices[6] = center - (axis[0]*e0) - (axis[1]*e1) + (axis[2]*e2);
|
|
||||||
vertices[7] = center - (axis[0]*e0) - (axis[1]*e1) - (axis[2]*e2);
|
|
||||||
|
|
||||||
for (int i=0; i<8; ++i) {
|
|
||||||
// Compute the projection length of the current vertex onto the projection axis
|
// Compute the projection length of the current vertex onto the projection axis
|
||||||
double projectionLength = projectionAxis.scalarProduct(vertices[i]-center) / projectionAxis.length();
|
double projectionLength = axis.scalarProduct(vertex-center) / axis.length();
|
||||||
|
|
||||||
//std::cout << "Projection length : " << projectionLength << std::endl;
|
|
||||||
//std::cout << "Max Projection length : " << maxProjectionLength << std::endl;
|
|
||||||
|
|
||||||
// If we found a bigger projection length
|
// If we found a bigger projection length
|
||||||
if (projectionLength > maxProjectionLength + EPSILON) {
|
if (projectionLength > maxProjectionLength + EPSILON) {
|
||||||
maxProjectionLength = projectionLength;
|
maxProjectionLength = projectionLength;
|
||||||
extremeVertices.clear();
|
extremeVertices.clear();
|
||||||
extremeVertices.push_back(vertices[i]);
|
extremeVertices.push_back(vertex);
|
||||||
//std::cout << "PRINT 1" << std::endl;
|
|
||||||
}
|
}
|
||||||
else if (equal(projectionLength, maxProjectionLength)) {
|
else if (equal(projectionLength, maxProjectionLength)) {
|
||||||
extremeVertices.push_back(vertices[i]);
|
extremeVertices.push_back(vertex);
|
||||||
//std::cout << "PRINT 2" << std::endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// An extreme should be a unique vertex, an edge or a face
|
// An extreme should be a unique vertex, an edge or a face
|
||||||
assert(extremeVertices.size() == 1 || extremeVertices.size() == 2 || extremeVertices.size() == 4);
|
assert(extremeVertices.size() == 1 || extremeVertices.size() == 2 || extremeVertices.size() == 4);
|
||||||
|
|
||||||
// Return the number of extreme vertices
|
// Return the extreme vertices
|
||||||
return extremeVertices.size();
|
return extremeVertices;
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,15 +50,16 @@ class OBB : public BoundingVolume {
|
||||||
OBB(const OBB& obb); // Copy-Constructor
|
OBB(const OBB& obb); // Copy-Constructor
|
||||||
virtual ~OBB(); // Destructor
|
virtual ~OBB(); // Destructor
|
||||||
|
|
||||||
Vector3D getCenter() const; // Return the center point of the OBB
|
Vector3D getCenter() const; // Return the center point of the OBB
|
||||||
void setCenter(const Vector3D& center); // Set the center point
|
void setCenter(const Vector3D& center); // Set the center point
|
||||||
Vector3D getAxis(unsigned int index) const throw(std::invalid_argument); // Return an axis of the OBB
|
Vector3D getAxis(unsigned int index) const throw(std::invalid_argument) const; // Return an axis of the OBB
|
||||||
void setAxis(unsigned int index, const Vector3D& axis) throw(std::invalid_argument); // Set an axis
|
void setAxis(unsigned int index, const Vector3D& axis) throw(std::invalid_argument); // Set an axis
|
||||||
double getExtent(unsigned int index) const throw(std::invalid_argument); // Return an extent value
|
Vector3D getVertex(unsigned int index) const throw (std::invalid_argument) const; // Return a vertex of the OBB
|
||||||
void setExtent(unsigned int index, double extent) throw(std::invalid_argument); // Set an extent value
|
double getExtent(unsigned int index) const throw(std::invalid_argument) const; // Return an extent value
|
||||||
virtual int getExtremeVertices(const Vector3D projectionAxis, std::vector<Vector3D>& extremeVertices) const; // Return all the vertices that are projected at the extreme of the projection of the bouding volume on the axis
|
void setExtent(unsigned int index, double extent) throw(std::invalid_argument); // Set an extent value
|
||||||
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 std::vector<Vector3D> 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 draw() const; // Draw the OBB (only for testing purpose)
|
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)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Return the center point of the OBB
|
// Return the center point of the OBB
|
||||||
|
@ -72,7 +73,7 @@ inline void OBB::setCenter(const Vector3D& center) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return an axis of the OBB
|
// Return an axis of the OBB
|
||||||
inline Vector3D OBB::getAxis(unsigned int index) const throw(std::invalid_argument) {
|
inline Vector3D OBB::getAxis(unsigned int index) const throw(std::invalid_argument) const {
|
||||||
// Check if the index value is valid
|
// Check if the index value is valid
|
||||||
if (index >= 0 && index <3) {
|
if (index >= 0 && index <3) {
|
||||||
return axis[index];
|
return axis[index];
|
||||||
|
@ -95,8 +96,43 @@ 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 {
|
||||||
|
// Check if the index value is valid
|
||||||
|
if (index >= 0 && index <8) {
|
||||||
|
Vector3D vertex;
|
||||||
|
|
||||||
|
switch(index) {
|
||||||
|
case 0 : vertex = center + (axis[0]*extent[0]) + (axis[1]*extent[1]) - (axis[2]*extent[2]);
|
||||||
|
break;
|
||||||
|
case 1 : vertex = center + (axis[0]*extent[0]) + (axis[1]*extent[1]) + (axis[2]*extent[2]);
|
||||||
|
break;
|
||||||
|
case 2 : vertex = center - (axis[0]*extent[0]) + (axis[1]*extent[1]) + (axis[2]*extent[2]);
|
||||||
|
break;
|
||||||
|
case 3 : vertex = center - (axis[0]*extent[0]) + (axis[1]*extent[1]) - (axis[2]*extent[2]);
|
||||||
|
break;
|
||||||
|
case 4 : vertex = center + (axis[0]*extent[0]) - (axis[1]*extent[1]) - (axis[2]*extent[2]);
|
||||||
|
break;
|
||||||
|
case 5 : vertex = center + (axis[0]*extent[0]) - (axis[1]*extent[1]) + (axis[2]*extent[2]);
|
||||||
|
break;
|
||||||
|
case 6 : vertex = center - (axis[0]*extent[0]) - (axis[1]*extent[1]) + (axis[2]*extent[2]);
|
||||||
|
break;
|
||||||
|
case 7 : vertex = center - (axis[0]*extent[0]) - (axis[1]*extent[1]) - (axis[2]*extent[2]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the vertex
|
||||||
|
return vertex;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// The index value is not valid, we throw an exception
|
||||||
|
throw std::invalid_argument("Exception : The index value has to be between 0 and 8");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Return an extent value
|
// Return an extent value
|
||||||
inline double OBB::getExtent(unsigned int index) const throw(std::invalid_argument) {
|
inline double OBB::getExtent(unsigned int index) const throw(std::invalid_argument) const {
|
||||||
// Check if the index value is valid
|
// Check if the index value is valid
|
||||||
if (index >= 0 && index <3) {
|
if (index >= 0 && index <3) {
|
||||||
return extent[index];
|
return extent[index];
|
||||||
|
|
Loading…
Reference in New Issue
Block a user