2 ===========================================================================
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
26 ===========================================================================
29 #ifndef __MATH_ODE_H__
30 #define __MATH_ODE_H__
33 ===============================================================================
35 Numerical solvers for ordinary differential equations.
37 ===============================================================================
41 //===============================================================
45 //===============================================================
47 typedef void (*deriveFunction_t)( const float t, const void *userData, const float *state, float *derivatives );
52 virtual ~idODE( void ) {}
54 virtual float Evaluate( const float *state, float *newState, float t0, float t1 ) = 0;
57 int dimension; // dimension in floats allocated for
58 deriveFunction_t derive; // derive function
59 const void * userData; // client data
62 //===============================================================
66 //===============================================================
68 class idODE_Euler : public idODE {
71 idODE_Euler( const int dim, const deriveFunction_t dr, const void *ud );
72 virtual ~idODE_Euler( void );
74 virtual float Evaluate( const float *state, float *newState, float t0, float t1 );
77 float * derivatives; // space to store derivatives
80 //===============================================================
84 //===============================================================
86 class idODE_Midpoint : public idODE {
89 idODE_Midpoint( const int dim, const deriveFunction_t dr, const void *ud );
90 virtual ~idODE_Midpoint( void );
92 virtual float Evaluate( const float *state, float *newState, float t0, float t1 );
96 float * derivatives; // space to store derivatives
99 //===============================================================
103 //===============================================================
105 class idODE_RK4 : public idODE {
108 idODE_RK4( const int dim, const deriveFunction_t dr, const void *ud );
109 virtual ~idODE_RK4( void );
111 virtual float Evaluate( const float *state, float *newState, float t0, float t1 );
115 float * d1; // derivatives
121 //===============================================================
125 //===============================================================
127 class idODE_RK4Adaptive : public idODE {
130 idODE_RK4Adaptive( const int dim, const deriveFunction_t dr, const void *ud );
131 virtual ~idODE_RK4Adaptive( void );
133 virtual float Evaluate( const float *state, float *newState, float t0, float t1 );
134 void SetMaxError( const float err );
137 float maxError; // maximum allowed error
139 float * d1; // derivatives
146 #endif /* !__MATH_ODE_H__ */