-
Notifications
You must be signed in to change notification settings - Fork 2
/
vec3.h
280 lines (245 loc) · 6.57 KB
/
vec3.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
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
#ifndef VEC3_H
#define VEC3_H
#include <stdint.h>
/**
* Calculates the length of a vec3
*
* @param {vec3} a vector to calculate length of
* @returns {Number} length of a
*/
float vec3_length(float* a);
/**
* Copy the values from one vec3 to another
*
* @param {vec3} out the receiving vector
* @param {vec3} a the source vector
*/
void vec3_copy(float* dst, float* a);
/**
* Set the components of a vec3 to the given values
*
* @param {vec3} out the receiving vector
* @param {Number} x X component
* @param {Number} y Y component
* @param {Number} z Z component
*/
void vec3_set(float* dst, float x, float y, float z);
/**
* Adds two vec3's
*
* @param {vec3} out the receiving vector
* @param {vec3} b the second operand
*/
void vec3_add(float* dst, float* b);
/**
* Subtracts vector b from vector a
*
* @param {vec3} out the receiving vector
* @param {vec3} b the second operand
*/
void vec3_subtract(float* dst, float* b);
/**
* Multiplies two vec3's
*
* @param {vec3} out the receiving vector
* @param {vec3} b the second operand
*/
void vec3_multiply(float* dst, float* b);
/**
* Divides two vec3's
*
* @param {vec3} out the receiving vector
* @param {vec3} b the second operand
*/
void vec3_divide(float* dst, float* b);
/**
* Math.ceil the components of a vec3
*
* @param {vec3} out the receiving vector
*/
void vec3_ceil(float* dst);
/**
* Math.floor the components of a vec3
*
* @param {vec3} out the receiving vector
*/
void vec3_floor(float* dst);
/**
* Returns the minimum of two vec3's
*
* @param {vec3} out the receiving vector
* @param {vec3} b the second operand
*/
void vec3_min(float* dst, float* b);
/**
* Returns the maximum of two vec3's
*
* @param {vec3} out the receiving vector
* @param {vec3} b the second operand
*/
void vec3_max(float* dst, float* b);
/**
* Math.round the components of a vec3
*
* @param {vec3} out the receiving vector
*/
void vec3_round(float* dst);
/**
* Scales a vec3 by a scalar number
*
* @param {vec3} out the receiving vector
* @param {Number} b amount to scale the vector by
*/
void vec3_scale(float* dst, float b);
/**
* Adds two vec3's after scaling the second operand by a scalar value
*
* @param {vec3} out the receiving vector
* @param {vec3} b the second operand
* @param {Number} scale the amount to scale b by before adding
*/
void vec3_scaleAndAdd(float* dst, float* b, float scale);
/**
* Calculates the euclidian distance between two vec3's
*
* @param {vec3} a the first operand
* @param {vec3} b the second operand
* @returns {Number} distance between a and b
*/
float vec3_distance(float* a, float* b);
/**
* Calculates the squared euclidian distance between two vec3's
*
* @param {vec3} a the first operand
* @param {vec3} b the second operand
* @returns {Number} squared distance between a and b
*/
float vec3_squaredDistance(float* a, float* b);
/**
* Calculates the squared length of a vec3
*
* @param {vec3} a vector to calculate squared length of
* @returns {Number} squared length of a
*/
float vec3_squaredLength(float* a);
/**
* Negates the components of a vec3
*
* @param {vec3} out the receiving vector
*/
void vec3_negate(float* dst);
/**
* Returns the inverse of the components of a vec3
*
* @param {vec3} out the receiving vector
*/
void vec3_inverse(float* dst);
/**
* Normalize a vec3
*
* @param {vec3} out the receiving vector
*/
void vec3_normalize(float* dst);
/**
* Calculates the dot product of two vec3's
*
* @param {vec3} a the first operand
* @param {vec3} b the second operand
* @returns {Number} dot product of a and b
*/
float vec3_dot(float* a, float* b);
/**
* Computes the cross product of two vec3's
*
* @param {vec3} out the receiving vector
* @param {vec3} b the second operand
*/
void vec3_cross(float* dst, float* b);
/**
* Performs a linear interpolation between two vec3's
*
* @param {vec3} out the receiving vector
* @param {vec3} b the second operand
* @param {Number} t interpolation amount, in the range [0-1], between the two inputs
*/
void vec3_lerp(float* dst, float* b, float t);
/**
* Performs a hermite interpolation with two control points
*
* @param {vec3} out the receiving vector
* @param {vec3} b the second operand
* @param {vec3} c the third operand
* @param {vec3} d the fourth operand
* @param {Number} t interpolation amount, in the range [0-1], between the two inputs
*/
void vec3_hermite(float* dst, float* b, float* c, float* d, float t);
/**
* Performs a bezier interpolation with two control points
*
* @param {vec3} out the receiving vector
* @param {vec3} b the second operand
* @param {vec3} c the third operand
* @param {vec3} d the fourth operand
* @param {Number} t interpolation amount, in the range [0-1], between the two inputs
*/
void vec3_bezier(float* dst, float* b, float* c, float* d, float t);
/**
* Transforms the vec3 with a mat4.
* 4th vector component is implicitly '1'
*
* @param {vec3} out the receiving vector
* @param {mat4} m matrix to transform with
*/
void vec3_transformMat4(float* dst, float* m);
/**
* Transforms the vec3 with a mat3.
*
* @param {vec3} out the receiving vector
* @param {mat3} m the 3x3 matrix to transform with
*/
void vec3_transformMat3(float* dst, float* m);
/**
* Transforms the vec3 with a quat
* Can also be used for dual quaternions. (Multiply it with the real part)
*
* @param {vec3} out the receiving vector
* @param {quat} q quaternion to transform with
*/
void vec3_transformQuat(float* dst, float* q);
/**
* Rotate a 3D vector around the x-axis
* @param {vec3} out The receiving vec3
* @param {vec3} b The origin of the rotation
* @param {Number} c The angle of rotation
*/
void vec3_rotateX(float* dst, float* b, float c);
/**
* Rotate a 3D vector around the y-axis
* @param {vec3} out The receiving vec3
* @param {vec3} b The origin of the rotation
* @param {Number} c The angle of rotation
*/
void vec3_rotateY(float* dst, float* b, float c);
/**
* Rotate a 3D vector around the z-axis
* @param {vec3} out The receiving vec3
* @param {vec3} b The origin of the rotation
* @param {Number} c The angle of rotation
*/
void vec3_rotateZ(float* dst, float* b, float c);
/**
* Get the angle between two 3D vectors
* @param {vec3} a The first operand
* @param {vec3} b The second operand
* @returns {Number} The angle in radians
*/
float vec3_angle(float* a, float* b);
/**
* Returns whether or not the vectors have exactly the same elements
*
* @param {vec3} a The first vector.
* @param {vec3} b The second vector.
* @returns {Boolean} True if the vectors are equal, false otherwise.
*/
uint8_t vec3_equals(float* a, float* b);
#endif