goat3d

diff libs/vmath/basis.cc @ 27:4deb0b12fe14

wtf... corrupted heap?
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 29 Sep 2013 08:20:19 +0300
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/libs/vmath/basis.cc	Sun Sep 29 08:20:19 2013 +0300
     1.3 @@ -0,0 +1,63 @@
     1.4 +#include "basis.h"
     1.5 +#include "vmath.h"
     1.6 +
     1.7 +Basis::Basis()
     1.8 +{
     1.9 +	i = Vector3(1, 0, 0);
    1.10 +	j = Vector3(0, 1, 0);
    1.11 +	k = Vector3(0, 0, 1);
    1.12 +}
    1.13 +
    1.14 +Basis::Basis(const Vector3 &i, const Vector3 &j, const Vector3 &k)
    1.15 +{
    1.16 +	this->i = i;
    1.17 +	this->j = j;
    1.18 +	this->k = k;
    1.19 +}
    1.20 +
    1.21 +Basis::Basis(const Vector3 &dir, bool left_handed)
    1.22 +{
    1.23 +	k = dir;
    1.24 +	j = Vector3(0, 1, 0);
    1.25 +	i = cross_product(j, k);
    1.26 +	j = cross_product(k, i);
    1.27 +}
    1.28 +
    1.29 +/** Rotate with euler angles */
    1.30 +void Basis::rotate(scalar_t x, scalar_t y, scalar_t z) {
    1.31 +	Matrix4x4 RotMat;
    1.32 +	RotMat.set_rotation(Vector3(x, y, z));
    1.33 +	i.transform(RotMat);
    1.34 +	j.transform(RotMat);
    1.35 +	k.transform(RotMat);
    1.36 +}
    1.37 +
    1.38 +/** Rotate by axis-angle specification */
    1.39 +void Basis::rotate(const Vector3 &axis, scalar_t angle) {
    1.40 +	Quaternion q;
    1.41 +	q.set_rotation(axis, angle);
    1.42 +	i.transform(q);
    1.43 +	j.transform(q);
    1.44 +	k.transform(q);
    1.45 +}
    1.46 +
    1.47 +/** Rotate with a 4x4 matrix */
    1.48 +void Basis::rotate(const Matrix4x4 &mat) {
    1.49 +	i.transform(mat);
    1.50 +	j.transform(mat);
    1.51 +	k.transform(mat);
    1.52 +}
    1.53 +
    1.54 +/** Rotate with a quaternion */
    1.55 +void Basis::rotate(const Quaternion &quat) {
    1.56 +	i.transform(quat);
    1.57 +	j.transform(quat);
    1.58 +	k.transform(quat);
    1.59 +}
    1.60 +
    1.61 +/** Extract a rotation matrix from the orthogonal basis */
    1.62 +Matrix3x3 Basis::create_rotation_matrix() const {
    1.63 +	return Matrix3x3(	i.x, j.x, k.x,
    1.64 +						i.y, j.y, k.y,
    1.65 +						i.z, j.z, k.z);
    1.66 +}