3dphotoshoot
view libs/vmath/quat.h @ 25:ac80210d5fbe
preparing a pc version for easier development of non-android-specifics
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Thu, 18 Jun 2015 03:12:30 +0300 |
parents | |
children |
line source
1 /*
2 libvmath - a vector math library
3 Copyright (C) 2004-2015 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 inline quat_t quat_mul(quat_t q1, quat_t q2);
42 static 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 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 inline void quat_to_mat3(mat3_t res, quat_t q);
54 static 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 /* Quaternion */
64 class Quaternion {
65 public:
66 scalar_t s;
67 Vector3 v;
69 Quaternion();
70 Quaternion(scalar_t s, const Vector3 &v);
71 Quaternion(scalar_t s, scalar_t x, scalar_t y, scalar_t z);
72 Quaternion(const Vector3 &axis, scalar_t angle);
73 Quaternion(const quat_t &quat);
75 Quaternion operator +(const Quaternion &quat) const;
76 Quaternion operator -(const Quaternion &quat) const;
77 Quaternion operator -() const;
78 Quaternion operator *(const Quaternion &quat) const;
80 void operator +=(const Quaternion &quat);
81 void operator -=(const Quaternion &quat);
82 void operator *=(const Quaternion &quat);
84 void reset_identity();
86 Quaternion conjugate() const;
88 scalar_t length() const;
89 scalar_t length_sq() const;
91 void normalize();
92 Quaternion normalized() const;
94 Quaternion inverse() const;
96 void set_rotation(const Vector3 &axis, scalar_t angle);
97 void rotate(const Vector3 &axis, scalar_t angle);
98 /* note: this is a totally different operation from the above
99 * this treats the quaternion as signifying direction and rotates
100 * it by a rotation quaternion by rot * q * rot'
101 */
102 void rotate(const Quaternion &q);
104 Matrix3x3 get_rotation_matrix() const;
105 };
107 Quaternion slerp(const Quaternion &q1, const Quaternion &q2, scalar_t t);
108 inline Quaternion lerp(const Quaternion &q1, const Quaternion &q2, scalar_t t);
110 #endif /* __cplusplus */
112 #include "quat.inl"
114 #endif /* VMATH_QUATERNION_H_ */