dungeon_crawler

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/prototype/vmath/basis.cc	Thu Jun 28 06:05:50 2012 +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 +}