-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _MOOF_MATH_HH_
#define _MOOF_MATH_HH_
* General math-related types and functions.
*/
+#if HAVE_CONFIG_H
#include "config.h"
+#endif
#include <cmath>
#include <cml/cml.h>
#include <SDL/SDL_opengl.h>
-
#if ENABLE_DOUBLE_PRECISION
typedef GLdouble GLscalar;
#define GL_SCALAR GL_DOUBLE
using namespace cml;
-
typedef GLscalar scalar;
typedef vector< scalar, fixed<2> > vector2;
typedef matrix< scalar, fixed<3,3>, col_basis, col_major > matrix3;
typedef matrix< scalar, fixed<4,4>, col_basis, col_major > matrix4;
-typedef quaternion< scalar, fixed<>, vector_first, positive_cross > quaternion;
+typedef quaternion< scalar, fixed<>, vector_first, positive_cross > quaternion;
typedef constants<scalar> constants;
-
inline vector3 demote(const vector4& vec)
{
return vector3(vec[0], vec[1], vec[2]);
}
-// Here are some 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:
+// Here are some 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 calculate_derivative(Derivative_Type& derivative, scalar absoluteTime);
// void step(const Derivative_Type& derivative, scalar deltaTime);
return evaluate<S,D>(state, t + dt);
}
-
template <class S, class D>
inline void euler(S& state, scalar t, scalar dt)
{
D a = evaluate<S,D>(state, t);
-
state.step(a, dt);
}
{
D a = evaluate<S,D>(state, t);
D b = evaluate<S,D>(state, t, dt * SCALAR(0.5), a);
-
state.step(b, dt);
}
D b = evaluate<S,D>(state, t, dt * SCALAR(0.5), a);
D c = evaluate<S,D>(state, t, dt * SCALAR(0.5), b);
D d = evaluate<S,D>(state, t, dt, c);
-
state.step((a + (b + c) * SCALAR(2.0) + d) * SCALAR(1.0/6.0), dt);
}