nuclear@0: #include "basis.h" nuclear@0: #include "vmath.h" nuclear@0: nuclear@0: Basis::Basis() nuclear@0: { nuclear@0: i = Vector3(1, 0, 0); nuclear@0: j = Vector3(0, 1, 0); nuclear@0: k = Vector3(0, 0, 1); nuclear@0: } nuclear@0: nuclear@0: Basis::Basis(const Vector3 &i, const Vector3 &j, const Vector3 &k) nuclear@0: { nuclear@0: this->i = i; nuclear@0: this->j = j; nuclear@0: this->k = k; nuclear@0: } nuclear@0: nuclear@0: Basis::Basis(const Vector3 &dir, bool left_handed) nuclear@0: { nuclear@0: k = dir; nuclear@0: j = Vector3(0, 1, 0); nuclear@0: i = cross_product(j, k); nuclear@0: j = cross_product(k, i); nuclear@0: } nuclear@0: nuclear@0: /** Rotate with euler angles */ nuclear@0: void Basis::rotate(scalar_t x, scalar_t y, scalar_t z) { nuclear@0: Matrix4x4 RotMat; nuclear@0: RotMat.set_rotation(Vector3(x, y, z)); nuclear@0: i.transform(RotMat); nuclear@0: j.transform(RotMat); nuclear@0: k.transform(RotMat); nuclear@0: } nuclear@0: nuclear@0: /** Rotate by axis-angle specification */ nuclear@0: void Basis::rotate(const Vector3 &axis, scalar_t angle) { nuclear@0: Quaternion q; nuclear@0: q.set_rotation(axis, angle); nuclear@0: i.transform(q); nuclear@0: j.transform(q); nuclear@0: k.transform(q); nuclear@0: } nuclear@0: nuclear@0: /** Rotate with a 4x4 matrix */ nuclear@0: void Basis::rotate(const Matrix4x4 &mat) { nuclear@0: i.transform(mat); nuclear@0: j.transform(mat); nuclear@0: k.transform(mat); nuclear@0: } nuclear@0: nuclear@0: /** Rotate with a quaternion */ nuclear@0: void Basis::rotate(const Quaternion &quat) { nuclear@0: i.transform(quat); nuclear@0: j.transform(quat); nuclear@0: k.transform(quat); nuclear@0: } nuclear@0: nuclear@0: /** Extract a rotation matrix from the orthogonal basis */ nuclear@0: Matrix3x3 Basis::create_rotation_matrix() const { nuclear@0: return Matrix3x3( i.x, j.x, k.x, nuclear@0: i.y, j.y, k.y, nuclear@0: i.z, j.z, k.z); nuclear@0: }