istereo

annotate libs/vmath/quat.h @ 43:73813c1176de

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