00001 00003 // 00004 // -= ODE solver using Euler's Method =- 00005 // 00006 // Definition: "a 1st order ordinary differential equation solver" 00007 // 00009 // 00010 // $RCSfile: EulerODEsolver.h,v $ 00011 // $Date: 2002/01/10 03:10:47 $ 00012 // $Revision: 1.4 $ 00013 // Copyright (C) 1998, 1999, 2000 Kevin Meinert, kevin@vrsource.org 00014 // 00015 // This library is free software; you can redistribute it and/or 00016 // modify it under the terms of the GNU Library General Public 00017 // License as published by the Free Software Foundation; either 00018 // version 2 of the License, or (at your option) any later version. 00019 // 00020 // This library is distributed in the hope that it will be useful, 00021 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00023 // Library General Public License for more details. 00024 // 00025 // You should have received a copy of the GNU Library General Public 00026 // License along with this library; if not, write to the Free 00027 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00028 // 00030 #ifndef EULER_METHOD 00031 #define EULER_METHOD 00032 00033 #include "ani/Dynamics/ODEsolver.h" 00034 00035 namespace ani 00036 { 00037 //: Euler's algorithm is simple, fast, but unstable at times. 00038 // if you need stability, use RungeKutta 00039 template <class _item> 00040 class EulerODEsolver : public ODEsolver<_item> 00041 { 00042 public: 00043 EulerODEsolver<_item>() {} 00044 virtual ~EulerODEsolver<_item>() {} 00045 00046 // dx = dx/dt*currentState * changeInTime 00047 // nextState = currentState = currentState + dx 00048 // before executing this function, 00049 // - you must have zeroed all forces, 00050 // - run each operator on the particle system 00051 virtual void exec( _item& currentState, float timeDelta ) 00052 { 00053 //: changeInState = timeDelta * func( currentState, currentTime ) 00054 // f = func(..., ...) 00055 f.computeDerivative( currentState, timeDelta * 1.0f ); 00056 // changeInState = timeDelta * f 00057 changeInState.multiplyPhase( f, timeDelta ); 00058 00059 //: nextState = currentState + changeInState 00060 currentState.addPhase( changeInState ); 00061 currentState.normalize(); 00062 } 00063 00064 // used to compute the change in currentState 00065 _item changeInState; 00066 00067 // temporary used to catch the value of the derivitive function (computeDerivative) 00068 _item f; 00069 }; 00070 }; 00071 #endif