dungeon_crawler

view prototype/vmath/basis.cc @ 1:96de911d05d4

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