goat3d

view libs/vmath/quat.h @ 39:0e48907847ad

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