Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: Matrix included into Project

File size: 2.3 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 ( float m11, float m12, float m13,
15             float m21, float m22, float m23,
16             float m31, float m32, float m33 )
17    {
18      this->m11 = m11; this->m12 = m12; this->m13 = m13;
19      this->m21 = m21; this->m22 = m22; this->m23 = m23;
20      this->m31 = m31; this->m32 = m32; this->m33 = m33;
21    };
22
23    Matrix operator+ (const Matrix& m) const {
24      return Matrix (this->m11 + m.m11, this->m12 + m.m12, this->m13 + m.m13,
25                     this->m21 + m.m21, this->m22 + m.m22, this->m23 + m.m23,
26                     this->m31 + m.m31, this->m32 + m.m32, this->m33 + m.m33);
27    }
28
29    Matrix operator- (const Matrix& m) const {
30      return Matrix (this->m11 - m.m11, this->m12 - m.m12, this->m13 - m.m13,
31                     this->m21 - m.m21, this->m22 - m.m22, this->m23 - m.m23,
32                     this->m31 - m.m31, this->m32 - m.m32, this->m33 - m.m33);
33    }
34
35    Matrix operator* (float k) const {
36      return Matrix(this->m11 - k, this->m12 - k, this->m13 - k,
37                    this->m21 - k, this->m22 - k, this->m23 - k,
38                    this->m31 - k, this->m32 - k, this->m33 - k);
39    }
40
41    Vector operator* (const Vector& v) const {
42      return Vector (this->m11*v.x + this->m12*v.y + this->m13*v.z,
43                     this->m21*v.x + this->m22*v.y + this->m23*v.z,
44                     this->m31*v.x + this->m32*v.y + this->m33*v.z );
45    }
46
47
48    Matrix getTransposed() const {
49      return Matrix( this->m11, this->m21, this->m31,
50                     this->m12, this->m22, this->m32,
51                     this->m13, this->m23, this->m33);
52    }
53
54    void toVectors(Vector& m1, Vector& m2, Vector& m3) const {
55      m1 = Vector(this->m11, this->m12, this->m13);
56      m2 = Vector(this->m21, this->m22, this->m23);
57      m3 = Vector(this->m31, this->m32, this->m33);
58    }
59
60    Vector getEigenValues() const;
61    void getEigenVectors(Vector& a, Vector& b, Vector& c) const;
62
63    /// @todo optimize
64    static Matrix identity() { return Matrix (1,0,0, 0,1,0, 0,0,1); }
65
66    void debug() const;
67
68
69  public:
70    float m11;    float m12;     float m13;
71    float m21;    float m22;     float m23;
72    float m31;    float m32;     float m33;
73
74};
Note: See TracBrowser for help on using the repository browser.