namespace Mf {
-// Generic implementation of the RK4 integrator. To use, you need one type
-// representing the state and another containing the derivatives of the primary
-// state variables. The state class must implement these methods:
+// Generic implementations of a few simple integrators. To use, you need one
+// type representing the state and another containing the derivatives of the
+// primary state variables. The state class must implement these methods:
//
// void getDerivative(Derivative_Type& derivative, Scalar absoluteTime);
// void applyDerivative(const Derivative_Type& derivative, Scalar deltaTime);
template<typename S, typename D>
-inline void integrate(S& state, Scalar t, Scalar dt)
+inline void euler(S& state, Scalar t, Scalar dt)
+{
+ D a = evaluate<S,D>(state, t);
+
+ state.applyDerivative(a, dt);
+}
+
+template<typename S, typename D>
+inline void rk2(S& state, Scalar t, Scalar dt)
+{
+ D a = evaluate<S,D>(state, t);
+ D b = evaluate<S,D>(state, t, dt * 0.5, a);
+
+ state.applyDerivative(b, dt);
+}
+
+template<typename S, typename D>
+inline void rk4(S& state, Scalar t, Scalar dt)
{
D a = evaluate<S,D>(state, t);
D b = evaluate<S,D>(state, t, dt * 0.5, a);
}
-//template<typename T>
-//inline T spring(Scalar k, Scalar b)
-//{
- //current.force = -15 * (current.position - Mf::Vector2(200.0, 200.0))
- //- 15.0 * current.velocity;
- //return
-//}
-
-
} // namespace Mf
#endif // _MOOF_RK4_HH_