1 | #include <math.h> |
---|
2 | |
---|
3 | /// @todo TAKE THIS OUT |
---|
4 | class 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 | |
---|
18 | class 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 | |
---|
57 | Matrix getTransposed() const { |
---|
58 | return Matrix( this->m11, this->m21, this->m31, |
---|
59 | this->m12, this->m22, this->m32, |
---|
60 | this->m13, this->m23, this->m33); |
---|
61 | } |
---|
62 | |
---|
63 | void toVectors(Vector& m1, Vector& m2, Vector& m3) const { |
---|
64 | m1 = Vector(this->m11, this->m12, this->m13); |
---|
65 | m2 = Vector(this->m21, this->m22, this->m23); |
---|
66 | m3 = Vector(this->m31, this->m32, this->m33); |
---|
67 | } |
---|
68 | |
---|
69 | Vector eigenValues() const; |
---|
70 | void eigenVectors(Vector& a, Vector& b, Vector& c) const; |
---|
71 | |
---|
72 | /// @todo optimize |
---|
73 | static Matrix identity() { return Matrix (1,0,0, 0,1,0, 0,0,1); } |
---|
74 | |
---|
75 | void debug() const; |
---|
76 | |
---|
77 | |
---|
78 | public: |
---|
79 | float m11; float m12; float m13; |
---|
80 | float m21; float m22; float m23; |
---|
81 | float m31; float m32; float m33; |
---|
82 | |
---|
83 | }; |
---|