goat3d

annotate libs/vmath/quat.h @ 27:4deb0b12fe14

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