Remove BodyState and DerivativeBodyState
git-svn-id: https://reactphysics3d.googlecode.com/svn/trunk@367 92aac97c-a6ce-11dd-a772-7fcde58d38e6
This commit is contained in:
parent
9987a5c659
commit
b9750898b2
|
@ -1,102 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
* Copyright (C) 2009 Daniel Chappuis *
|
|
||||||
****************************************************************************
|
|
||||||
* This file is part of ReactPhysics3D. *
|
|
||||||
* *
|
|
||||||
* ReactPhysics3D is free software: you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU Lesser General Public License as published *
|
|
||||||
* by the Free Software Foundation, either version 3 of the License, or *
|
|
||||||
* (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* ReactPhysics3D is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU Lesser General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License *
|
|
||||||
* along with ReactPhysics3D. If not, see <http://www.gnu.org/licenses/>. *
|
|
||||||
***************************************************************************/
|
|
||||||
|
|
||||||
// Libraries
|
|
||||||
#include "BodyState.h"
|
|
||||||
#include <cmath>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
// We want to use the ReactPhysics3D namespace
|
|
||||||
using namespace reactphysics3d;
|
|
||||||
|
|
||||||
// Constructor
|
|
||||||
BodyState::BodyState(const Vector3D& position, const Quaternion& orientation, const Matrix3x3& inertiaTensorInverse, const Kilogram& massInverse)
|
|
||||||
: position(position), orientation(orientation), inertiaTensorInverse(inertiaTensorInverse), massInverse(massInverse) {
|
|
||||||
|
|
||||||
// Recalculate the secondary values from the primary values
|
|
||||||
recalculate();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copy-constructor
|
|
||||||
BodyState::BodyState(const BodyState& bodyState)
|
|
||||||
: position(bodyState.position), linearMomentum(bodyState.linearMomentum), orientation(bodyState.orientation),
|
|
||||||
angularMomentum(bodyState.angularMomentum), linearVelocity(bodyState.linearVelocity),
|
|
||||||
angularVelocity(bodyState.angularVelocity), spin(bodyState.spin), inertiaTensorInverse(bodyState.inertiaTensorInverse),
|
|
||||||
massInverse(bodyState.massInverse), externalForce(bodyState.externalForce) {
|
|
||||||
}
|
|
||||||
|
|
||||||
// Destructor
|
|
||||||
BodyState::~BodyState() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Recalculate the secondary values of the BodyState when the primary values have changed
|
|
||||||
void BodyState::recalculate() {
|
|
||||||
|
|
||||||
// Compute the linear velocity
|
|
||||||
linearVelocity = linearMomentum * massInverse.getValue();
|
|
||||||
|
|
||||||
// Compute the angular velocity
|
|
||||||
angularVelocity = inertiaTensorInverse * angularMomentum;
|
|
||||||
|
|
||||||
// Normalize the orientation quaternion
|
|
||||||
orientation = orientation.getUnit();
|
|
||||||
|
|
||||||
// Compute the spin quaternion
|
|
||||||
spin = Quaternion(angularVelocity.getX(), angularVelocity.getY(), angularVelocity.getZ(), 0) * orientation * 0.5;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Compute the body state at time t + dt
|
|
||||||
// This method is used with integration methods that need to compute the state at a future
|
|
||||||
// time (like Runge-Kutta 4 integrator)
|
|
||||||
void BodyState::computeAtTime(const Time& timeStep, const DerivativeBodyState& lastDerivativeBodyState) {
|
|
||||||
|
|
||||||
double dt = timeStep.getValue(); // Timestep
|
|
||||||
|
|
||||||
// Compute the position at time t + dt
|
|
||||||
position = position + lastDerivativeBodyState.getLinearVelocity() * dt;
|
|
||||||
|
|
||||||
// Compute the linear momentum at time t + dt
|
|
||||||
linearMomentum = linearMomentum + lastDerivativeBodyState.getForce() * dt;
|
|
||||||
|
|
||||||
// Compute the orientation at time t + dt
|
|
||||||
orientation = orientation + lastDerivativeBodyState.getSpin() * dt;
|
|
||||||
|
|
||||||
// Compute the angular momentum at time t + dt
|
|
||||||
angularMomentum = angularMomentum + lastDerivativeBodyState.getTorque() * dt;
|
|
||||||
|
|
||||||
// Recalculate the secondary values of the body state
|
|
||||||
recalculate();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return the force on the body at time t
|
|
||||||
// This method is used with integration methods that need to compute the state at a future
|
|
||||||
// time (like Runge-Kutta 4 integrator)
|
|
||||||
Vector3D BodyState::computeForce(Time time) const {
|
|
||||||
// TODO : Implement this method (we want that the user of the library could define this method)
|
|
||||||
return externalForce;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return the torque on the body at time
|
|
||||||
// This method is used with integration methods that need to compute the state at a future
|
|
||||||
// time (like Runge-Kutta 4 integrator)
|
|
||||||
Vector3D BodyState::computeTorque(Time time) const {
|
|
||||||
// TODO : Implement this method (we want that the user of the library could define this method)
|
|
||||||
return externalTorque;
|
|
||||||
}
|
|
|
@ -1,204 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
* Copyright (C) 2009 Daniel Chappuis *
|
|
||||||
****************************************************************************
|
|
||||||
* This file is part of ReactPhysics3D. *
|
|
||||||
* *
|
|
||||||
* ReactPhysics3D is free software: you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU Lesser General Public License as published *
|
|
||||||
* by the Free Software Foundation, either version 3 of the License, or *
|
|
||||||
* (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* ReactPhysics3D is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU Lesser General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License *
|
|
||||||
* along with ReactPhysics3D. If not, see <http://www.gnu.org/licenses/>. *
|
|
||||||
***************************************************************************/
|
|
||||||
|
|
||||||
#ifndef BODYSTATE_H
|
|
||||||
#define BODYSTATE_H
|
|
||||||
|
|
||||||
// Libraries
|
|
||||||
#include "../mathematics/mathematics.h"
|
|
||||||
#include "../physics/physics.h"
|
|
||||||
#include "DerivativeBodyState.h"
|
|
||||||
|
|
||||||
// Namespace reactphysics3d
|
|
||||||
namespace reactphysics3d {
|
|
||||||
|
|
||||||
// TODO : Remove this class and put everything in the RigidBody class
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------
|
|
||||||
Class BodyState :
|
|
||||||
A BodyState contains all the dynamics values of a body.
|
|
||||||
-------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
class BodyState {
|
|
||||||
private :
|
|
||||||
// Primary values
|
|
||||||
Vector3D position; // Position of the body
|
|
||||||
Vector3D linearMomentum; // Linear momentum of the body
|
|
||||||
Quaternion orientation; // Orientation quaternion of the body
|
|
||||||
Vector3D angularMomentum; // Angular momentum of the body
|
|
||||||
Vector3D externalForce; // Current external force on the body
|
|
||||||
Vector3D externalTorque; // Current external torque on the body
|
|
||||||
|
|
||||||
// Secondary values
|
|
||||||
Vector3D linearVelocity; // Linear velocity of the body
|
|
||||||
Vector3D angularVelocity; // Angular velocity of the body
|
|
||||||
Quaternion spin; // Spin is the derivative of orientation quaternion over time.
|
|
||||||
|
|
||||||
// Constants
|
|
||||||
Matrix3x3 inertiaTensorInverse; // Inverse of the inertia tensor of the body
|
|
||||||
Kilogram massInverse; // Inverse of the mass of the body
|
|
||||||
|
|
||||||
public :
|
|
||||||
BodyState(const Vector3D& position, const Quaternion& orientation, 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
|
|
||||||
Vector3D getLinearMomentum() const; // Return the linear momemtum
|
|
||||||
void setLinearMomentum(const Vector3D& linearMomentum); // Set the linear momentum
|
|
||||||
Quaternion getOrientation() const; // Return the orientation quaternion
|
|
||||||
void setOrientation(const Quaternion& orientation); // Set the orientation quaternion
|
|
||||||
Vector3D getAngularMomentum() const; // Return the angular momentum
|
|
||||||
void setAngularMomentum(const Vector3D& angularMomentum); // Set the angular momentum
|
|
||||||
Vector3D getLinearVelocity() const; // Return the linear velocity
|
|
||||||
void setLinearVelocity(const Vector3D& linearVelocity); // TODO : Delete this
|
|
||||||
Vector3D getAngularVelocity() const; // Return the angular velocity
|
|
||||||
void setAngularVelocity(const Vector3D& angularVelocity);
|
|
||||||
Quaternion getSpin() const; // Return the spin of the body
|
|
||||||
void setSpin(const Quaternion& spin);
|
|
||||||
void setMassInverse(Kilogram massInverse); // Set the inverse of the mass
|
|
||||||
Matrix3x3 getInertiaTensorInverse() const; // Get the inverse of the inertia tensor
|
|
||||||
void setInertiaTensorInverse(const Matrix3x3& inertiaTensorInverse); // Set the inverse of the inertia tensor
|
|
||||||
Vector3D getExternalForce() const; // Return the current external force of the body
|
|
||||||
void setExternalForce(const Vector3D& force); // Set the current external force on the body
|
|
||||||
Vector3D getExternalTorque() const; // Return the current external torque of the body
|
|
||||||
void setExternalTorque(const Vector3D& torque); // Set the current external torque of the body
|
|
||||||
Kilogram getMassInverse() const; // TODO : Delete this
|
|
||||||
void recalculate(); // Recalculate the secondary values
|
|
||||||
// of the BodyState from the primary ones
|
|
||||||
void computeAtTime(const Time& timeStep,
|
|
||||||
const DerivativeBodyState& lastDerivativeBodyState); // Compute the body state at time t + dt
|
|
||||||
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
|
|
||||||
};
|
|
||||||
|
|
||||||
// --- Inlines functions --- //
|
|
||||||
|
|
||||||
// Return the position of the body
|
|
||||||
inline Vector3D BodyState::getPosition() const {
|
|
||||||
return position;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set the position of the body
|
|
||||||
inline void BodyState::setPosition(const Vector3D& position) {
|
|
||||||
this->position = position;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return the linear momentum of the body
|
|
||||||
inline Vector3D BodyState::getLinearMomentum() const {
|
|
||||||
return linearMomentum;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set the linear momentum of the body
|
|
||||||
inline void BodyState::setLinearMomentum(const Vector3D& linearMomentum) {
|
|
||||||
this->linearMomentum = linearMomentum;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return the orientation quaternion of the body
|
|
||||||
inline Quaternion BodyState::getOrientation() const {
|
|
||||||
return orientation;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set the orientation quaternion
|
|
||||||
inline void BodyState::setOrientation(const Quaternion& orientation) {
|
|
||||||
this->orientation = orientation;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return the angular momentum of the body
|
|
||||||
inline Vector3D BodyState::getAngularMomentum() const {
|
|
||||||
return angularMomentum;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set the angular momentum of the body
|
|
||||||
inline void BodyState::setAngularMomentum(const Vector3D& angularMomentum) {
|
|
||||||
this->angularMomentum = angularMomentum;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return the linear velocity
|
|
||||||
inline Vector3D BodyState::getLinearVelocity() const {
|
|
||||||
return linearVelocity;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void BodyState::setLinearVelocity(const Vector3D& linearVelocity) {
|
|
||||||
this->linearVelocity = linearVelocity;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return the angular velocity of the body
|
|
||||||
inline Vector3D BodyState::getAngularVelocity() const {
|
|
||||||
return angularVelocity;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void BodyState::setAngularVelocity(const Vector3D& angularVelocity) {
|
|
||||||
this->angularVelocity = angularVelocity;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return the spin of the body
|
|
||||||
inline Quaternion BodyState::getSpin() const {
|
|
||||||
return spin;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void BodyState::setSpin(const Quaternion& spin) {
|
|
||||||
this->spin = spin;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set the inverse of the mass
|
|
||||||
inline void BodyState::setMassInverse(Kilogram massInverse) {
|
|
||||||
this->massInverse = massInverse;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the inverse of the inertia tensor
|
|
||||||
inline Matrix3x3 BodyState::getInertiaTensorInverse() const {
|
|
||||||
return inertiaTensorInverse;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set the inverse of the inertia tensor
|
|
||||||
inline void BodyState::setInertiaTensorInverse(const Matrix3x3& inertiaTensorInverse) {
|
|
||||||
this->inertiaTensorInverse = inertiaTensorInverse;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return the external force on the body
|
|
||||||
inline Vector3D BodyState::getExternalForce() const {
|
|
||||||
return externalForce;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set the external force on the body
|
|
||||||
inline void BodyState::setExternalForce(const Vector3D& force) {
|
|
||||||
this->externalForce = force;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return the current external torque on the body
|
|
||||||
inline Vector3D BodyState::getExternalTorque() const {
|
|
||||||
return externalTorque;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set the current external torque on the body
|
|
||||||
inline void BodyState::setExternalTorque(const Vector3D& torque) {
|
|
||||||
this->externalTorque = torque;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// TODO : Delete this
|
|
||||||
inline Kilogram BodyState::getMassInverse() const {
|
|
||||||
return massInverse;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // End of the ReactPhysics3D namespace
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,43 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
* Copyright (C) 2009 Daniel Chappuis *
|
|
||||||
****************************************************************************
|
|
||||||
* This file is part of ReactPhysics3D. *
|
|
||||||
* *
|
|
||||||
* ReactPhysics3D is free software: you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU Lesser General Public License as published *
|
|
||||||
* by the Free Software Foundation, either version 3 of the License, or *
|
|
||||||
* (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* ReactPhysics3D is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU Lesser General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License *
|
|
||||||
* along with ReactPhysics3D. If not, see <http://www.gnu.org/licenses/>. *
|
|
||||||
***************************************************************************/
|
|
||||||
|
|
||||||
// Libraries
|
|
||||||
#include "DerivativeBodyState.h"
|
|
||||||
|
|
||||||
// We want to use the ReactPhysics3D namespace
|
|
||||||
using namespace reactphysics3d;
|
|
||||||
|
|
||||||
// Constructor
|
|
||||||
DerivativeBodyState::DerivativeBodyState(const Vector3D& linearVelocity, const Vector3D& force, const Vector3D& torque,
|
|
||||||
const Quaternion& spin) : linearVelocity(linearVelocity), force(force), torque(torque),
|
|
||||||
spin(spin) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copy-constructor
|
|
||||||
DerivativeBodyState::DerivativeBodyState(const DerivativeBodyState& derivativeBodyState)
|
|
||||||
: linearVelocity(derivativeBodyState.linearVelocity), force(derivativeBodyState.force),
|
|
||||||
torque(derivativeBodyState.torque), spin(derivativeBodyState.spin) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Destructor
|
|
||||||
DerivativeBodyState::~DerivativeBodyState() {
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,79 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
* Copyright (C) 2009 Daniel Chappuis *
|
|
||||||
****************************************************************************
|
|
||||||
* This file is part of ReactPhysics3D. *
|
|
||||||
* *
|
|
||||||
* ReactPhysics3D is free software: you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU Lesser General Public License as published *
|
|
||||||
* by the Free Software Foundation, either version 3 of the License, or *
|
|
||||||
* (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* ReactPhysics3D is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU Lesser General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License *
|
|
||||||
* along with ReactPhysics3D. If not, see <http://www.gnu.org/licenses/>. *
|
|
||||||
***************************************************************************/
|
|
||||||
|
|
||||||
#ifndef DERIVATIVEBODYSTATE_H
|
|
||||||
#define DERIVATIVEBODYSTATE_H
|
|
||||||
|
|
||||||
// Libraries
|
|
||||||
#include "../mathematics/mathematics.h"
|
|
||||||
|
|
||||||
// Namespace ReactPhysics3D
|
|
||||||
namespace reactphysics3d {
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------
|
|
||||||
Class DerivativeBodyState :
|
|
||||||
This class represents a derivative of a body state at time t.
|
|
||||||
This class is used in the numerical integrator to compute the
|
|
||||||
derivative of a body state at different times.
|
|
||||||
-------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
class DerivativeBodyState {
|
|
||||||
private :
|
|
||||||
Vector3D linearVelocity; // Linear velocity of the body
|
|
||||||
Vector3D force; // Force applied to the body
|
|
||||||
Vector3D torque; // Torque applied to the body
|
|
||||||
Quaternion spin; // Quaternion spin of the body
|
|
||||||
|
|
||||||
public :
|
|
||||||
DerivativeBodyState(const Vector3D& linearVelocity, const Vector3D& force, const Vector3D& torque,
|
|
||||||
const Quaternion& spin); // Constructor
|
|
||||||
DerivativeBodyState(const DerivativeBodyState& derivativeBodyState); // Copy-constructor
|
|
||||||
virtual ~DerivativeBodyState(); // Destructor
|
|
||||||
|
|
||||||
Vector3D getLinearVelocity() const; // Return the linear velocity
|
|
||||||
Vector3D getForce() const; // Return the force
|
|
||||||
Vector3D getTorque() const; // Return the torque
|
|
||||||
Quaternion getSpin() const; // Return the spin
|
|
||||||
};
|
|
||||||
|
|
||||||
// --- Inline functions --- //
|
|
||||||
|
|
||||||
// Return the linear velocity
|
|
||||||
inline Vector3D DerivativeBodyState::getLinearVelocity() const {
|
|
||||||
return linearVelocity;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return the force
|
|
||||||
inline Vector3D DerivativeBodyState::getForce() const {
|
|
||||||
return force;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return the torque
|
|
||||||
inline Vector3D DerivativeBodyState::getTorque() const {
|
|
||||||
return torque;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return the spin
|
|
||||||
inline Quaternion DerivativeBodyState::getSpin() const {
|
|
||||||
return spin;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
Loading…
Reference in New Issue
Block a user