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

This commit is contained in:
chappuis.daniel 2009-11-07 16:25:26 +00:00
parent b1acf4dd0d
commit 09d03cdc70
2 changed files with 110 additions and 0 deletions

View File

@ -0,0 +1,56 @@
/****************************************************************************
* 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 "SemiImplicitEuler.h"
// We want to use the ReactPhysics3D namespace
using namespace reactphysics3d;
// Constructor
SemiImplicitEuler::SemiImplicitEuler() {
}
// Copy-constructor
SemiImplicitEuler::SemiImplicitEuler(const SemiImplicitEuler& euler) {
}
// Destructor
SemiImplicitEuler::~SemiImplicitEuler() {
}
// Integrate a body state over time. This method use the semi-implicit Euler integration algorithm
void SemiImplicitEuler::integrate(BodyState& bodyState, const Time& time, const Time& timeStep) {
double dt = timeStep.getValue(); // Timestep
// Compute the integrated body state
bodyState.setLinearMomentum(bodyState.getLinearMomentum() + bodyState.getForce() * dt);
bodyState.setAngularMomentum(bodyState.getAngularMomentum() + bodyState.getTorque() * dt);
// Recalculate the secondary values of the body state
bodyState.recalculate();
// Compute the integrated position and orientation
bodyState.setPosition(bodyState.getPosition() + bodyState.getLinearVelocity() * dt);
bodyState.setOrientation(bodyState.getOrientation() + bodyState.getSpin() * dt);
}

View File

@ -0,0 +1,54 @@
/****************************************************************************
* 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 SEMIIMPLICITEULER_H
#define SEMIIMPLICITEULER_H
// Libraries
#include "IntegrationAlgorithm.h"
#include "../body/BodyState.h"
// Namespace ReactPhysics3D
namespace reactphysics3d {
// TODO : Test the semi-implicit Euler
/* -------------------------------------------------------------------
Class SemiImplicitEuler :
This class will be used to solve the differential equation of
movement by integrating a body state. This class implements
the semi-implicit Euler algorithm. It's a first order integrator
algorithm and it's always stable.
-------------------------------------------------------------------
*/
class SemiImplicitEuler : public IntegrationAlgorithm {
private :
public :
SemiImplicitEuler(); // Constructor
SemiImplicitEuler(const SemiImplicitEuler& euler); // Copy-constructor
virtual ~SemiImplicitEuler(); // Destructor
void integrate(BodyState& bodyState, const Time& t, const Time& dt); // Integrate a body state over time
};
}
#endif