git-svn-id: https://reactphysics3d.googlecode.com/svn/trunk@75 92aac97c-a6ce-11dd-a772-7fcde58d38e6
This commit is contained in:
parent
06b57b2c99
commit
ee2cd6ff0b
|
@ -20,6 +20,9 @@
|
||||||
#ifndef BODY_H
|
#ifndef BODY_H
|
||||||
#define BODY_H
|
#define BODY_H
|
||||||
|
|
||||||
|
// Libraries
|
||||||
|
#include "../physics/physics.h"
|
||||||
|
|
||||||
// Namespace reactphysics3d
|
// Namespace reactphysics3d
|
||||||
namespace reactphysics3d {
|
namespace reactphysics3d {
|
||||||
|
|
||||||
|
@ -31,23 +34,26 @@ namespace reactphysics3d {
|
||||||
*/
|
*/
|
||||||
class Body {
|
class Body {
|
||||||
private :
|
private :
|
||||||
double mass; // Mass of the body
|
Kilogram mass; // Mass of the body
|
||||||
|
|
||||||
public :
|
public :
|
||||||
Body(double mass); // Constructor
|
Body(Kilogram mass); // Constructor
|
||||||
double getMass(); // Return the mass of the body
|
Body(const Body& body); // Copy-constructor
|
||||||
void setMass(double mass); // Set the mass of the body
|
virtual ~Body(); // Destructor
|
||||||
|
|
||||||
|
Kilogram getMass(); // Return the mass of the body
|
||||||
|
void setMass(Kilogram mass); // Set the mass of the body
|
||||||
};
|
};
|
||||||
|
|
||||||
// --- Inlines function --- //
|
// --- Inlines function --- //
|
||||||
|
|
||||||
// Method that return the mass of the body
|
// Method that return the mass of the body
|
||||||
inline double Body::getMass() {
|
inline Kilogram Body::getMass() {
|
||||||
return mass;
|
return mass;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Method that set the mass of the body
|
// Method that set the mass of the body
|
||||||
inline void Body::setMass(double mass) {
|
inline void Body::setMass(Kilogram mass) {
|
||||||
this->mass = mass;
|
this->mass = mass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,23 +24,17 @@
|
||||||
using namespace reactphysics3d;
|
using namespace reactphysics3d;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
BodyState::BodyState(const Vector3D& position, const Matrix3x3& inertiaTensorInverse, double massInverse) {
|
BodyState::BodyState(const Vector3D& position, const Matrix3x3& inertiaTensorInverse, const Kilogram& massInverse)
|
||||||
this->position = position;
|
: position(position), inertiaTensorInverse(inertiaTensorInverse), massInverse(massInverse) {
|
||||||
this->inertiaTensorInverse = inertiaTensorInverse;
|
|
||||||
this->massInverse = massInverse;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy-constructor
|
// Copy-constructor
|
||||||
BodyState::BodyState(const BodyState& bodyState) {
|
BodyState::BodyState(const BodyState& bodyState)
|
||||||
this->position = bodyState.position;
|
: position(bodyState.position), linearMomentum(bodyState.linearMomentum), linearVelocity(bodyState.linearVelocity),
|
||||||
this->linearMomentum = bodyState.linearMomentum;
|
angularVelocity(bodyState.angularVelocity), spin(bodyState.spin), inertiaTensorInverse(bodyState.inertiaTensorInverse),
|
||||||
this->orientation = bodyState.orientation;
|
massInverse(bodyState.massInverse) {
|
||||||
this->angularMomentum = bodyState.angularMomentum;
|
|
||||||
this->linearVelocity = bodyState.linearVelocity;
|
|
||||||
this->angularVelocity = bodyState.angularVelocity;
|
|
||||||
this->spin = bodyState.spin;
|
|
||||||
this->inertiaTensorInverse = bodyState.inertiaTensorInverse;
|
|
||||||
this->massInverse = bodyState.massInverse;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
|
|
||||||
// Libraries
|
// Libraries
|
||||||
#include "../mathematics/mathematics.h"
|
#include "../mathematics/mathematics.h"
|
||||||
|
#include "../physics/physics.h"
|
||||||
|
|
||||||
// Namespace reactphysics3d
|
// Namespace reactphysics3d
|
||||||
namespace reactphysics3d {
|
namespace reactphysics3d {
|
||||||
|
@ -46,12 +47,12 @@ class BodyState {
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
Matrix3x3 inertiaTensorInverse; // Inverse of the inertia tensor of the body
|
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 :
|
public :
|
||||||
BodyState(const Vector3D& position, const Matrix3x3& inertiaTensorInverse, double massInverse); // Constructor
|
BodyState(const Vector3D& position, const Matrix3x3& inertiaTensorInverse, const Kilogram& massInverse); // Constructor
|
||||||
BodyState(const BodyState& bodyState); // Copy-constructor
|
BodyState(const BodyState& bodyState); // Copy-constructor
|
||||||
virtual ~BodyState(); // Destructor
|
virtual ~BodyState(); // Destructor
|
||||||
|
|
||||||
Vector3D getPosition() const; // Return the position of the body
|
Vector3D getPosition() const; // Return the position of the body
|
||||||
void setPosition(const Vector3D& position); // Set 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
|
void setAngularMomentum(const Vector3D& angularMomentum); // Set the angular momentum
|
||||||
Vector3D getAngularVelocity() const; // Return the angular velocity
|
Vector3D getAngularVelocity() const; // Return the angular velocity
|
||||||
Quaternion getSpin() const; // Return the spin of the body
|
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 setInertiaTensorInverse(const Matrix3x3& inertiaTensorInverse); // Set the inverse of the inertia tensor
|
||||||
|
|
||||||
void recalculate(); // Recalculate the secondary values of the BodyState
|
void recalculate(); // Recalculate the secondary values of the BodyState
|
||||||
|
@ -122,7 +123,7 @@ inline Quaternion BodyState::getSpin() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the inverse of the mass
|
// Set the inverse of the mass
|
||||||
inline void BodyState::setMassInverse(double massInverse) {
|
inline void BodyState::setMassInverse(Kilogram massInverse) {
|
||||||
this->massInverse = massInverse;
|
this->massInverse = massInverse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,9 @@
|
||||||
|
|
||||||
// Libraries
|
// Libraries
|
||||||
#include "Body.h"
|
#include "Body.h"
|
||||||
|
#include "BodyState.h"
|
||||||
#include "../mathematics/mathematics.h"
|
#include "../mathematics/mathematics.h"
|
||||||
|
#include "../physics/physics.h"
|
||||||
|
|
||||||
// Namespace reactphysics3d
|
// Namespace reactphysics3d
|
||||||
namespace reactphysics3d {
|
namespace reactphysics3d {
|
||||||
|
@ -43,16 +45,40 @@ class RigidBody : public Body {
|
||||||
bool isCollisionEnabled; // True if the body can collide with others bodies
|
bool isCollisionEnabled; // True if the body can collide with others bodies
|
||||||
|
|
||||||
public :
|
public :
|
||||||
RigidBody(double mass); // Constructor
|
RigidBody(const Vector3D& position, const Kilogram& mass, const Matrix3x3& inertiaTensor); // 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 getInertiaTensor() const; // Return the inertia tensor of the body
|
||||||
void setInertiaTensor(const Matrix3x3& inertiaTensor); // Set 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 getCurrentBodyState() const; // Return the current state of the body
|
||||||
BodyState getPreviousState() const; // Return the previous 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user