3dphotoshoot

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/libs/vmath/basis.cc	Sun May 31 00:40:26 2015 +0300
     1.3 @@ -0,0 +1,80 @@
     1.4 +/*
     1.5 +libvmath - a vector math library
     1.6 +Copyright (C) 2004-2015 John Tsiombikas <nuclear@member.fsf.org>
     1.7 +
     1.8 +This program is free software: you can redistribute it and/or modify
     1.9 +it under the terms of the GNU Lesser General Public License as published
    1.10 +by the Free Software Foundation, either version 3 of the License, or
    1.11 +(at your option) any later version.
    1.12 +
    1.13 +This program is distributed in the hope that it will be useful,
    1.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.16 +GNU Lesser General Public License for more details.
    1.17 +
    1.18 +You should have received a copy of the GNU Lesser General Public License
    1.19 +along with this program.  If not, see <http://www.gnu.org/licenses/>.
    1.20 +*/
    1.21 +#include "basis.h"
    1.22 +#include "vmath.h"
    1.23 +
    1.24 +Basis::Basis()
    1.25 +{
    1.26 +	i = Vector3(1, 0, 0);
    1.27 +	j = Vector3(0, 1, 0);
    1.28 +	k = Vector3(0, 0, 1);
    1.29 +}
    1.30 +
    1.31 +Basis::Basis(const Vector3 &i, const Vector3 &j, const Vector3 &k)
    1.32 +{
    1.33 +	this->i = i;
    1.34 +	this->j = j;
    1.35 +	this->k = k;
    1.36 +}
    1.37 +
    1.38 +Basis::Basis(const Vector3 &dir, bool left_handed)
    1.39 +{
    1.40 +	k = dir;
    1.41 +	j = Vector3(0, 1, 0);
    1.42 +	i = cross_product(j, k);
    1.43 +	j = cross_product(k, i);
    1.44 +}
    1.45 +
    1.46 +/** Rotate with euler angles */
    1.47 +void Basis::rotate(scalar_t x, scalar_t y, scalar_t z) {
    1.48 +	Matrix4x4 RotMat;
    1.49 +	RotMat.set_rotation(Vector3(x, y, z));
    1.50 +	i.transform(RotMat);
    1.51 +	j.transform(RotMat);
    1.52 +	k.transform(RotMat);
    1.53 +}
    1.54 +
    1.55 +/** Rotate by axis-angle specification */
    1.56 +void Basis::rotate(const Vector3 &axis, scalar_t angle) {
    1.57 +	Quaternion q;
    1.58 +	q.set_rotation(axis, angle);
    1.59 +	i.transform(q);
    1.60 +	j.transform(q);
    1.61 +	k.transform(q);
    1.62 +}
    1.63 +
    1.64 +/** Rotate with a 4x4 matrix */
    1.65 +void Basis::rotate(const Matrix4x4 &mat) {
    1.66 +	i.transform(mat);
    1.67 +	j.transform(mat);
    1.68 +	k.transform(mat);
    1.69 +}
    1.70 +
    1.71 +/** Rotate with a quaternion */
    1.72 +void Basis::rotate(const Quaternion &quat) {
    1.73 +	i.transform(quat);
    1.74 +	j.transform(quat);
    1.75 +	k.transform(quat);
    1.76 +}
    1.77 +
    1.78 +/** Extract a rotation matrix from the orthogonal basis */
    1.79 +Matrix3x3 Basis::create_rotation_matrix() const {
    1.80 +	return Matrix3x3(	i.x, j.x, k.x,
    1.81 +						i.y, j.y, k.y,
    1.82 +						i.z, j.z, k.z);
    1.83 +}