2010-09-09 22:27:01 +00:00
|
|
|
/********************************************************************************
|
|
|
|
* ReactPhysics3D physics library, http://code.google.com/p/reactphysics3d/ *
|
|
|
|
* Copyright (c) 2010 Daniel Chappuis *
|
|
|
|
*********************************************************************************
|
|
|
|
* *
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy *
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal *
|
|
|
|
* in the Software without restriction, including without limitation the rights *
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is *
|
|
|
|
* furnished to do so, subject to the following conditions: *
|
|
|
|
* *
|
|
|
|
* The above copyright notice and this permission notice shall be included in *
|
|
|
|
* all copies or substantial portions of the Software. *
|
|
|
|
* *
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN *
|
|
|
|
* THE SOFTWARE. *
|
|
|
|
********************************************************************************/
|
|
|
|
|
2011-07-10 17:25:44 +00:00
|
|
|
#ifndef BOX_SHAPE_H
|
|
|
|
#define BOX_SHAPE_H
|
2010-09-09 22:27:01 +00:00
|
|
|
|
|
|
|
// Libraries
|
|
|
|
#include <cfloat>
|
2011-07-09 16:58:50 +00:00
|
|
|
#include "Shape.h"
|
2010-09-09 22:27:01 +00:00
|
|
|
#include "../mathematics/mathematics.h"
|
|
|
|
|
2011-08-05 17:35:01 +00:00
|
|
|
|
2010-09-09 22:27:01 +00:00
|
|
|
// ReactPhysics3D namespace
|
|
|
|
namespace reactphysics3d {
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------
|
2011-07-10 17:25:44 +00:00
|
|
|
Class BoxShape :
|
2011-06-30 20:23:01 +00:00
|
|
|
This class represents a 3D box. Those axis are unit length.
|
|
|
|
The three extents are half-widths of the box along the three
|
|
|
|
axis x, y, z local axis. The "transform" of the corresponding
|
2011-08-05 17:35:01 +00:00
|
|
|
rigid body gives an orientation and a position to the box.
|
2010-09-09 22:27:01 +00:00
|
|
|
-------------------------------------------------------------------
|
|
|
|
*/
|
2011-07-10 17:25:44 +00:00
|
|
|
class BoxShape : public Shape {
|
2011-06-30 20:23:01 +00:00
|
|
|
private :
|
2011-08-23 21:53:01 +00:00
|
|
|
Vector3 extent; // Extent sizes of the box in the x, y and z direction
|
2010-09-09 22:27:01 +00:00
|
|
|
|
|
|
|
public :
|
2011-08-18 21:02:48 +00:00
|
|
|
BoxShape(const Vector3& extent); // Constructor
|
2011-07-10 17:25:44 +00:00
|
|
|
virtual ~BoxShape(); // Destructor
|
2010-09-09 22:27:01 +00:00
|
|
|
|
2011-08-23 21:53:01 +00:00
|
|
|
const Vector3& getExtent() const; // Return the extents of the box
|
|
|
|
void setExtent(const Vector3& extent); // Set the extents of the box
|
|
|
|
virtual Vector3 getLocalExtents(double margin=0.0) const; // Return the local extents in x,y and z direction
|
|
|
|
virtual Vector3 getLocalSupportPoint(const Vector3& direction, double margin=0.0) const; // Return a local support point in a given direction
|
|
|
|
virtual void computeLocalInertiaTensor(Matrix3x3& tensor, double mass) const; // Return the local inertia tensor of the shape
|
2011-02-01 11:03:54 +00:00
|
|
|
|
|
|
|
#ifdef VISUAL_DEBUG
|
2011-07-10 17:25:44 +00:00
|
|
|
virtual void draw() const; // Draw the Box (only for testing purpose)
|
2011-02-01 11:03:54 +00:00
|
|
|
#endif
|
2010-09-09 22:27:01 +00:00
|
|
|
};
|
|
|
|
|
2011-06-30 20:23:01 +00:00
|
|
|
// Return the extents of the box
|
2011-08-18 21:02:48 +00:00
|
|
|
inline const Vector3& BoxShape::getExtent() const {
|
2011-06-30 20:23:01 +00:00
|
|
|
return extent;
|
2010-09-09 22:27:01 +00:00
|
|
|
}
|
|
|
|
|
2011-06-30 20:23:01 +00:00
|
|
|
// Set the extents of the box
|
2011-08-18 21:02:48 +00:00
|
|
|
inline void BoxShape::setExtent(const Vector3& extent) {
|
2011-06-30 20:23:01 +00:00
|
|
|
this->extent = extent;
|
2010-09-09 22:27:01 +00:00
|
|
|
}
|
|
|
|
|
2011-06-30 20:23:01 +00:00
|
|
|
// Return the local extents of the shape (half-width) in x,y and z local direction
|
|
|
|
// This method is used to compute the AABB of the box
|
2011-08-18 21:02:48 +00:00
|
|
|
inline Vector3 BoxShape::getLocalExtents(double margin) const {
|
|
|
|
return extent + Vector3(margin, margin, margin);
|
2010-09-09 22:27:01 +00:00
|
|
|
}
|
|
|
|
|
2011-08-05 17:35:01 +00:00
|
|
|
// Return a local support point in a given direction
|
2011-08-18 21:02:48 +00:00
|
|
|
inline Vector3 BoxShape::getLocalSupportPoint(const Vector3& direction, double margin) const {
|
2011-02-07 15:09:45 +00:00
|
|
|
assert(margin >= 0.0);
|
|
|
|
|
2011-08-18 21:02:48 +00:00
|
|
|
return Vector3(direction.getX() < 0.0 ? -extent.getX()-margin : extent.getX()+margin,
|
2011-06-30 20:23:01 +00:00
|
|
|
direction.getY() < 0.0 ? -extent.getY()-margin : extent.getY()+margin,
|
|
|
|
direction.getZ() < 0.0 ? -extent.getZ()-margin : extent.getZ()+margin);
|
2011-02-01 11:03:54 +00:00
|
|
|
}
|
|
|
|
|
2010-09-09 22:27:01 +00:00
|
|
|
}; // End of the ReactPhysics3D namespace
|
|
|
|
|
|
|
|
#endif
|