[5664] | 1 | #include <math.h> |
---|
[5662] | 2 | |
---|
[5664] | 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; }; |
---|
[5662] | 10 | |
---|
[5664] | 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 | }; |
---|
[5662] | 15 | |
---|
[5664] | 16 | |
---|
| 17 | |
---|
[5662] | 18 | class Matrix |
---|
| 19 | { |
---|
[5663] | 20 | |
---|
[5662] | 21 | public: |
---|
[5663] | 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; |
---|
[5664] | 29 | }; |
---|
[5663] | 30 | |
---|
[5665] | 31 | Matrix operator+ (const Matrix& m) const { |
---|
[5663] | 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 | |
---|
[5665] | 37 | Matrix operator- (const Matrix& m) const { |
---|
[5663] | 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 | |
---|
[5665] | 43 | Matrix operator* (float k) const { |
---|
[5663] | 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 | |
---|
[5665] | 49 | Vector operator* (const Vector& v) const { |
---|
[5664] | 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 ); |
---|
[5663] | 53 | |
---|
[5664] | 54 | } |
---|
| 55 | |
---|
| 56 | |
---|
[5665] | 57 | Matrix getTransposed() const { |
---|
[5664] | 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 | |
---|
[5665] | 63 | void toVectors(Vector& m1, Vector& m2, Vector& m3) const { |
---|
[5664] | 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 | |
---|
[5665] | 69 | Vector eigenValues() const; |
---|
| 70 | void eigenVectors(Vector& a, Vector& b, Vector& c) const; |
---|
[5664] | 71 | |
---|
| 72 | /// @todo optimize |
---|
| 73 | static Matrix identity() { return Matrix (1,0,0, 0,1,0, 0,0,1); } |
---|
| 74 | |
---|
[5663] | 75 | void debug() const; |
---|
| 76 | |
---|
| 77 | |
---|
| 78 | public: |
---|
[5662] | 79 | float m11; float m12; float m13; |
---|
| 80 | float m21; float m22; float m23; |
---|
| 81 | float m31; float m32; float m33; |
---|
| 82 | |
---|
| 83 | }; |
---|