vrshoot

annotate libs/vmath/basis.cc @ 3:c179c72369be

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