dungeon_crawler

annotate prototype/vmath/basis.cc @ 80:a373b36ffc17

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