doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Ode.h
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
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.
13 
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.
18 
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/>.
21 
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.
23 
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.
25 
26 ===========================================================================
27 */
28 
29 #ifndef __MATH_ODE_H__
30 #define __MATH_ODE_H__
31 
32 /*
33 ===============================================================================
34 
35  Numerical solvers for ordinary differential equations.
36 
37 ===============================================================================
38 */
39 
40 
41 //===============================================================
42 //
43 // idODE
44 //
45 //===============================================================
46 
47 typedef void (*deriveFunction_t)( const float t, const void *userData, const float *state, float *derivatives );
48 
49 class idODE {
50 
51 public:
52  virtual ~idODE( void ) {}
53 
54  virtual float Evaluate( const float *state, float *newState, float t0, float t1 ) = 0;
55 
56 protected:
57  int dimension; // dimension in floats allocated for
58  deriveFunction_t derive; // derive function
59  const void * userData; // client data
60 };
61 
62 //===============================================================
63 //
64 // idODE_Euler
65 //
66 //===============================================================
67 
68 class idODE_Euler : public idODE {
69 
70 public:
71  idODE_Euler( const int dim, const deriveFunction_t dr, const void *ud );
72  virtual ~idODE_Euler( void );
73 
74  virtual float Evaluate( const float *state, float *newState, float t0, float t1 );
75 
76 protected:
77  float * derivatives; // space to store derivatives
78 };
79 
80 //===============================================================
81 //
82 // idODE_Midpoint
83 //
84 //===============================================================
85 
86 class idODE_Midpoint : public idODE {
87 
88 public:
89  idODE_Midpoint( const int dim, const deriveFunction_t dr, const void *ud );
90  virtual ~idODE_Midpoint( void );
91 
92  virtual float Evaluate( const float *state, float *newState, float t0, float t1 );
93 
94 protected:
95  float * tmpState;
96  float * derivatives; // space to store derivatives
97 };
98 
99 //===============================================================
100 //
101 // idODE_RK4
102 //
103 //===============================================================
104 
105 class idODE_RK4 : public idODE {
106 
107 public:
108  idODE_RK4( const int dim, const deriveFunction_t dr, const void *ud );
109  virtual ~idODE_RK4( void );
110 
111  virtual float Evaluate( const float *state, float *newState, float t0, float t1 );
112 
113 protected:
114  float * tmpState;
115  float * d1; // derivatives
116  float * d2;
117  float * d3;
118  float * d4;
119 };
120 
121 //===============================================================
122 //
123 // idODE_RK4Adaptive
124 //
125 //===============================================================
126 
127 class idODE_RK4Adaptive : public idODE {
128 
129 public:
130  idODE_RK4Adaptive( const int dim, const deriveFunction_t dr, const void *ud );
131  virtual ~idODE_RK4Adaptive( void );
132 
133  virtual float Evaluate( const float *state, float *newState, float t0, float t1 );
134  void SetMaxError( const float err );
135 
136 protected:
137  float maxError; // maximum allowed error
138  float * tmpState;
139  float * d1; // derivatives
140  float * d1half;
141  float * d2;
142  float * d3;
143  float * d4;
144 };
145 
146 #endif /* !__MATH_ODE_H__ */
float * tmpState
Definition: Ode.h:114
idODE_RK4Adaptive(const int dim, const deriveFunction_t dr, const void *ud)
Definition: Ode.cpp:212
virtual ~idODE_RK4Adaptive(void)
Definition: Ode.cpp:230
float * derivatives
Definition: Ode.h:96
deriveFunction_t derive
Definition: Ode.h:58
virtual float Evaluate(const float *state, float *newState, float t0, float t1)=0
idODE_Midpoint(const int dim, const deriveFunction_t dr, const void *ud)
Definition: Ode.cpp:87
float * d1
Definition: Ode.h:115
idODE_Euler(const int dim, const deriveFunction_t dr, const void *ud)
Definition: Ode.cpp:43
virtual float Evaluate(const float *state, float *newState, float t0, float t1)
Definition: Ode.cpp:255
float * d2
Definition: Ode.h:141
int dimension
Definition: Ode.h:57
float * d4
Definition: Ode.h:118
virtual float Evaluate(const float *state, float *newState, float t0, float t1)
Definition: Ode.cpp:170
float * d2
Definition: Ode.h:116
float * d1
Definition: Ode.h:139
void(* deriveFunction_t)(const float t, const void *userData, const float *state, float *derivatives)
Definition: Ode.h:47
float * tmpState
Definition: Ode.h:138
float * d3
Definition: Ode.h:142
Definition: Ode.h:49
float maxError
Definition: Ode.h:137
virtual ~idODE_RK4(void)
Definition: Ode.cpp:157
Definition: Ode.h:105
virtual ~idODE(void)
Definition: Ode.h:52
idODE_RK4(const int dim, const deriveFunction_t dr, const void *ud)
Definition: Ode.cpp:141
float * d4
Definition: Ode.h:143
float * derivatives
Definition: Ode.h:77
virtual ~idODE_Euler(void)
Definition: Ode.cpp:55
static WindowRef ValidModeCallbackProc inCallback OSStatus err
void SetMaxError(const float err)
Definition: Ode.cpp:244
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
virtual float Evaluate(const float *state, float *newState, float t0, float t1)
Definition: Ode.cpp:110
const void * userData
Definition: Ode.h:59
float * tmpState
Definition: Ode.h:95
virtual ~idODE_Midpoint(void)
Definition: Ode.cpp:100
float * d1half
Definition: Ode.h:140
float * d3
Definition: Ode.h:117
GLdouble GLdouble t
Definition: glext.h:2943
virtual float Evaluate(const float *state, float *newState, float t0, float t1)
Definition: Ode.cpp:64