goat3d
annotate libs/vmath/basis.cc @ 27:4deb0b12fe14
wtf... corrupted heap?
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 29 Sep 2013 08:20:19 +0300 |
parents | |
children |
rev | line source |
---|---|
nuclear@27 | 1 #include "basis.h" |
nuclear@27 | 2 #include "vmath.h" |
nuclear@27 | 3 |
nuclear@27 | 4 Basis::Basis() |
nuclear@27 | 5 { |
nuclear@27 | 6 i = Vector3(1, 0, 0); |
nuclear@27 | 7 j = Vector3(0, 1, 0); |
nuclear@27 | 8 k = Vector3(0, 0, 1); |
nuclear@27 | 9 } |
nuclear@27 | 10 |
nuclear@27 | 11 Basis::Basis(const Vector3 &i, const Vector3 &j, const Vector3 &k) |
nuclear@27 | 12 { |
nuclear@27 | 13 this->i = i; |
nuclear@27 | 14 this->j = j; |
nuclear@27 | 15 this->k = k; |
nuclear@27 | 16 } |
nuclear@27 | 17 |
nuclear@27 | 18 Basis::Basis(const Vector3 &dir, bool left_handed) |
nuclear@27 | 19 { |
nuclear@27 | 20 k = dir; |
nuclear@27 | 21 j = Vector3(0, 1, 0); |
nuclear@27 | 22 i = cross_product(j, k); |
nuclear@27 | 23 j = cross_product(k, i); |
nuclear@27 | 24 } |
nuclear@27 | 25 |
nuclear@27 | 26 /** Rotate with euler angles */ |
nuclear@27 | 27 void Basis::rotate(scalar_t x, scalar_t y, scalar_t z) { |
nuclear@27 | 28 Matrix4x4 RotMat; |
nuclear@27 | 29 RotMat.set_rotation(Vector3(x, y, z)); |
nuclear@27 | 30 i.transform(RotMat); |
nuclear@27 | 31 j.transform(RotMat); |
nuclear@27 | 32 k.transform(RotMat); |
nuclear@27 | 33 } |
nuclear@27 | 34 |
nuclear@27 | 35 /** Rotate by axis-angle specification */ |
nuclear@27 | 36 void Basis::rotate(const Vector3 &axis, scalar_t angle) { |
nuclear@27 | 37 Quaternion q; |
nuclear@27 | 38 q.set_rotation(axis, angle); |
nuclear@27 | 39 i.transform(q); |
nuclear@27 | 40 j.transform(q); |
nuclear@27 | 41 k.transform(q); |
nuclear@27 | 42 } |
nuclear@27 | 43 |
nuclear@27 | 44 /** Rotate with a 4x4 matrix */ |
nuclear@27 | 45 void Basis::rotate(const Matrix4x4 &mat) { |
nuclear@27 | 46 i.transform(mat); |
nuclear@27 | 47 j.transform(mat); |
nuclear@27 | 48 k.transform(mat); |
nuclear@27 | 49 } |
nuclear@27 | 50 |
nuclear@27 | 51 /** Rotate with a quaternion */ |
nuclear@27 | 52 void Basis::rotate(const Quaternion &quat) { |
nuclear@27 | 53 i.transform(quat); |
nuclear@27 | 54 j.transform(quat); |
nuclear@27 | 55 k.transform(quat); |
nuclear@27 | 56 } |
nuclear@27 | 57 |
nuclear@27 | 58 /** Extract a rotation matrix from the orthogonal basis */ |
nuclear@27 | 59 Matrix3x3 Basis::create_rotation_matrix() const { |
nuclear@27 | 60 return Matrix3x3( i.x, j.x, k.x, |
nuclear@27 | 61 i.y, j.y, k.y, |
nuclear@27 | 62 i.z, j.z, k.z); |
nuclear@27 | 63 } |