nuclear@10: /* nuclear@10: libvmath - a vector math library nuclear@10: Copyright (C) 2004-2015 John Tsiombikas nuclear@10: nuclear@10: This program is free software: you can redistribute it and/or modify nuclear@10: it under the terms of the GNU Lesser General Public License as published nuclear@10: by the Free Software Foundation, either version 3 of the License, or nuclear@10: (at your option) any later version. nuclear@10: nuclear@10: This program is distributed in the hope that it will be useful, nuclear@10: but WITHOUT ANY WARRANTY; without even the implied warranty of nuclear@10: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the nuclear@10: GNU Lesser General Public License for more details. nuclear@10: nuclear@10: You should have received a copy of the GNU Lesser General Public License nuclear@10: along with this program. If not, see . nuclear@10: */ nuclear@10: #include "basis.h" nuclear@10: #include "vmath.h" nuclear@10: nuclear@10: Basis::Basis() nuclear@10: { nuclear@10: i = Vector3(1, 0, 0); nuclear@10: j = Vector3(0, 1, 0); nuclear@10: k = Vector3(0, 0, 1); nuclear@10: } nuclear@10: nuclear@10: Basis::Basis(const Vector3 &i, const Vector3 &j, const Vector3 &k) nuclear@10: { nuclear@10: this->i = i; nuclear@10: this->j = j; nuclear@10: this->k = k; nuclear@10: } nuclear@10: nuclear@10: Basis::Basis(const Vector3 &dir, bool left_handed) nuclear@10: { nuclear@10: k = dir; nuclear@10: j = Vector3(0, 1, 0); nuclear@10: i = cross_product(j, k); nuclear@10: j = cross_product(k, i); nuclear@10: } nuclear@10: nuclear@10: /** Rotate with euler angles */ nuclear@10: void Basis::rotate(scalar_t x, scalar_t y, scalar_t z) { nuclear@10: Matrix4x4 RotMat; nuclear@10: RotMat.set_rotation(Vector3(x, y, z)); nuclear@10: i.transform(RotMat); nuclear@10: j.transform(RotMat); nuclear@10: k.transform(RotMat); nuclear@10: } nuclear@10: nuclear@10: /** Rotate by axis-angle specification */ nuclear@10: void Basis::rotate(const Vector3 &axis, scalar_t angle) { nuclear@10: Quaternion q; nuclear@10: q.set_rotation(axis, angle); nuclear@10: i.transform(q); nuclear@10: j.transform(q); nuclear@10: k.transform(q); nuclear@10: } nuclear@10: nuclear@10: /** Rotate with a 4x4 matrix */ nuclear@10: void Basis::rotate(const Matrix4x4 &mat) { nuclear@10: i.transform(mat); nuclear@10: j.transform(mat); nuclear@10: k.transform(mat); nuclear@10: } nuclear@10: nuclear@10: /** Rotate with a quaternion */ nuclear@10: void Basis::rotate(const Quaternion &quat) { nuclear@10: i.transform(quat); nuclear@10: j.transform(quat); nuclear@10: k.transform(quat); nuclear@10: } nuclear@10: nuclear@10: /** Extract a rotation matrix from the orthogonal basis */ nuclear@10: Matrix3x3 Basis::create_rotation_matrix() const { nuclear@10: return Matrix3x3( i.x, j.x, k.x, nuclear@10: i.y, j.y, k.y, nuclear@10: i.z, j.z, k.z); nuclear@10: }