-
Notifications
You must be signed in to change notification settings - Fork 2
/
quat.h
125 lines (110 loc) · 3.5 KB
/
quat.h
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
#ifndef QUAT_H
#define QUAT_H
#include <stdint.h>
/**
* Set a quat to the identity quaternion
*
* @param {quat} out the receiving quaternion
*/
void quat_identity(float* dst);
/**
* Sets a quat from the given angle and rotation axis,
* then returns it.
*
* @param {quat} out the receiving quaternion
* @param {vec3} axis the axis around which to rotate
* @param {Number} rad the angle in radians
**/
void quat_setAxisAngle(float* dst, float* axis, float rad);
/**
* Gets the rotation axis and angle for a given
* quaternion. If a quaternion is created with
* setAxisAngle, this method will return the same
* values as providied in the original parameter list
* OR functionally equivalent values.
* Example: The quaternion formed by axis [0, 0, 1] and
* angle -90 is the same as the quaternion formed by
* [0, 0, 1] and 270. This method favors the latter.
* @param {vec3} out_axis Vector receiving the axis of rotation
* @param {quat} q Quaternion to be decomposed
* @return {Number} Angle, in radians, of the rotation
*/
float quat_getAxisAngle(float* out_axis, float* q);
/**
* Multiplies two quat's
*
* @param {quat} out the receiving quaternion
* @param {quat} b the second operand
*/
void quat_multiply(float* dst, float* b);
/**
* Rotates a quaternion by the given angle about the X axis
*
* @param {quat} out quat receiving operation result
* @param {number} rad angle (in radians) to rotate
*/
void quat_rotateX(float* dst, float rad);
/**
* Rotates a quaternion by the given angle about the Y axis
*
* @param {quat} out quat receiving operation result
* @param {number} rad angle (in radians) to rotate
*/
void quat_rotateY(float* dst, float rad);
/**
* Rotates a quaternion by the given angle about the Z axis
*
* @param {quat} out quat receiving operation result
* @param {number} rad angle (in radians) to rotate
*/
void quat_rotateZ(float* dst, float rad);
/**
* Calculates the W component of a quat from the X, Y, and Z components.
* Assumes that quaternion is 1 unit in length.
* Any existing W component will be ignored.
*
* @param {quat} out the receiving quaternion
*/
void quat_calculateW(float* dst);
/**
* Performs a spherical linear interpolation between two quat
*
* @param {quat} out the receiving quaternion
* @param {quat} b the second operand
* @param {Number} t interpolation amount, in the range [0-1], between the two inputs
*/
void quat_slerp(float* dst, float* b, float t);
/**
* Calculates the inverse of a quat
*
* @param {quat} out the receiving quaternion
*/
void quat_invert(float* dst);
/**
* Calculates the conjugate of a quat
* If the quaternion is normalized, this function is faster than quat.inverse and produces the same result.
*
* @param {quat} out the receiving quaternion
* @param {quat} a quat to calculate conjugate of
*/
void quat_conjugate(float* dst);
/**
* Creates a quaternion from the given 3x3 rotation matrix.
*
* NOTE: The resultant quaternion is not normalized, so you should be sure
* to renormalize the quaternion yourself where necessary.
*
* @param {quat} out the receiving quaternion
* @param {mat3} m rotation matrix
*/
void quat_fromMat3(float* dst, float* m);
/**
* Creates a quaternion from the given euler angle x, y, z.
*
* @param {quat} out the receiving quaternion
* @param {x} Angle to rotate around X axis in degrees.
* @param {y} Angle to rotate around Y axis in degrees.
* @param {z} Angle to rotate around Z axis in degrees.
*/
void quat_fromEuler(float* dst, float x, float y, float z);
#endif