3dphotoshoot

view libs/vmath/basis.cc @ 10:c71c477521ca

converting to GLES2 and C++
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 31 May 2015 00:40:26 +0300
parents
children
line source
1 /*
2 libvmath - a vector math library
3 Copyright (C) 2004-2015 John Tsiombikas <nuclear@member.fsf.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published
7 by the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include "basis.h"
19 #include "vmath.h"
21 Basis::Basis()
22 {
23 i = Vector3(1, 0, 0);
24 j = Vector3(0, 1, 0);
25 k = Vector3(0, 0, 1);
26 }
28 Basis::Basis(const Vector3 &i, const Vector3 &j, const Vector3 &k)
29 {
30 this->i = i;
31 this->j = j;
32 this->k = k;
33 }
35 Basis::Basis(const Vector3 &dir, bool left_handed)
36 {
37 k = dir;
38 j = Vector3(0, 1, 0);
39 i = cross_product(j, k);
40 j = cross_product(k, i);
41 }
43 /** Rotate with euler angles */
44 void Basis::rotate(scalar_t x, scalar_t y, scalar_t z) {
45 Matrix4x4 RotMat;
46 RotMat.set_rotation(Vector3(x, y, z));
47 i.transform(RotMat);
48 j.transform(RotMat);
49 k.transform(RotMat);
50 }
52 /** Rotate by axis-angle specification */
53 void Basis::rotate(const Vector3 &axis, scalar_t angle) {
54 Quaternion q;
55 q.set_rotation(axis, angle);
56 i.transform(q);
57 j.transform(q);
58 k.transform(q);
59 }
61 /** Rotate with a 4x4 matrix */
62 void Basis::rotate(const Matrix4x4 &mat) {
63 i.transform(mat);
64 j.transform(mat);
65 k.transform(mat);
66 }
68 /** Rotate with a quaternion */
69 void Basis::rotate(const Quaternion &quat) {
70 i.transform(quat);
71 j.transform(quat);
72 k.transform(quat);
73 }
75 /** Extract a rotation matrix from the orthogonal basis */
76 Matrix3x3 Basis::create_rotation_matrix() const {
77 return Matrix3x3( i.x, j.x, k.x,
78 i.y, j.y, k.y,
79 i.z, j.z, k.z);
80 }