lin
2025-04-23 399353eb5dc7e9c1db94cc97c380dc7f66c51a4c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
#
# Copyright (C) 2015 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
 
header:
summary: Quaternion Functions
description:
 The following functions manipulate quaternions.
end:
 
function: rsQuaternionAdd
version: 9 23
ret: void
arg: rs_quaternion* q, "Destination quaternion to add to."
arg: const rs_quaternion* rhs, "Quaternion to add."
summary: Add two quaternions
description:
 Adds two quaternions, i.e. <code>*q += *rhs;</code>
inline:
 q->w += rhs->w;
 q->x += rhs->x;
 q->y += rhs->y;
 q->z += rhs->z;
test: none
end:
 
function: rsQuaternionConjugate
version: 9 23
ret: void
arg: rs_quaternion* q, "Quaternion to modify."
summary: Conjugate a quaternion
description:
 Conjugates the quaternion.
inline:
 q->x = -q->x;
 q->y = -q->y;
 q->z = -q->z;
test: none
end:
 
function: rsQuaternionDot
version: 9 23
ret: float
arg: const rs_quaternion* q0, "First quaternion."
arg: const rs_quaternion* q1, "Second quaternion."
summary:  Dot product of two quaternions
description:
 Returns the dot product of two quaternions.
inline:
 return q0->w*q1->w + q0->x*q1->x + q0->y*q1->y + q0->z*q1->z;
test: none
end:
 
function: rsQuaternionGetMatrixUnit
version: 9 23
ret: void
arg: rs_matrix4x4* m, "Resulting matrix."
arg: const rs_quaternion* q, "Normalized quaternion."
summary: Get a rotation matrix from a quaternion
description:
 Computes a rotation matrix from the normalized quaternion.
inline:
 float xx = q->x * q->x;
 float xy = q->x * q->y;
 float xz = q->x * q->z;
 float xw = q->x * q->w;
 float yy = q->y * q->y;
 float yz = q->y * q->z;
 float yw = q->y * q->w;
 float zz = q->z * q->z;
 float zw = q->z * q->w;
 
 m->m[0]  = 1.0f - 2.0f * ( yy + zz );
 m->m[4]  =        2.0f * ( xy - zw );
 m->m[8]  =        2.0f * ( xz + yw );
 m->m[1]  =        2.0f * ( xy + zw );
 m->m[5]  = 1.0f - 2.0f * ( xx + zz );
 m->m[9]  =        2.0f * ( yz - xw );
 m->m[2]  =        2.0f * ( xz - yw );
 m->m[6]  =        2.0f * ( yz + xw );
 m->m[10] = 1.0f - 2.0f * ( xx + yy );
 m->m[3]  = m->m[7] = m->m[11] = m->m[12] = m->m[13] = m->m[14] = 0.0f;
 m->m[15] = 1.0f;
test: none
end:
 
function: rsQuaternionLoadRotateUnit
version: 9 23
ret: void
arg: rs_quaternion* q, "Destination quaternion."
arg: float rot, "Angle to rotate by, in radians."
arg: float x, "X component of the vector."
arg: float y, "Y component of the vector."
arg: float z, "Z component of the vector."
summary:  Quaternion that represents a rotation about an arbitrary unit vector
description:
 Loads a quaternion that represents a rotation about an arbitrary unit vector.
inline:
 rot *= (float)(M_PI / 180.0f) * 0.5f;
 float c = cos(rot);
 float s = sin(rot);
 
 q->w = c;
 q->x = x * s;
 q->y = y * s;
 q->z = z * s;
test: none
end:
 
function: rsQuaternionSet
version: 9 23
ret: void
arg: rs_quaternion* q, "Destination quaternion."
arg: float w, "W component."
arg: float x, "X component."
arg: float y, "Y component."
arg: float z, "Z component."
summary: Create a quaternion
description:
 Creates a quaternion from its four components or from another quaternion.
inline:
 q->w = w;
 q->x = x;
 q->y = y;
 q->z = z;
test: none
end:
 
function: rsQuaternionSet
version: 9 23
ret: void
arg: rs_quaternion* q
arg: const rs_quaternion* rhs, "Source quaternion."
inline:
 q->w = rhs->w;
 q->x = rhs->x;
 q->y = rhs->y;
 q->z = rhs->z;
test: none
end:
 
# NOTE: The following inline definitions depend on each other.  The order must be preserved
# for the compilation to work.
 
function: rsQuaternionLoadRotate
version: 9 23
ret: void
arg: rs_quaternion* q, "Destination quaternion."
arg: float rot, "Angle to rotate by."
arg: float x, "X component of a vector."
arg: float y, "Y component of a vector."
arg: float z, "Z component of a vector."
summary: Create a rotation quaternion
description:
 Loads a quaternion that represents a rotation about an arbitrary vector
 (doesn't have to be unit)
inline:
 const float len = x*x + y*y + z*z;
 if (len != 1) {
     const float recipLen = 1.f / sqrt(len);
     x *= recipLen;
     y *= recipLen;
     z *= recipLen;
 }
 rsQuaternionLoadRotateUnit(q, rot, x, y, z);
test: none
end:
 
function: rsQuaternionNormalize
version: 9 23
ret: void
arg: rs_quaternion* q, "Quaternion to normalize."
summary:  Normalize a quaternion
description:
 Normalizes the quaternion.
inline:
 const float len = rsQuaternionDot(q, q);
 if (len != 1) {
     const float recipLen = 1.f / sqrt(len);
     q->w *= recipLen;
     q->x *= recipLen;
     q->y *= recipLen;
     q->z *= recipLen;
 }
test: none
end:
 
function: rsQuaternionMultiply
version: 9 23
ret: void
arg: rs_quaternion* q, "Destination quaternion."
arg: float scalar, "Scalar to multiply the quaternion by."
summary:  Multiply a quaternion by a scalar or another quaternion
description:
 Multiplies a quaternion by a scalar or by another quaternion, e.g
 <code>*q = *q * scalar;</code> or <code>*q = *q * *rhs;</code>.
inline:
 q->w *= scalar;
 q->x *= scalar;
 q->y *= scalar;
 q->z *= scalar;
test: none
end:
 
function: rsQuaternionMultiply
version: 9 23
ret: void
arg: rs_quaternion* q
arg: const rs_quaternion* rhs, "Quaternion to multiply the destination quaternion by."
inline:
 rs_quaternion qtmp;
 rsQuaternionSet(&qtmp, q);
 
 q->w = qtmp.w*rhs->w - qtmp.x*rhs->x - qtmp.y*rhs->y - qtmp.z*rhs->z;
 q->x = qtmp.w*rhs->x + qtmp.x*rhs->w + qtmp.y*rhs->z - qtmp.z*rhs->y;
 q->y = qtmp.w*rhs->y + qtmp.y*rhs->w + qtmp.z*rhs->x - qtmp.x*rhs->z;
 q->z = qtmp.w*rhs->z + qtmp.z*rhs->w + qtmp.x*rhs->y - qtmp.y*rhs->x;
 rsQuaternionNormalize(q);
test: none
end:
 
function: rsQuaternionSlerp
version: 9 23
ret: void
arg: rs_quaternion* q, "Result quaternion from the interpolation."
arg: const rs_quaternion* q0, "First input quaternion."
arg: const rs_quaternion* q1, "Second input quaternion."
arg: float t, "How much to interpolate by."
summary: Spherical linear interpolation between two quaternions
description:
 Performs spherical linear interpolation between two quaternions.
inline:
 if (t <= 0.0f) {
     rsQuaternionSet(q, q0);
     return;
 }
 if (t >= 1.0f) {
     rsQuaternionSet(q, q1);
     return;
 }
 
 rs_quaternion tempq0, tempq1;
 rsQuaternionSet(&tempq0, q0);
 rsQuaternionSet(&tempq1, q1);
 
 float angle = rsQuaternionDot(q0, q1);
 if (angle < 0) {
     rsQuaternionMultiply(&tempq0, -1.0f);
     angle *= -1.0f;
 }
 
 float scale, invScale;
 if (angle + 1.0f > 0.05f) {
     if (1.0f - angle >= 0.05f) {
         float theta = acos(angle);
         float invSinTheta = 1.0f / sin(theta);
         scale = sin(theta * (1.0f - t)) * invSinTheta;
         invScale = sin(theta * t) * invSinTheta;
     } else {
         scale = 1.0f - t;
         invScale = t;
     }
 } else {
     rsQuaternionSet(&tempq1, tempq0.z, -tempq0.y, tempq0.x, -tempq0.w);
     scale = sin(M_PI * (0.5f - t));
     invScale = sin(M_PI * t);
 }
 
 rsQuaternionSet(q, tempq0.w*scale + tempq1.w*invScale, tempq0.x*scale + tempq1.x*invScale,
                     tempq0.y*scale + tempq1.y*invScale, tempq0.z*scale + tempq1.z*invScale);
test: none
end:
 
# New versions. Same signatures but don't contain a body.
function: rsQuaternionAdd
version: 24
ret: void
arg: rs_quaternion* q
arg: const rs_quaternion* rhs
test: none
end:
 
function: rsQuaternionConjugate
version: 24
ret: void
arg: rs_quaternion* q
test: none
end:
 
function: rsQuaternionDot
version: 24
ret: float
arg: const rs_quaternion* q0
arg: const rs_quaternion* q1
test: none
end:
 
function: rsQuaternionGetMatrixUnit
version: 24
ret: void
arg: rs_matrix4x4* m
arg: const rs_quaternion* q
test: none
end:
 
function: rsQuaternionLoadRotateUnit
version: 24
ret: void
arg: rs_quaternion* q
arg: float rot
arg: float x
arg: float y
arg: float z
test: none
end:
 
function: rsQuaternionSet
version: 24
ret: void
arg: rs_quaternion* q
arg: float w
arg: float x
arg: float y
arg: float z
test: none
end:
 
function: rsQuaternionSet
version: 24
ret: void
arg: rs_quaternion* q
arg: const rs_quaternion* rhs
test: none
end:
 
# NOTE: The following inline definitions depend on each other.  The order must be preserved
# for the compilation to work.
 
function: rsQuaternionLoadRotate
version: 24
ret: void
arg: rs_quaternion* q
arg: float rot
arg: float x
arg: float y
arg: float z
test: none
end:
 
function: rsQuaternionNormalize
version: 24
ret: void
arg: rs_quaternion* q
test: none
end:
 
function: rsQuaternionMultiply
version: 24
ret: void
arg: rs_quaternion* q
arg: float scalar
test: none
end:
 
function: rsQuaternionMultiply
version: 24
ret: void
arg: rs_quaternion* q
arg: const rs_quaternion* rhs
test: none
end:
 
function: rsQuaternionSlerp
version: 24
ret: void
arg: rs_quaternion* q
arg: const rs_quaternion* q0
arg: const rs_quaternion* q1
arg: float t
test: none
end: