Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/math/matrix.h @ 5668

Last change on this file since 5668 was 5668, checked in by bensch, 18 years ago

orxonox/trunk: two of 3 eigenvectors

File size: 2.7 KB
Line 
1#include <math.h>
2
3/// @todo TAKE THIS OUT
4class Vector
5{
6  public:
7    Vector() {this->x = this->y = this->z = 0; };
8    Vector (float x, float y, float z) { this->x=x; this->y = y; this->z = z; };
9    inline const Vector& operator/= (float f) {if ((f == 0.0)) {this->x=0;this->y=0;this->z=0;} else {this->x /= f; this->y /= f; this->z /= f;} return *this; };
10
11    float x, y, z;
12    inline Vector cross (const Vector& v) const { return Vector(y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x ); }
13    inline float len() const { return sqrt (x*x+y*y+z*z); }
14};
15
16
17
18class Matrix
19{
20
21  public:
22    Matrix ( float m11, float m12, float m13,
23             float m21, float m22, float m23,
24             float m31, float m32, float m33 )
25    {
26      this->m11 = m11; this->m12 = m12; this->m13 = m13;
27      this->m21 = m21; this->m22 = m22; this->m23 = m23;
28      this->m31 = m31; this->m32 = m32; this->m33 = m33;
29    };
30
31    Matrix operator+ (const Matrix& m) const {
32      return Matrix (this->m11 + m.m11, this->m12 + m.m12, this->m13 + m.m13,
33                     this->m21 + m.m21, this->m22 + m.m22, this->m23 + m.m23,
34                     this->m31 + m.m31, this->m32 + m.m32, this->m33 + m.m33);
35    }
36
37    Matrix operator- (const Matrix& m) const {
38      return Matrix (this->m11 - m.m11, this->m12 - m.m12, this->m13 - m.m13,
39                     this->m21 - m.m21, this->m22 - m.m22, this->m23 - m.m23,
40                     this->m31 - m.m31, this->m32 - m.m32, this->m33 - m.m33);
41    }
42
43    Matrix operator* (float k) const {
44      return Matrix(this->m11 - k, this->m12 - k, this->m13 - k,
45                    this->m21 - k, this->m22 - k, this->m23 - k,
46                    this->m31 - k, this->m32 - k, this->m33 - k);
47    }
48
49    Vector operator* (const Vector& v) const {
50      return Vector (this->m11*v.x + this->m12*v.y + this->m13*v.z,
51                     this->m21*v.x + this->m22*v.y + this->m23*v.z,
52                     this->m31*v.x + this->m32*v.y + this->m33*v.z );
53    }
54
55
56    Matrix getTransposed() const {
57      return Matrix( this->m11, this->m21, this->m31,
58                     this->m12, this->m22, this->m32,
59                     this->m13, this->m23, this->m33);
60    }
61
62    void toVectors(Vector& m1, Vector& m2, Vector& m3) const {
63      m1 = Vector(this->m11, this->m12, this->m13);
64      m2 = Vector(this->m21, this->m22, this->m23);
65      m3 = Vector(this->m31, this->m32, this->m33);
66    }
67
68    Vector getEigenValues() const;
69    void getEigenVectors(Vector& a, Vector& b, Vector& c) const;
70
71    /// @todo optimize
72    static Matrix identity() { return Matrix (1,0,0, 0,1,0, 0,0,1); }
73
74    void debug() const;
75
76
77  public:
78    float m11;    float m12;     float m13;
79    float m21;    float m22;     float m23;
80    float m31;    float m32;     float m33;
81
82};
Note: See TracBrowser for help on using the repository browser.