summaryrefslogtreecommitdiff
path: root/src/cglm_bindings.h
blob: 61554e36a9f24ca2687bf1d7d2f0e24688a15c7e (plain)
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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
#ifndef HONEY_CGLM_BINDINGS_H
#define HONEY_CGLM_BINDINGS_H

/** @file cglm_bindings.h
 * @brief Lua bindings for CGLM functions. 
 */

#include "common.h"

/** @brief Push the honey cglm binding functions to the lua stack.
 *
 * @returns Nothing.
 */
void honey_setup_cglm(lua_State* L);

/** @brief Push a new float array to the lua stack.
 *
 * This function initializes the array to all zeros.
 *
 * @param[in] n The size of the floating-point array to create.
 *
 * @returns The vector so generated.
 */
int honey_cglm_new_array_zero(lua_State* L);

/** @brief Set an element of a float array.
 *
 * This function does NOT check if your index is out of bounds.
 * Use caution!
 *
 * @param[in] array The array to modify.
 * @param[in] index The index to set.
 * @param[in] value The value to set array[index] to.
 *
 * @returns Nothing.
 */
int honey_cglm_array_set_value(lua_State* L);

/** @brief Get an element of a vec3.
 *
 * This function does NOT check if your index is out of bounds.
 * Use caution!
 *
 * @param[in] array The array to inspect.
 * @param[in] index The index to get.
 *
 * @returns The value at array[index].
 */
int honey_cglm_array_get_value(lua_State* L);

/** @brief Create a copy of a floating point array.
 *
 * @param[in] array The array to copy.
 * @param[in] n The size of the array.
 *
 * @returns A copy of the array.
 */
int honey_cglm_array_copy(lua_State* L);

/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
 *
 * cglm vec3 functions
 *
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 */

/** @brief Compute the dot product of two vectors.
 *
 * @param[in] a Vector a.
 * @param[in] b Vector b.
 *
 * @returns dot(a,b).
 */
int honey_cglm_vec3_dot(lua_State* L);

/** @brief Compute the square of the norm of a vector.
 *
 * Use this if you are tempted to compute norm*norm;
 * it avoids the two calls to sqrt.
 *
 * @param[in] v The vector to compute norm^2 for.
 *
 * @returns norm(v)^2.
 */
int honey_cglm_vec3_norm2(lua_State* L);

/** @brief Compute the norm of a vector.
 *
 * @param[in] v The vector.
 *
 * @returns norm(v).
 */
int honey_cglm_vec3_norm(lua_State* L);

/** @brief Add two vectors together.
 *
 * @param[in] a The first vector.
 * @param[in] b The second vector.
 * @param[out] dest vec3 to fill with a + b.
 *
 * @returns Nothing.
 */
int honey_cglm_vec3_add(lua_State* L);

/** @brief Subtract one vector from another.
 *
 * @param[in] a The first vector.
 * @param[in] b The second vector.
 * @param[out] dest Vector to fill with a - b
 *
 * @returns Nothing.
 */
int honey_cglm_vec3_sub(lua_State* L);

/** @brief Add a scalar to a vector.
 *
 * @param[in] a The scalar.
 * @param[in] v The vector.
 * @param[out] dest vec3 to fill with a + v
 *
 * @returns Nothing.
 */
int honey_cglm_vec3_adds(lua_State* L);

/** @param Component-wise multiply two vectors together.
 *
 * @param[in] a The first vector.
 * @param[in] b The second vector.
 * @param[out] dest vec3 to fill with [ a.x*b.x, a.y*b.y, a.z*b.z, a.w*b.w ]
 *
 * @returns Nothing.
 */
int honey_cglm_vec3_mul(lua_State* L);

/** @brief Multiply a vector by a scalar.
 *
 * @param[in] a The scalar.
 * @param[in] v The vector.
 * @param[out] dest vec3 to fill with a*v.
 *
 * @returns Nothing.
 */
int honey_cglm_vec3_muls(lua_State* L);

/** @brief Normalize a vector.
 *
 * @param[in,out] v The vector.
 *
 * @returns Nothing.
 */
int honey_cglm_vec3_normalize(lua_State* L);

/** @brief Compute the distance between two vectors.
 *
 * @param[in] a The first vector.
 * @param[in] b The second vector.
 *
 * @returns norm(a-b).
 */
int honey_cglm_vec3_distance(lua_State* L);

/** @brief Linearly interpolate between two values.
 *
 * @param[in] a The first vector.
 * @param[in] b The second vector.
 * @param[in] s A scalar.
 * @param[out] dest vec3 to fill with a + s*(b-s).
 *
 * @returns Nothing.
 */
int honey_cglm_vec3_lerp(lua_State* L);

/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *
 * cglm vec4 functions
 *
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 */

/** @brief Compute the dot product of two vectors.
 *
 * @param[in] a Vector a.
 * @param[in] b Vector b.
 *
 * @returns dot(a,b).
 */
int honey_cglm_vec4_dot(lua_State* L);

/** @brief Compute the square of the norm of a vector.
 *
 * Use this if you are tempted to compute norm*norm;
 * it avoids the two calls to sqrt.
 *
 * @param[in] v The vector to compute norm^2 for.
 *
 * @returns norm(v)^2.
 */
int honey_cglm_vec4_norm2(lua_State* L);

/** @brief Compute the norm of a vector.
 *
 * @param[in] v The vector.
 *
 * @returns norm(v).
 */
int honey_cglm_vec4_norm(lua_State* L);

/** @brief Add two vectors together.
 *
 * @param[in] a The first vector.
 * @param[in] b The second vector.
 * @param[out] dest vec4 to fill with a + b.
 *
 * @returns Nothing.
 */
int honey_cglm_vec4_add(lua_State* L);

/** @brief Add a scalar to a vector.
 *
 * @param[in] a The scalar.
 * @param[in] v The vector.
 * @param[out] dest vec4 to fill with a + v
 *
 * @returns Nothing.
 */
int honey_cglm_vec4_adds(lua_State* L);

/** @brief Subtract one vector from another.
 *
 * @param[in] a The first vector.
 * @param[in] b The second vector.
 * @param[out] dest vec4 to fill with a - b.
 *
 * @returns Nothing.
 */
int honey_cglm_vec4_sub(lua_State* L);

/** @param Component-wise multiply two vectors together.
 *
 * @param[in] a The first vector.
 * @param[in] b The second vector.
 * @param[out] dest vec4 to fill with [ a.x*b.x, a.y*b.y, a.z*b.z, a.w*b.w ]
 *
 * @returns Nothing.
 */
int honey_cglm_vec4_mul(lua_State* L);

/** @brief Multiply a vector by a scalar.
 *
 * @param[in] a The scalar.
 * @param[in] v The vector.
 * @param[out] dest vec4 to fill with a*v.
 *
 * @returns Nothing.
 */
int honey_cglm_vec4_muls(lua_State* L);

/** @brief Normalize a vector.
 *
 * @param[in,out] v The vector.
 *
 * @returns Nothing.
 */
int honey_cglm_vec4_normalize(lua_State* L);

/** @brief Compute the distance between two vectors.
 *
 * @param[in] a The first vector.
 * @param[in] b The second vector.
 *
 * @returns norm(a-b).
 */
int honey_cglm_vec4_distance(lua_State* L);

/** @brief Linearly interpolate between two values.
 *
 * @param[in] a The first vector.
 * @param[in] b The second vector.
 * @param[in] s A scalar.
 * @param[out] dest vec4 to fill with a + s*(b-s).
 *
 * @returns Nothing.
 */
int honey_cglm_vec4_lerp(lua_State* L);

/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *
 * cglm mat3 functions
 *
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 */

/** @brief Set a matrix to be the identity matrix.
 *
 * @param[out] matrix The matrix to set to the identity.
 *
 * @returns Nothing.
 */
int honey_cglm_mat3_identity(lua_State* L);

/** @brief Multiply two mat3s together.
 *
 * @param[in] A The first matrix.
 * @param[in] B The second matrix.
 * @param[out] dest mat3 to fill with A*B.
 *
 * @returns Nothing.
 */
int honey_cglm_mat3_mul(lua_State* L);

/** @brief Multiply a matrix by a scalar.
 *
 * @param[in] a The scalar.
 * @param[in,out] M The matrix.
 *
 * @returns Nothing.
 */
int honey_cglm_mat3_muls(lua_State* L);

/** @brief Multiply a matrix by a column vector.
 *
 * @param[in] M The matrix.
 * @param[in] v The column vector.
 * @param[out] dest Matrix to fill with M*v.
 *
 * @returns Nothing.
 */
int honey_cglm_mat3_mulv(lua_State* L);

/** @brief Transpose a matrix.
 *
 * @param[in,out] M The matrix to transpose.
 *
 * @returns Nothing.
 */
int honey_cglm_mat3_trans(lua_State* L);

/** @brief Get the determinant of a matrix.
 *
 * @param[in] M The matrix.
 *
 * @returns det(M).
 */
int honey_cglm_mat3_det(lua_State* L);

/** @brief Get the trace of a matrix.
 *
 * @param[in] M The matrix.
 *
 * @returns trace(M).
 */
int honey_cglm_mat3_trace(lua_State* L);

/** @brief Get the inverse of a matrix.
 *
 * @param[in] M The matrix to invert.
 * @param[out] dest Matrix to fill with inv(M).
 *
 * @returns Nothing.
 */
int honey_cglm_mat3_inv(lua_State* L);

/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *
 * cglm mat4 functions
 *
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 */

/** @brief Set a matrix to be the identity matrix.
 *
 * @param[out] matrix The matrix to set to the identity.
 *
 * @returns Nothing.
 */
int honey_cglm_mat4_identity(lua_State* L);

/** @brief Get the upper left of a matrix as a mat3.
 *
 * @param[in] matrix The matrix to extract.
 * @param[out] dest The 3x3 matrix to fill.
 *
 * @returns Nothing.
 */
int honey_cglm_mat4_pick3(lua_State* L);

/** @brief Multiply two mat4s together.
 *
 * @param[in] A The first matrix.
 * @param[in] B The second matrix.
 * @param[out] dest mat4 to fill with A*B.
 *
 * @returns Nothing.
 */
int honey_cglm_mat4_mul(lua_State* L);

/** @brief Multiply a matrix by a scalar.
 *
 * @param[in] a The scalar.
 * @param[in,out] M The matrix.
 *
 * @returns Nothing.
 */
int honey_cglm_mat4_muls(lua_State* L);

/** @brief Multiply a matrix by a column vector.
 *
 * @param[in] M The matrix.
 * @param[in] v The column vector.
 * @param[out] dest Matrix to fill with M*v.
 *
 * @returns Nothing.
 */
int honey_cglm_mat4_mulv(lua_State* L);

/** @brief Transpose a matrix.
 *
 * @param[in,out] M The matrix to transpose.
 *
 * @returns Nothing.
 */
int honey_cglm_mat4_trans(lua_State* L);

/** @brief Get the determinant of a matrix.
 *
 * @param[in] M The matrix.
 *
 * @returns det(M).
 */
int honey_cglm_mat4_det(lua_State* L);

/** @brief Get the trace of a matrix.
 *
 * @param[in] M The matrix.
 *
 * @returns trace(M).
 */
int honey_cglm_mat4_trace(lua_State* L);

/** @brief Get the inverse of a matrix.
 *
 * This is the precise version; use honey_cglm_mat4_inv_fast
 * for a faster but less precise version.
 *
 * @param[in] M The matrix to invert.
 * @param[out] dest Matrix to fill with inv(M).
 *
 * @returns Nothing.
 */
int honey_cglm_mat4_inv(lua_State* L);

/** @brief Get the inverse of a matrix.
 *
 * This is the fast version; use honey_cglm_mat4_inv
 * for a slower but more precise version.
 *
 * @param[in] M The matrix to invert.
 * @param[out] dest Matrix to fill with inv(M).
 *
 * @returns Nothing.
 */
int honey_cglm_mat4_inv_fast(lua_State* L);

/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *
 * cglm 3d affine transforms
 *
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 */

/** @brief Translate a matrix by a vector.
 *
 * This function modifies the matrix in place.
 *
 * @param[in,out] matrix The mat4 to translate.
 * @param[in] vector The vec3 to translate by.
 *
 * @returns Nothing.
 */
int honey_cglm_translate(lua_State* L);

/** @brief Scale a matrix by a vector.
 *
 * @param[in,out] matrix The mat4 to scale.
 * @param[in] vector The vec3 to scale by.
 *
 * @returns Nothing.
 */
int honey_cglm_scale(lua_State* L);

/** @brief Rotate a matrix about a given axis.
 *
 * @param[in,out] matrix The mat4 to rotate.
 * @param[in] center The vec3 center of rotation.
 * @param[in] axis The vec3 axis of rotation.
 * @param[in] angle The angle to rotate by.
 *
 * @returns Nothing.
 */
int honey_cglm_rotate(lua_State* L);

/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *
 * cglm camera matrix functions
 *
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 */

/** @brief Put perspective projection matrix into float array.
 *
 * @param[out] matrix The mat4 to populate.
 * @param[in] fov The FOV for the camera.
 * @param[in] aspect The aspect ratio to use with the camera.
 * @param[in] near Distance to the near clipping plane.
 * @param[in] far Distance to the far clipping plane.
 *
 * @returns Nothing.
 */
int honey_cglm_perspective(lua_State* L);

/** @brief Put an orthographic projection matrix into float array.
 *
 * @param[out] matrix The mat4 to populate.
 * @param[in] a The first vector of the AABB bounding box.
 * @param[in] b The second vector of the AABB bounding box.
 *
 * @returns Nothing.
 */
int honey_cglm_orthographic(lua_State* L);

/** @brief Compute the view matrix.
 *
 * @param[in] position The camera's vec3 position.
 * @param[in] direction The vec3 direction the camera is facing.
 * @param[in] up The camera's vec3 up vector.
 * @param[out] dest The view matrix destination.
 *
 * @returns Nothing.
 */
int honey_cglm_look(lua_State* L);


#endif