Changeset 5664 in orxonox.OLD for trunk/src/lib
- Timestamp:
- Nov 21, 2005, 3:59:12 AM (19 years ago)
- Location:
- trunk/src/lib/math
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/math/matrix.cc
r5663 r5664 4 4 #include "matrix.h" 5 5 6 7 class Vector8 {9 public:10 Vector (float x, float y, float z) { this->x=x; this->y = y; this->z = z; };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 };14 6 15 7 void Matrix::eigVl(const Matrix& mat) … … 79 71 } 80 72 81 Matrix M = *this - Matrix::identity() * eigValue[0];82 73 83 float u11, u12, u13, u22, u23, u33; 74 // EigenVectors 75 for (int i = 0; i < 3; ++i) 76 { 77 printf (":: i = %d\n", i); 78 Matrix M = *this - Matrix::identity() * eigValue[i]; 79 Vector m1, m2, m3; 80 81 M.getTransposed().toVectors(m1, m2, m3); 82 83 Vector u1, u2, u3; 84 85 u1 = m2.cross(m3); u1 /= u1.len(); 86 u2 = m3.cross(m1); u2 /= u2.len(); 87 u3 = m1.cross(m2); u3 /= u3.len(); 88 89 printf("%f, %f, %f\n", u1.x, u1.y, u1.z); 90 printf("%f, %f, %f\n", u2.x, u2.y, u2.z); 91 printf("%f, %f, %f\n", u3.x, u3.y, u3.z); 92 93 // u1 = M*u1; 94 // u2 = M*u2; 95 // u3 = M*u3; 96 // 97 // printf("%f, %f, %f\n", u1.x, u1.y, u1.z); 98 // printf("%f, %f, %f\n", u2.x, u2.y, u2.z); 99 // printf("%f, %f, %f\n", u3.x, u3.y, u3.z); 100 // printf("\n\n"); 101 } 84 102 85 103 this->debug(); -
trunk/src/lib/math/matrix.h
r5663 r5664 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 }; 1 15 2 16 … … 13 27 this->m21 = m21; this->m22 = m22; this->m23 = m23; 14 28 this->m31 = m31; this->m32 = m32; this->m33 = m33; 15 } 29 }; 16 30 17 Matrix operator+ (const Matrix& m) 18 { 31 Matrix operator+ (const Matrix& m) { 19 32 return Matrix (this->m11 + m.m11, this->m12 + m.m12, this->m13 + m.m13, 20 33 this->m21 + m.m21, this->m22 + m.m22, this->m23 + m.m23, … … 22 35 } 23 36 24 Matrix operator- (const Matrix& m) 25 { 37 Matrix operator- (const Matrix& m) { 26 38 return Matrix (this->m11 - m.m11, this->m12 - m.m12, this->m13 - m.m13, 27 39 this->m21 - m.m21, this->m22 - m.m22, this->m23 - m.m23, … … 29 41 } 30 42 31 Matrix operator* (float k) 32 { 43 Matrix operator* (float k) { 33 44 return Matrix(this->m11 - k, this->m12 - k, this->m13 - k, 34 45 this->m21 - k, this->m22 - k, this->m23 - k, … … 36 47 } 37 48 38 static Matrix identity() { return Matrix (1,0,0, 0,1,0, 0,0,1); } 49 Vector operator* (const Vector& v) { 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() { 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) { 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 70 /// @todo optimize 71 static Matrix identity() { return Matrix (1,0,0, 0,1,0, 0,0,1); } 39 72 40 73 void eigVl(const Matrix& matrix);
Note: See TracChangeset
for help on using the changeset viewer.