2010-09-09 19:41:14 +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. *
|
|
|
|
********************************************************************************/
|
2009-02-09 09:08:33 +00:00
|
|
|
|
2009-02-10 11:54:34 +00:00
|
|
|
#ifndef BODY_H
|
|
|
|
#define BODY_H
|
2009-02-09 09:08:33 +00:00
|
|
|
|
2010-09-01 16:37:13 +00:00
|
|
|
// Libraries
|
2009-02-10 11:54:34 +00:00
|
|
|
#include <stdexcept>
|
2010-09-01 16:37:13 +00:00
|
|
|
#include <cassert>
|
2009-02-09 11:22:04 +00:00
|
|
|
|
2010-08-05 15:06:34 +00:00
|
|
|
|
2009-02-09 09:08:33 +00:00
|
|
|
// Namespace reactphysics3d
|
|
|
|
namespace reactphysics3d {
|
|
|
|
|
2010-09-01 16:37:13 +00:00
|
|
|
class BroadBoundingVolume;
|
|
|
|
class NarrowBoundingVolume;
|
2010-08-05 15:06:34 +00:00
|
|
|
|
2009-02-09 09:08:33 +00:00
|
|
|
/* -------------------------------------------------------------------
|
|
|
|
Class Body :
|
|
|
|
This class is an abstract class to represent body of the physics
|
|
|
|
engine.
|
|
|
|
-------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
class Body {
|
2010-07-05 19:29:14 +00:00
|
|
|
protected :
|
2010-09-01 16:37:13 +00:00
|
|
|
double mass; // Mass of the body
|
|
|
|
BroadBoundingVolume* broadBoundingVolume; // Bounding volume used for the broad-phase collision detection
|
|
|
|
NarrowBoundingVolume* narrowBoundingVolume; // Bounding volume used for the narrow-phase collision detection
|
|
|
|
bool isMotionEnabled; // True if the body is able to move
|
|
|
|
bool isCollisionEnabled; // True if the body can collide with others bodies
|
|
|
|
|
|
|
|
void setBroadBoundingVolume(BroadBoundingVolume* broadBoundingVolume); // Set the broad-phase bounding volume
|
|
|
|
void setNarrowBoundingVolume(NarrowBoundingVolume* narrowBoundingVolume); // Set the narrow-phase bounding volume
|
2009-02-09 09:08:33 +00:00
|
|
|
|
|
|
|
public :
|
2010-09-01 16:37:13 +00:00
|
|
|
Body(double mass) throw(std::invalid_argument); // Constructor
|
|
|
|
virtual ~Body(); // Destructor
|
2010-08-05 15:06:34 +00:00
|
|
|
|
|
|
|
double getMass() const; // Return the mass of the body
|
|
|
|
void setMass(double mass); // Set the mass of the body
|
|
|
|
bool getIsMotionEnabled() const; // Return if the rigid body can move
|
|
|
|
void setIsMotionEnabled(bool isMotionEnabled); // Set the value to true if the body can move
|
|
|
|
bool getIsCollisionEnabled() const; // Return true if the body can collide with others bodies
|
|
|
|
void setIsCollisionEnabled(bool isCollisionEnabled); // Set the isCollisionEnabled value
|
2010-09-01 16:37:13 +00:00
|
|
|
const BroadBoundingVolume* getBroadBoundingVolume() const; // Return the broad-phase bounding volume
|
|
|
|
const NarrowBoundingVolume* getNarrowBoundingVolume() const; // Return the narrow-phase bounding volume of the body
|
2009-02-09 09:08:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Method that return the mass of the body
|
2010-07-24 17:14:29 +00:00
|
|
|
inline double Body::getMass() const {
|
2009-02-09 09:08:33 +00:00
|
|
|
return mass;
|
|
|
|
};
|
|
|
|
|
2010-07-05 19:29:14 +00:00
|
|
|
// Return if the rigid body can move
|
|
|
|
inline bool Body::getIsMotionEnabled() const {
|
|
|
|
return isMotionEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the value to true if the body can move
|
|
|
|
inline void Body::setIsMotionEnabled(bool isMotionEnabled) {
|
|
|
|
this->isMotionEnabled = isMotionEnabled;
|
|
|
|
}
|
|
|
|
|
2009-02-09 09:08:33 +00:00
|
|
|
// Method that set the mass of the body
|
2010-07-24 17:14:29 +00:00
|
|
|
inline void Body::setMass(double mass) {
|
2009-02-09 09:08:33 +00:00
|
|
|
this->mass = mass;
|
|
|
|
}
|
|
|
|
|
2010-07-05 19:29:14 +00:00
|
|
|
// Return true if the body can collide with others bodies
|
|
|
|
inline bool Body::getIsCollisionEnabled() const {
|
|
|
|
return isCollisionEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the isCollisionEnabled value
|
|
|
|
inline void Body::setIsCollisionEnabled(bool isCollisionEnabled) {
|
|
|
|
this->isCollisionEnabled = isCollisionEnabled;
|
|
|
|
}
|
|
|
|
|
2010-08-05 15:06:34 +00:00
|
|
|
// Return the broad-phase bounding volume
|
2010-09-01 16:37:13 +00:00
|
|
|
inline const BroadBoundingVolume* Body::getBroadBoundingVolume() const {
|
2010-08-05 15:06:34 +00:00
|
|
|
return broadBoundingVolume;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the oriented bounding box of the rigid body
|
2010-09-01 16:37:13 +00:00
|
|
|
inline const NarrowBoundingVolume* Body::getNarrowBoundingVolume() const {
|
2010-08-05 15:06:34 +00:00
|
|
|
return narrowBoundingVolume;
|
|
|
|
}
|
|
|
|
|
2009-02-09 09:08:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|