istereo2

annotate libs/vmath/quat.h @ 34:33ba8618972c

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