Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5692 was 5692, checked in by bensch, 19 years ago

orxonox/trunk: no more valgrind warnings :)))))))

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