Oolite
Loading...
Searching...
No Matches
OOQuaternion.h
Go to the documentation of this file.
1/*
2
3OOQuaternion.h
4
5Mathematical framework for Oolite.
6
7Oolite
8Copyright (C) 2004-2013 Giles C Williams and contributors
9
10This program is free software; you can redistribute it and/or
11modify it under the terms of the GNU General Public License
12as published by the Free Software Foundation; either version 2
13of the License, or (at your option) any later version.
14
15This program is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18GNU General Public License for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
23MA 02110-1301, USA.
24
25*/
26
33
34extern const Quaternion kIdentityQuaternion; // 1, 0, 0, 0
35extern const Quaternion kZeroQuaternion; // 0, 0, 0, 0
36
37/* Construct quaternion */
39
40/* Comparison of quaternions */
42
43/* Multiply quaternions */
45
46/* Negation, or additive inverse -- negate all components */
48
49/* Conjugate, or spacial inverse -- negate x, y, z components */
51
52/* Set quaternion to random unit quaternion */
55
56/* Build quaternion representing a rotation around a given axis */
58
59/* Inner product of two quaternions */
61
62/* Create basis vectors from a quaternion. */
66
68
69void basis_vectors_from_quaternion(Quaternion quat, Vector* outRight, Vector* outUp, Vector* outForward);
70
71/* produce a quaternion representing an angle between two vectors. Assumes the vectors are normalized. */
74
75/* produce a quaternion representing an angle between two vectors with a maximum arc */
77
78/* Rotate a quaternion about a fixed axis. */
83
84/* Normalize quaternion */
86
87#if __OBJC__
88NSString* QuaternionDescription(Quaternion quaternion); // @"(w + xi + yj + zk)"
89#endif
90
93
94/*** Only inline definitions beyond this point ***/
95
97{
98 Quaternion result;
99 result.w = qw;
100 result.x = qx;
101 result.y = qy;
102 result.z = qz;
103 return result;
104}
105
107{
108 return a.w == b.w && a.x == b.x && a.y == b.y && a.z == b.z;
109}
110
112{
113 return make_quaternion(-q.w, -q.x, -q.y, -q.z);
114}
115
117{
118 return make_quaternion(q.w, -q.x, -q.y, -q.z);
119}
120
122{
123 OOScalar a = angle * 0.5f;
124 OOScalar scale = sin(a);
125
126 quat->w = cos(a);
127 quat->x = axis.x * scale;
128 quat->y = axis.y * scale;
129 quat->z = axis.z * scale;
130}
131
133{
134 return q1.w * q2.w + q1.x * q2.x + q1.y * q2.y + q1.z * q2.z;
135}
136
138{
139 OOScalar w = quat->w;
140 OOScalar x = quat->x;
141 OOScalar y = quat->y;
142 OOScalar z = quat->z;
143
144 OOScalar lv = 1.0f / sqrt(w * w + x * x + y * y + z * z);
145
146 quat->w = lv * w;
147 quat->x = lv * x;
148 quat->y = lv * y;
149 quat->z = lv * z;
150}
151
153{
154 Quaternion q;
156 return q;
157}
#define ALWAYS_INLINE_FUNC
#define NONNULL_FUNC
#define INLINE_CONST_FUNC
#define OOINLINE
#define CONST_FUNC
GLfloat OOScalar
Definition OOMaths.h:49
Quaternion quaternion_rotation_between(Vector v0, Vector v1) CONST_FUNC
Quaternion quaternion_rotation_betweenHP(HPVector v0, HPVector v1) CONST_FUNC
OOINLINE bool quaternion_equal(Quaternion a, Quaternion b) INLINE_CONST_FUNC
void quaternion_rotate_about_x(Quaternion *quat, OOScalar angle) NONNULL_FUNC
Vector vector_forward_from_quaternion(Quaternion quat) CONST_FUNC
void basis_vectors_from_quaternion(Quaternion quat, Vector *outRight, Vector *outUp, Vector *outForward)
Vector quaternion_rotate_vector(Quaternion q, Vector vector) CONST_FUNC
OOINLINE OOScalar quaternion_dot_product(Quaternion q1, Quaternion q2) CONST_FUNC
OOINLINE Quaternion make_quaternion(OOScalar qw, OOScalar qx, OOScalar qy, OOScalar qz) INLINE_CONST_FUNC
OOINLINE Quaternion quaternion_conjugate(Quaternion q) INLINE_CONST_FUNC
void quaternion_rotate_about_axis(Quaternion *quat, Vector axis, OOScalar angle) NONNULL_FUNC
const Quaternion kIdentityQuaternion
OOINLINE Quaternion quaternion_negate(Quaternion q) INLINE_CONST_FUNC
void quaternion_rotate_about_z(Quaternion *quat, OOScalar angle) NONNULL_FUNC
HPVector quaternion_rotate_HPvector(Quaternion q, HPVector vector) CONST_FUNC
OOINLINE void quaternion_set_rotate_about_axis(Quaternion *quat, Vector axis, OOScalar angle) NONNULL_FUNC
Quaternion quaternion_multiply(Quaternion q1, Quaternion q2) CONST_FUNC
OOINLINE void quaternion_normalize(Quaternion *quat) NONNULL_FUNC ALWAYS_INLINE_FUNC
Vector vector_up_from_quaternion(Quaternion quat) CONST_FUNC
void quaternion_rotate_about_y(Quaternion *quat, OOScalar angle) NONNULL_FUNC
const Quaternion kZeroQuaternion
HPVector HPvector_forward_from_quaternion(Quaternion quat) CONST_FUNC
Quaternion quaternion_limited_rotation_between(Vector v0, Vector v1, float maxArc) CONST_FUNC
void quaternion_set_random(Quaternion *quat) NONNULL_FUNC
OOINLINE Quaternion OORandomQuaternion(void) ALWAYS_INLINE_FUNC
Vector vector_right_from_quaternion(Quaternion quat) CONST_FUNC
float y
float x
OOScalar w
OOScalar x
OOScalar y
OOScalar z
OOScalar x
Definition OOVector.h:32
OOScalar y
Definition OOVector.h:33
OOScalar z
Definition OOVector.h:34