]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/RK4.hh
random changes
[chaz/yoink] / src / Moof / RK4.hh
index 00c0b649c9406414dd7a56593322b59bb1f8b780..806127ecc977c1388b2dcef37f838f2658f86f77 100644 (file)
@@ -34,9 +34,9 @@
 
 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);
@@ -64,7 +64,24 @@ inline D evaluate(const S& state,  Scalar t, Scalar dt, const D& derivative)
 
 
 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);
@@ -75,15 +92,6 @@ inline void integrate(S& state, Scalar t, Scalar dt)
 }
 
 
-//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_
This page took 0.018159 seconds and 4 git commands to generate.