]> git.mxchange.org Git - flightgear.git/blob - src/FDM/YASim/Math.hpp
Initial revision of Andy Ross's YASim code. This is (Y)et (A)nother Flight
[flightgear.git] / src / FDM / YASim / Math.hpp
1 #ifndef _MATH_HPP
2 #define _MATH_HPP
3
4 namespace yasim {
5
6 class Math
7 {
8 public:
9     // Simple wrappers around library routines
10     static float abs(float f);
11     static float sqrt(float f);
12     static float pow(float base, float exp);
13     static float ceil(float f);
14     static float sin(float f);
15     static float cos(float f);
16     static float tan(float f);
17     static float atan2(float y, float x);
18
19     // double variants of the above
20     static double abs(double f);
21     static double sqrt(double f);
22     static double pow(double base, double exp);
23     static double ceil(double f);
24     static double sin(double f);
25     static double cos(double f);
26     static double tan(double f);
27     static double atan2(double y, double x);
28
29     // Some 3D vector stuff.  In all cases, it is permissible for the
30     // "out" vector to be the same as one of the inputs.
31     static void  set3(float* v, float* out);
32     static float dot3(float* a, float* b);
33     static void  cross3(float* a, float* b, float* out);
34     static void  mul3(float scalar, float* v, float* out);
35     static void  add3(float* a, float* b, float* out);
36     static void  sub3(float* a, float* b, float* out);
37     static float mag3(float* v);
38     static void  unit3(float* v, float* out);
39
40     // Matrix array convention: 0 1 2
41     //                          3 4 5
42     //                          6 7 8
43
44     // Multiply two matrices
45     static void mmul33(float* a, float* b, float* out);
46
47     // Multiply by vector
48     static void vmul33(float* m, float* v, float* out);
49
50     // Multiply the vector by the matrix transpose.  Or pre-multiply the
51     // matrix by v as a row vector.  Same thing.
52     static void tmul33(float* m, float* v, float* out);
53
54     // Invert matrix
55     static void invert33(float* m, float* out);
56
57     // Transpose matrix (for an orthonormal orientation matrix, this
58     // is the same as the inverse).
59     static void trans33(float* m, float* out);
60
61     // Generates an orthonormal basis:
62     //   xOut becomes the unit vector in the direction of x
63     //   yOut is perpendicular to xOut in the x/y plane
64     //   zOut becomes the unit vector: (xOut cross yOut)
65     static void ortho33(float* x, float* y,
66                         float* xOut, float* yOut, float* zOut);
67 };
68
69 }; // namespace yasim
70 #endif // _MATH_HPP