Add the getInertiaTensorWorld() and getInertiaTensorInverseWorld methods
git-svn-id: https://reactphysics3d.googlecode.com/svn/trunk@338 92aac97c-a6ce-11dd-a772-7fcde58d38e6
This commit is contained in:
parent
53ed7b1b3a
commit
0f38e643a3
|
@ -24,9 +24,9 @@
|
||||||
using namespace reactphysics3d;
|
using namespace reactphysics3d;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
RigidBody::RigidBody(const Vector3D& position, const Quaternion& orientation, const Kilogram& mass, const Matrix3x3& inertiaTensor, const OBB& obb)
|
RigidBody::RigidBody(const Vector3D& position, const Quaternion& orientation, const Kilogram& mass, const Matrix3x3& inertiaTensorLocal, const OBB& obb)
|
||||||
: Body(mass), inertiaTensor(inertiaTensor), currentBodyState(position, orientation, inertiaTensor.getInverse(), Kilogram(1.0/mass.getValue())),
|
: Body(mass), inertiaTensorLocal(inertiaTensorLocal), currentBodyState(position, orientation, inertiaTensorLocal.getInverse(), Kilogram(1.0/mass.getValue())),
|
||||||
previousBodyState(position, orientation, inertiaTensor.getInverse(), Kilogram(1.0/mass.getValue())), obb(obb) {
|
previousBodyState(position, orientation, inertiaTensorLocal.getInverse(), Kilogram(1.0/mass.getValue())), obb(obb) {
|
||||||
|
|
||||||
isMotionEnabled = true;
|
isMotionEnabled = true;
|
||||||
isCollisionEnabled = true;
|
isCollisionEnabled = true;
|
||||||
|
@ -40,7 +40,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy-constructor
|
// Copy-constructor
|
||||||
RigidBody::RigidBody(const RigidBody& rigidBody) : Body(rigidBody), inertiaTensor(rigidBody.inertiaTensor),
|
RigidBody::RigidBody(const RigidBody& rigidBody) : Body(rigidBody), inertiaTensorLocal(rigidBody.inertiaTensorLocal),
|
||||||
currentBodyState(rigidBody.currentBodyState), previousBodyState(rigidBody.previousBodyState), obb(rigidBody.obb) {
|
currentBodyState(rigidBody.currentBodyState), previousBodyState(rigidBody.previousBodyState), obb(rigidBody.obb) {
|
||||||
this->isMotionEnabled = rigidBody.isMotionEnabled;
|
this->isMotionEnabled = rigidBody.isMotionEnabled;
|
||||||
this->isCollisionEnabled = rigidBody.isCollisionEnabled;
|
this->isCollisionEnabled = rigidBody.isCollisionEnabled;
|
||||||
|
|
|
@ -43,7 +43,7 @@ namespace reactphysics3d {
|
||||||
*/
|
*/
|
||||||
class RigidBody : public Body {
|
class RigidBody : public Body {
|
||||||
private :
|
private :
|
||||||
Matrix3x3 inertiaTensor; // Inertia tensor of the body
|
Matrix3x3 inertiaTensorLocal; // Local inertia tensor of the body (in body coordinates)
|
||||||
BodyState currentBodyState; // Current body state
|
BodyState currentBodyState; // Current body state
|
||||||
BodyState previousBodyState; // Previous body state
|
BodyState previousBodyState; // Previous body state
|
||||||
bool isMotionEnabled; // True if the body can move
|
bool isMotionEnabled; // True if the body can move
|
||||||
|
@ -52,34 +52,54 @@ class RigidBody : public Body {
|
||||||
OBB obb; // Oriented bounding box that contains the rigid body
|
OBB obb; // Oriented bounding box that contains the rigid body
|
||||||
|
|
||||||
public :
|
public :
|
||||||
RigidBody(const Vector3D& position, const Quaternion& orientation, const Kilogram& mass, const Matrix3x3& inertiaTensor, const OBB& obb); // Constructor
|
RigidBody(const Vector3D& position, const Quaternion& orientation, const Kilogram& mass, const Matrix3x3& inertiaTensorLocal, const OBB& obb); // Constructor
|
||||||
RigidBody(const RigidBody& rigidBody); // Copy-constructor
|
RigidBody(const RigidBody& rigidBody); // Copy-constructor
|
||||||
virtual ~RigidBody(); // Destructor
|
virtual ~RigidBody(); // Destructor
|
||||||
|
|
||||||
Matrix3x3 getInertiaTensor() const; // Return the inertia tensor of the body
|
Matrix3x3 getInertiaTensorLocal() const; // Return the local inertia tensor of the body (in body coordinates)
|
||||||
void setInertiaTensor(const Matrix3x3& inertiaTensor); // Set the inertia tensor of the body
|
void setInertiaTensorLocal(const Matrix3x3& inertiaTensorLocal); // Set the local inertia tensor of the body (in body coordinates)
|
||||||
BodyState& getCurrentBodyState(); // Return a reference to the current state of the body
|
Matrix3x3 getInertiaTensorWorld() const; // Return the inertia tensor in world coordinates
|
||||||
BodyState& getPreviousBodyState(); // TODO : DELETE THIS
|
Matrix3x3 getInertiaTensorInverseWorld() const; // Return the inverse of the inertia tensor in world coordinates
|
||||||
void setInterpolationFactor(double factor); // Set the interpolation factor of the body
|
BodyState& getCurrentBodyState(); // Return a reference to the current state of the body
|
||||||
BodyState getInterpolatedState() const; // Compute and return the interpolated state
|
BodyState& getPreviousBodyState(); // TODO : DELETE THIS
|
||||||
bool getIsMotionEnabled() const; // Return if the rigid body can move
|
void setInterpolationFactor(double factor); // Set the interpolation factor of the body
|
||||||
void setIsMotionEnabled(bool isMotionEnabled); // Set the value to true if the body can move
|
BodyState getInterpolatedState() const; // Compute and return the interpolated state
|
||||||
void setLinearVelocity(const Vector3D& linearVelocity); // Set the linear velocity of the rigid body
|
bool getIsMotionEnabled() const; // Return if the rigid body can move
|
||||||
void updatePreviousBodyState(); // Update the previous body state of the body
|
void setIsMotionEnabled(bool isMotionEnabled); // Set the value to true if the body can move
|
||||||
const OBB* const getOBB() const; // Return the oriented bounding box of the rigid body
|
void setLinearVelocity(const Vector3D& linearVelocity); // Set the linear velocity of the rigid body
|
||||||
void update(); // Update the rigid body in order to reflect a change in the body state
|
void updatePreviousBodyState(); // Update the previous body state of the body
|
||||||
|
const OBB* const getOBB() const; // Return the oriented bounding box of the rigid body
|
||||||
|
void update(); // Update the rigid body in order to reflect a change in the body state
|
||||||
};
|
};
|
||||||
|
|
||||||
// --- Inline functions --- //
|
// --- Inline functions --- //
|
||||||
|
|
||||||
// Return the inertia tensor of the body
|
// Return the local inertia tensor of the body (in body coordinates)
|
||||||
inline Matrix3x3 RigidBody::getInertiaTensor() const {
|
inline Matrix3x3 RigidBody::getInertiaTensorLocal() const {
|
||||||
return inertiaTensor;
|
return inertiaTensorLocal;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the inertia tensor of the body
|
// Set the local inertia tensor of the body (in body coordinates)
|
||||||
inline void RigidBody::setInertiaTensor(const Matrix3x3& inertiaTensor) {
|
inline void RigidBody::setInertiaTensorLocal(const Matrix3x3& inertiaTensorLocal) {
|
||||||
this->inertiaTensor = inertiaTensor;
|
this->inertiaTensorLocal = inertiaTensorLocal;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the inertia tensor in world coordinates
|
||||||
|
// The inertia tensor I_w in world coordinates in computed with the local inertia tensor I_b in body coordinates
|
||||||
|
// by I_w = R * I_b * R^T
|
||||||
|
// where R is the rotation matrix (and R^T its transpose) of the current orientation quaternion of the body
|
||||||
|
inline Matrix3x3 RigidBody::getInertiaTensorWorld() const {
|
||||||
|
// Compute and return the inertia tensor in world coordinates
|
||||||
|
return currentBodyState.getOrientation().getMatrix() * inertiaTensorLocal * currentBodyState.getOrientation().getMatrix().getTranspose();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the inverse of the inertia tensor in world coordinates
|
||||||
|
// The inertia tensor I_w in world coordinates in computed with the local inverse inertia tensor I_b^-1 in body coordinates
|
||||||
|
// by I_w = R * I_b^-1 * R^T
|
||||||
|
// where R is the rotation matrix (and R^T its transpose) of the current orientation quaternion of the body
|
||||||
|
inline Matrix3x3 RigidBody::getInertiaTensorInverseWorld() const {
|
||||||
|
// Compute and return the inertia tensor in world coordinates
|
||||||
|
return currentBodyState.getOrientation().getMatrix() * currentBodyState.getInertiaTensorInverse() * currentBodyState.getOrientation().getMatrix().getTranspose();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return a reference to the current state of the body
|
// Return a reference to the current state of the body
|
||||||
|
|
Loading…
Reference in New Issue
Block a user