git-svn-id: https://reactphysics3d.googlecode.com/svn/trunk@75 92aac97c-a6ce-11dd-a772-7fcde58d38e6

This commit is contained in:
chappuis.daniel 2009-02-09 11:22:04 +00:00
parent 06b57b2c99
commit ee2cd6ff0b
4 changed files with 58 additions and 31 deletions

View File

@ -20,6 +20,9 @@
#ifndef BODY_H
#define BODY_H
// Libraries
#include "../physics/physics.h"
// Namespace reactphysics3d
namespace reactphysics3d {
@ -31,23 +34,26 @@ namespace reactphysics3d {
*/
class Body {
private :
double mass; // Mass of the body
Kilogram mass; // Mass of the body
public :
Body(double mass); // Constructor
double getMass(); // Return the mass of the body
void setMass(double mass); // Set the mass of the body
Body(Kilogram mass); // Constructor
Body(const Body& body); // Copy-constructor
virtual ~Body(); // Destructor
Kilogram getMass(); // Return the mass of the body
void setMass(Kilogram mass); // Set the mass of the body
};
// --- Inlines function --- //
// Method that return the mass of the body
inline double Body::getMass() {
inline Kilogram Body::getMass() {
return mass;
};
// Method that set the mass of the body
inline void Body::setMass(double mass) {
inline void Body::setMass(Kilogram mass) {
this->mass = mass;
}

View File

@ -24,23 +24,17 @@
using namespace reactphysics3d;
// Constructor
BodyState::BodyState(const Vector3D& position, const Matrix3x3& inertiaTensorInverse, double massInverse) {
this->position = position;
this->inertiaTensorInverse = inertiaTensorInverse;
this->massInverse = massInverse;
BodyState::BodyState(const Vector3D& position, const Matrix3x3& inertiaTensorInverse, const Kilogram& massInverse)
: position(position), inertiaTensorInverse(inertiaTensorInverse), massInverse(massInverse) {
}
// Copy-constructor
BodyState::BodyState(const BodyState& bodyState) {
this->position = bodyState.position;
this->linearMomentum = bodyState.linearMomentum;
this->orientation = bodyState.orientation;
this->angularMomentum = bodyState.angularMomentum;
this->linearVelocity = bodyState.linearVelocity;
this->angularVelocity = bodyState.angularVelocity;
this->spin = bodyState.spin;
this->inertiaTensorInverse = bodyState.inertiaTensorInverse;
this->massInverse = bodyState.massInverse;
BodyState::BodyState(const BodyState& bodyState)
: position(bodyState.position), linearMomentum(bodyState.linearMomentum), linearVelocity(bodyState.linearVelocity),
angularVelocity(bodyState.angularVelocity), spin(bodyState.spin), inertiaTensorInverse(bodyState.inertiaTensorInverse),
massInverse(bodyState.massInverse) {
}
// Destructor

View File

@ -22,6 +22,7 @@
// Libraries
#include "../mathematics/mathematics.h"
#include "../physics/physics.h"
// Namespace reactphysics3d
namespace reactphysics3d {
@ -46,12 +47,12 @@ class BodyState {
// Constants
Matrix3x3 inertiaTensorInverse; // Inverse of the inertia tensor of the body
double massInverse; // Inverse of the mass of the body
Kilogram massInverse; // Inverse of the mass of the body
public :
BodyState(const Vector3D& position, const Matrix3x3& inertiaTensorInverse, double massInverse); // Constructor
BodyState(const BodyState& bodyState); // Copy-constructor
virtual ~BodyState(); // Destructor
BodyState(const Vector3D& position, const Matrix3x3& inertiaTensorInverse, const Kilogram& massInverse); // Constructor
BodyState(const BodyState& bodyState); // Copy-constructor
virtual ~BodyState(); // Destructor
Vector3D getPosition() const; // Return the position of the body
void setPosition(const Vector3D& position); // Set the position of the body
@ -63,7 +64,7 @@ class BodyState {
void setAngularMomentum(const Vector3D& angularMomentum); // Set the angular momentum
Vector3D getAngularVelocity() const; // Return the angular velocity
Quaternion getSpin() const; // Return the spin of the body
void setMassInverse(double massInverse); // Set the inverse of the mass
void setMassInverse(Kilogram massInverse); // Set the inverse of the mass
void setInertiaTensorInverse(const Matrix3x3& inertiaTensorInverse); // Set the inverse of the inertia tensor
void recalculate(); // Recalculate the secondary values of the BodyState
@ -122,7 +123,7 @@ inline Quaternion BodyState::getSpin() const {
}
// Set the inverse of the mass
inline void BodyState::setMassInverse(double massInverse) {
inline void BodyState::setMassInverse(Kilogram massInverse) {
this->massInverse = massInverse;
}

View File

@ -22,7 +22,9 @@
// Libraries
#include "Body.h"
#include "BodyState.h"
#include "../mathematics/mathematics.h"
#include "../physics/physics.h"
// Namespace reactphysics3d
namespace reactphysics3d {
@ -43,16 +45,40 @@ class RigidBody : public Body {
bool isCollisionEnabled; // True if the body can collide with others bodies
public :
RigidBody(double mass); // Constructor
RigidBody(const RigidBody& rigidBody); // Copy-constructor
virtual ~RigidBody(); // Destructor
RigidBody(const Vector3D& position, const Kilogram& mass, const Matrix3x3& inertiaTensor); // Constructor
RigidBody(const RigidBody& rigidBody); // Copy-constructor
virtual ~RigidBody(); // Destructor
Matrix3x3 getInertiaTensor() const; // Return the inertia tensor of the body
void setInertiaTensor(const Matrix3x3& inertiaTensor); // Set the inertia tensor of the body
BodyState getCurrentState() const; // Return the current state of the body
BodyState getPreviousState() const; // Return the previous state of the body
BodyState getCurrentBodyState() const; // Return the current state of the body
BodyState getPreviousBodyState() const; // Return the previous state of the body
Vector3D computeForce(Time time) const; // Return the force on the body at time t
Vector3D computeTorque(Time time) const; // Return the torque on the body at time t
};
// --- Inline functions --- //
// Return the inertia tensor of the body
Matrix3x3 RigidBody::getInertiaTensor() const {
return inertiaTensor;
}
// Set the inertia tensor of the body
void RigidBody::setInertiaTensor(const Matrix3x3& inertiaTensor) {
this->inertiaTensor = inertiaTensor;
}
// Return the current state of the body
BodyState RigidBody::getCurrentBodyState() const {
return currentBodyState;
}
// Return the previous state of the body
BodyState RigidBody::getPreviousBodyState() const {
return previousBodyState;
}
}