3dphotoshoot

annotate libs/vmath/quat.h @ 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
rev   line source
nuclear@10 1 /*
nuclear@10 2 libvmath - a vector math library
nuclear@10 3 Copyright (C) 2004-2015 John Tsiombikas <nuclear@member.fsf.org>
nuclear@10 4
nuclear@10 5 This program is free software: you can redistribute it and/or modify
nuclear@10 6 it under the terms of the GNU Lesser General Public License as published
nuclear@10 7 by the Free Software Foundation, either version 3 of the License, or
nuclear@10 8 (at your option) any later version.
nuclear@10 9
nuclear@10 10 This program is distributed in the hope that it will be useful,
nuclear@10 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
nuclear@10 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
nuclear@10 13 GNU Lesser General Public License for more details.
nuclear@10 14
nuclear@10 15 You should have received a copy of the GNU Lesser General Public License
nuclear@10 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
nuclear@10 17 */
nuclear@10 18
nuclear@10 19 #ifndef VMATH_QUATERNION_H_
nuclear@10 20 #define VMATH_QUATERNION_H_
nuclear@10 21
nuclear@10 22 #include <stdio.h>
nuclear@10 23 #include "vmath_types.h"
nuclear@10 24 #include "vector.h"
nuclear@10 25
nuclear@10 26 #ifdef __cplusplus
nuclear@10 27 extern "C" {
nuclear@10 28 #endif /* __cplusplus */
nuclear@10 29
nuclear@10 30 #define quat_cons(s, x, y, z) v4_cons(x, y, z, s)
nuclear@10 31 #define quat_vec(q) v3_cons((q).x, (q).y, (q).z)
nuclear@10 32 #define quat_s(q) ((q).w)
nuclear@10 33 #define quat_identity() quat_cons(1.0, 0.0, 0.0, 0.0)
nuclear@10 34 void quat_print(FILE *fp, quat_t q);
nuclear@10 35
nuclear@10 36 #define quat_add v4_add
nuclear@10 37 #define quat_sub v4_sub
nuclear@10 38 #define quat_neg v4_neg
nuclear@10 39
nuclear@10 40 static inline quat_t quat_mul(quat_t q1, quat_t q2);
nuclear@10 41
nuclear@10 42 static inline quat_t quat_conjugate(quat_t q);
nuclear@10 43
nuclear@10 44 #define quat_length v4_length
nuclear@10 45 #define quat_length_sq v4_length_sq
nuclear@10 46
nuclear@10 47 #define quat_normalize v4_normalize
nuclear@10 48 static inline quat_t quat_inverse(quat_t q);
nuclear@10 49
nuclear@10 50 quat_t quat_rotate(quat_t q, scalar_t angle, scalar_t x, scalar_t y, scalar_t z);
nuclear@10 51 quat_t quat_rotate_quat(quat_t q, quat_t rotq);
nuclear@10 52
nuclear@10 53 static inline void quat_to_mat3(mat3_t res, quat_t q);
nuclear@10 54 static inline void quat_to_mat4(mat4_t res, quat_t q);
nuclear@10 55
nuclear@10 56 #define quat_lerp quat_slerp
nuclear@10 57 quat_t quat_slerp(quat_t q1, quat_t q2, scalar_t t);
nuclear@10 58
nuclear@10 59
nuclear@10 60 #ifdef __cplusplus
nuclear@10 61 } /* extern "C" */
nuclear@10 62
nuclear@10 63 /* Quaternion */
nuclear@10 64 class Quaternion {
nuclear@10 65 public:
nuclear@10 66 scalar_t s;
nuclear@10 67 Vector3 v;
nuclear@10 68
nuclear@10 69 Quaternion();
nuclear@10 70 Quaternion(scalar_t s, const Vector3 &v);
nuclear@10 71 Quaternion(scalar_t s, scalar_t x, scalar_t y, scalar_t z);
nuclear@10 72 Quaternion(const Vector3 &axis, scalar_t angle);
nuclear@10 73 Quaternion(const quat_t &quat);
nuclear@10 74
nuclear@10 75 Quaternion operator +(const Quaternion &quat) const;
nuclear@10 76 Quaternion operator -(const Quaternion &quat) const;
nuclear@10 77 Quaternion operator -() const;
nuclear@10 78 Quaternion operator *(const Quaternion &quat) const;
nuclear@10 79
nuclear@10 80 void operator +=(const Quaternion &quat);
nuclear@10 81 void operator -=(const Quaternion &quat);
nuclear@10 82 void operator *=(const Quaternion &quat);
nuclear@10 83
nuclear@10 84 void reset_identity();
nuclear@10 85
nuclear@10 86 Quaternion conjugate() const;
nuclear@10 87
nuclear@10 88 scalar_t length() const;
nuclear@10 89 scalar_t length_sq() const;
nuclear@10 90
nuclear@10 91 void normalize();
nuclear@10 92 Quaternion normalized() const;
nuclear@10 93
nuclear@10 94 Quaternion inverse() const;
nuclear@10 95
nuclear@10 96 void set_rotation(const Vector3 &axis, scalar_t angle);
nuclear@10 97 void rotate(const Vector3 &axis, scalar_t angle);
nuclear@10 98 /* note: this is a totally different operation from the above
nuclear@10 99 * this treats the quaternion as signifying direction and rotates
nuclear@10 100 * it by a rotation quaternion by rot * q * rot'
nuclear@10 101 */
nuclear@10 102 void rotate(const Quaternion &q);
nuclear@10 103
nuclear@10 104 Matrix3x3 get_rotation_matrix() const;
nuclear@10 105 };
nuclear@10 106
nuclear@10 107 Quaternion slerp(const Quaternion &q1, const Quaternion &q2, scalar_t t);
nuclear@10 108 inline Quaternion lerp(const Quaternion &q1, const Quaternion &q2, scalar_t t);
nuclear@10 109
nuclear@10 110 #endif /* __cplusplus */
nuclear@10 111
nuclear@10 112 #include "quat.inl"
nuclear@10 113
nuclear@10 114 #endif /* VMATH_QUATERNION_H_ */