git-svn-id: https://reactphysics3d.googlecode.com/svn/trunk@208 92aac97c-a6ce-11dd-a772-7fcde58d38e6
This commit is contained in:
parent
3667a9b291
commit
dd2ca4e5d0
sources/reactphysics3d/integration
|
@ -18,35 +18,35 @@
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
// Libraries
|
// Libraries
|
||||||
#include "Euler.h"
|
#include "ExplicitEuler.h"
|
||||||
|
|
||||||
// We want to use the ReactPhysics3D namespace
|
// We want to use the ReactPhysics3D namespace
|
||||||
using namespace reactphysics3d;
|
using namespace reactphysics3d;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Euler::Euler() {
|
ExplicitEuler::ExplicitEuler() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy-constructor
|
// Copy-constructor
|
||||||
Euler::Euler(const Euler& euler) {
|
ExplicitEuler::ExplicitEuler(const ExplicitEuler& euler) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
Euler::~Euler() {
|
ExplicitEuler::~ExplicitEuler() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Integrate a body state over time. This method use the Euler integration algorithm
|
// Integrate a body state over time. This method use the explicit Euler integration algorithm
|
||||||
void Euler::integrate(BodyState& bodyState, const Time& time, const Time& timeStep) {
|
void ExplicitEuler::integrate(BodyState& bodyState, const Time& time, const Time& timeStep) {
|
||||||
double dt = timeStep.getValue(); // Timestep
|
double dt = timeStep.getValue(); // Timestep
|
||||||
|
|
||||||
// Compute the integrated body state
|
// Compute the integrated body state
|
||||||
bodyState.setPosition(bodyState.getPosition() + bodyState.getLinearVelocity() * dt);
|
bodyState.setPosition(bodyState.getPosition() + bodyState.getLinearVelocity() * dt);
|
||||||
bodyState.setLinearMomentum(bodyState.getLinearMomentum() + bodyState.computeForce(time) * dt);
|
bodyState.setLinearMomentum(bodyState.getLinearMomentum() + bodyState.getForce() * dt);
|
||||||
bodyState.setOrientation(bodyState.getOrientation() + bodyState.getSpin() * dt);
|
bodyState.setOrientation(bodyState.getOrientation() + bodyState.getSpin() * dt);
|
||||||
bodyState.setAngularMomentum(bodyState.getAngularMomentum() + bodyState.computeTorque(time) * dt);
|
bodyState.setAngularMomentum(bodyState.getAngularMomentum() + bodyState.getTorque() * dt);
|
||||||
|
|
||||||
// Recalculate the secondary values of the body state
|
// Recalculate the secondary values of the body state
|
||||||
bodyState.recalculate();
|
bodyState.recalculate();
|
||||||
|
|
|
@ -17,33 +17,35 @@
|
||||||
* along with ReactPhysics3D. If not, see <http://www.gnu.org/licenses/>. *
|
* along with ReactPhysics3D. If not, see <http://www.gnu.org/licenses/>. *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
#ifndef EULER_H
|
#ifndef EXPLICITEULER_H
|
||||||
#define EULER_H
|
#define EXPLICITEULER_H
|
||||||
|
|
||||||
// Libraries
|
// Libraries
|
||||||
#include "IntegrationAlgorithm.h"
|
#include "IntegrationAlgorithm.h"
|
||||||
#include "../body/BodyState.h"
|
#include "../body/BodyState.h"
|
||||||
#include "../body/DerivativeBodyState.h"
|
|
||||||
|
// TODO : Test explicit-Euler integrator (change has been made : computeForce(time) and computeTorque(time)
|
||||||
|
// replaced by getForce() and getTorque().
|
||||||
|
|
||||||
// Namespace ReactPhysics3D
|
// Namespace ReactPhysics3D
|
||||||
namespace reactphysics3d {
|
namespace reactphysics3d {
|
||||||
|
|
||||||
/* -------------------------------------------------------------------
|
/* -------------------------------------------------------------------
|
||||||
Class Euler :
|
Class ExplicitEuler :
|
||||||
This class will be used to solve the differential equation of
|
This class will be used to solve the differential equation of
|
||||||
movement by integrating a body state. This class implements
|
movement by integrating a body state. This class implements
|
||||||
the Euler algorithm. It's important to undersand that Euler
|
the explicit Euler algorithm. It's important to undersand that this
|
||||||
algorithm should be used only for testing purpose because the
|
algorithm should be used only for testing purpose because the
|
||||||
Euler algorithm is not a good one.
|
explicit Euler algorithm can be unstable.
|
||||||
-------------------------------------------------------------------
|
-------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
class Euler : public IntegrationAlgorithm {
|
class ExplicitEuler : public IntegrationAlgorithm {
|
||||||
private :
|
private :
|
||||||
|
|
||||||
public :
|
public :
|
||||||
Euler(); // Constructor
|
ExplicitEuler(); // Constructor
|
||||||
Euler(const Euler& euler); // Copy-constructor
|
ExplicitEuler(const ExplicitEuler& euler); // Copy-constructor
|
||||||
virtual ~Euler(); // Destructor
|
virtual ~ExplicitEuler(); // Destructor
|
||||||
|
|
||||||
void integrate(BodyState& bodyState, const Time& t, const Time& dt); // Integrate a body state over time
|
void integrate(BodyState& bodyState, const Time& t, const Time& dt); // Integrate a body state over time
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user