-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathgl-matrix.h
861 lines (788 loc) · 20 KB
/
gl-matrix.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
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
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
#ifndef GL_MATRIX_H
#define GL_MATRIX_H
#ifdef __cplusplus
extern "C" {
#endif
/*
* gl-matrix.c - High performance matrix and vector operations for OpenGL
* Version 1.2.3
*/
#define GL_MATRIX_MAJOR_VERSION 1
#define GL_MATRIX_MINOR_VERSION 2
#define GL_MATRIX_MICRO_VERSION 3
#define GL_MATRIX_VERSION "1.2.3"
/* Hex version number. A value of 0x010203 means version 1.2.3.
useful for comparisons. e.g. GL_MATRIX_VERSION_HEX >= 0x010203 */
#define GL_MATRIX_VERSION_HEX ((GL_MATRIX_MAJOR_VERSION << 16) | \
(GL_MATRIX_MINOR_VERSION << 8) | \
(GL_MATRIX_MICRO_VERSION))
typedef double *vec3_t;
typedef double *vec4_t;
typedef double *mat3_t;
typedef double *mat4_t;
typedef double *quat_t;
/*
* vec3_t - 3 Dimensional Vector
*/
/*
* vec3_create
* Creates a new instance of a vec3_t
*
* Params:
* vec - Optional, vec3_t containing values to initialize with. If NULL, the
* vector will be initialized with zeroes.
*
* Returns:
* New vec3
*/
vec3_t vec3_create(vec3_t vec);
/*
* vec3_set
* Copies the values of one vec3_t to another
*
* Params:
* vec - vec3_t containing values to copy
* dest - vec3_t receiving copied values
*
* Returns:
* dest
*/
vec3_t vec3_set(vec3_t vec, vec3_t dest);
/*
* vec3_add
* Performs a vector addition
*
* Params:
* vec - vec3, first operand
* vec2 - vec3, second operand
* dest - Optional, vec3_t receiving operation result. If NULL, result is written to vec
*
* Returns:
* dest if not NULL, vec otherwise
*/
vec3_t vec3_add(vec3_t vec, vec3_t vec2, vec3_t dest);
/*
* vec3_subtract
* Performs a vector subtraction
*
* Params:
* vec - vec3, first operand
* vec2 - vec3, second operand
* dest - Optional, vec3_t receiving operation result. If NULL, result is written to vec
*
* Returns:
* dest if not NULL, vec otherwise
*/
vec3_t vec3_subtract(vec3_t vec, vec3_t vec2, vec3_t dest);
/*
* vec3_multiply
* Performs a vector multiplication
*
* Params:
* vec - vec3, first operand
* vec2 - vec3, second operand
* dest - Optional, vec3_t receiving operation result. If NULL, result is written to vec
*
* Returns:
* dest if not NULL, vec otherwise
*/
vec3_t vec3_multiply(vec3_t vec, vec3_t vec2, vec3_t dest);
/*
* vec3_negate
* Negates the components of a vec3
*
* Params:
* vec - vec3_t to negate
* dest - Optional, vec3_t receiving operation result. If NULL, result is written to vec
*
* Returns:
* dest if not NULL, vec otherwise
*/
vec3_t vec3_negate(vec3_t vec, vec3_t dest);
/*
* vec3_scale
* Multiplies the components of a vec3_t by a scalar value
*
* Params:
* vec - vec3_t to scale
* val - Numeric value to scale by
* dest - Optional, vec3_t receiving operation result. If NULL, result is written to vec
*
* Returns:
* dest if not NULL, vec otherwise
*/
vec3_t vec3_scale(vec3_t vec, double val, vec3_t dest);
/*
* vec3_normalize
* Generates a unit vector of the same direction as the provided vec3
* If vector length is 0, returns [0, 0, 0]
*
* Params:
* vec - vec3_t to normalize
* dest - Optional, vec3_t receiving operation result. If NULL, result is written to vec
*
* Returns:
* dest if not NULL, vec otherwise
*/
vec3_t vec3_normalize(vec3_t vec, vec3_t dest);
/*
* vec3_cross
* Generates the cross product of two vec3s
*
* Params:
* vec - vec3, first operand
* vec2 - vec3, second operand
* dest - Optional, vec3_t receiving operation result. If NULL, result is written to vec
*
* Returns:
* dest if not NULL, vec otherwise
*/
vec3_t vec3_cross (vec3_t vec, vec3_t vec2, vec3_t dest);
/*
* vec3_length
* Caclulates the length of a vec3
*
* Params:
* vec - vec3_t to calculate length of
*
* Returns:
* Length of vec
*/
double vec3_length(vec3_t vec);
/*
* vec3_dot
* Caclulates the dot product of two vec3s
*
* Params:
* vec - vec3, first operand
* vec2 - vec3, second operand
*
* Returns:
* Dot product of vec and vec2
*/
double vec3_dot(vec3_t vec, vec3_t vec2);
/*
* vec3_direction
* Generates a unit vector pointing from one vector to another
*
* Params:
* vec - origin vec3
* vec2 - vec3_t to point to
* dest - Optional, vec3_t receiving operation result. If NULL, result is written to vec
*
* Returns:
* dest if not NULL, vec otherwise
*/
vec3_t vec3_direction (vec3_t vec, vec3_t vec2, vec3_t dest);
/*
* vec3_lerp
* Performs a linear interpolation between two vec3
*
* Params:
* vec - vec3, first vector
* vec2 - vec3, second vector
* lerp - interpolation amount between the two inputs
* dest - Optional, vec3_t receiving operation result. If NULL, result is written to vec
*
* Returns:
* dest if not NULL, vec otherwise
*/
vec3_t vec3_lerp(vec3_t vec, vec3_t vec2, double lerp, vec3_t dest);
/*
* vec3_dist
* Calculates the euclidian distance between two vec3
*
* Params:
* vec - vec3, first vector
* vec2 - vec3, second vector
*
* Returns:
* distance between vec and vec2
*/
double vec3_dist(vec3_t vec, vec3_t vec2);
/*
* vec3_unproject
* Projects the specified vec3_t from screen space into object space
* Based on Mesa gluUnProject implementation at:
* http://webcvs.freedesktop.org/mesa/Mesa/src/glu/mesa/project.c?revision=1.4&view=markup
*
* Params:
* vec - vec3, screen-space vector to project
* view - mat4, View matrix
* proj - mat4, Projection matrix
* viewport - vec4, Viewport as given to gl.viewport [x, y, width, height]
* dest - Optional, vec3_t receiving unprojected result. If NULL, result is written to vec
*
* Returns:
* dest if not NULL, vec otherwise
*/
vec3_t vec3_unproject(vec3_t vec, mat4_t view, mat4_t proj, vec4_t viewport, vec3_t dest);
/*
* vec3_str
* Writes a string representation of a vector
*
* Params:
* vec - vec3_t to represent as a string
* buffer - char * to store the results
*/
void vec3_str(vec3_t vec, char *buffer);
/*
* mat3_t - 3x3 Matrix
*/
/*
* mat3_create
* Creates a new instance of a mat3_t
*
* Params:
* mat - Optional, mat3_t containing values to initialize with. If NULL the result
* will be initialized with zeroes.
*
* Returns:
* New mat3
*/
mat3_t mat3_create(mat3_t mat);
/*
* mat3_set
* Copies the values of one mat3_t to another
*
* Params:
* mat - mat3_t containing values to copy
* dest - mat3_t receiving copied values
*
* Returns:
* dest
*/
mat3_t mat3_set(mat3_t mat, mat3_t dest);
/*
* mat3_identity
* Sets a mat3_t to an identity matrix
*
* Params:
* dest - mat3_t to set
*
* Returns:
* dest
*/
mat3_t mat3_identity(mat3_t dest);
/*
* mat4.transpose
* Transposes a mat3_t (flips the values over the diagonal)
*
* Params:
* mat - mat3_t to transpose
* dest - Optional, mat3_t receiving transposed values. If NULL, result is written to mat
*
* Returns:
* dest is specified, mat otherwise
*/
mat3_t mat3_transpose(mat3_t mat, mat3_t dest);
/*
* mat3_toMat4
* Copies the elements of a mat3_t into the upper 3x3 elements of a mat4
*
* Params:
* mat - mat3_t containing values to copy
* dest - Optional, mat4_t receiving copied values
*
* Returns:
* dest if not NULL, a new mat4_t otherwise
*/
mat4_t mat3_toMat4(mat3_t mat, mat4_t dest);
/*
* mat3_str
* Writes a string representation of a mat3
*
* Params:
* mat - mat3_t to represent as a string
* buffer - char * to store the results
*/
void mat3_str(mat3_t mat, char *buffer);
/*
* mat4_t - 4x4 Matrix
*/
/*
* mat4_create
* Creates a new instance of a mat4_t
*
* Params:
* mat - Optional, mat4_t containing values to initialize with
*
* Returns:
* New mat4
*/
mat4_t mat4_create(mat4_t mat);
/*
* mat4_set
* Copies the values of one mat4_t to another
*
* Params:
* mat - mat4_t containing values to copy
* dest - mat4_t receiving copied values
*
* Returns:
* dest
*/
mat4_t mat4_set(mat4_t mat, mat4_t dest);
/*
* mat4_identity
* Sets a mat4_t to an identity matrix
*
* Params:
* dest - mat4_t to set
*
* Returns:
* dest
*/
mat4_t mat4_identity(mat4_t dest);
/*
* mat4_transpose
* Transposes a mat4_t (flips the values over the diagonal)
*
* Params:
* mat - mat4_t to transpose
* dest - Optional, mat4_t receiving transposed values. If NULL, result is written to mat
*
* Returns:
* dest is specified, mat otherwise
*/
mat4_t mat4_transpose(mat4_t mat, mat4_t dest);
/*
* mat4_determinant
* Calculates the determinant of a mat4
*
* Params:
* mat - mat4_t to calculate determinant of
*
* Returns:
* determinant of mat
*/
double mat4_determinant(mat4_t mat);
/*
* mat4_inverse
* Calculates the inverse matrix of a mat4
*
* Params:
* mat - mat4_t to calculate inverse of
* dest - Optional, mat4_t receiving inverse matrix. If NULL, result is written to mat
*
* Returns:
* dest is specified, mat otherwise, NULL if matrix cannot be inverted
*/
mat4_t mat4_inverse(mat4_t mat, mat4_t dest);
/*
* mat4_toRotationMat
* Copies the upper 3x3 elements of a mat4_t into another mat4
*
* Params:
* mat - mat4_t containing values to copy
* dest - Optional, mat4_t receiving copied values
*
* Returns:
* dest is specified, a new mat4_t otherwise
*/
mat4_t mat4_toRotationMat(mat4_t mat, mat4_t dest);
/*
* mat4_toMat3
* Copies the upper 3x3 elements of a mat4_t into a mat3
*
* Params:
* mat - mat4_t containing values to copy
* dest - Optional, mat3_t receiving copied values
*
* Returns:
* dest is specified, a new mat3_t otherwise
*/
mat3_t mat4_toMat3(mat4_t mat, mat3_t dest);
/*
* mat4_toInverseMat3
* Calculates the inverse of the upper 3x3 elements of a mat4_t and copies the result into a mat3
* The resulting matrix is useful for calculating transformed normals
*
* Params:
* mat - mat4_t containing values to invert and copy
* dest - Optional, mat3_t receiving values
*
* Returns:
* dest is specified, a new mat3_t otherwise, NULL if the matrix cannot be inverted
*/
mat3_t mat4_toInverseMat3(mat4_t mat, mat3_t dest);
/*
* mat4_multiply
* Performs a matrix multiplication
*
* Params:
* mat - mat4, first operand
* mat2 - mat4, second operand
* dest - Optional, mat4_t receiving operation result. If NULL, result is written to mat
*
* Returns:
* dest if not NULL, mat otherwise
*/
mat4_t mat4_multiply(mat4_t mat, mat4_t mat2, mat4_t dest);
/*
* mat4_multiplyVec3
* Transforms a vec3_t with the given matrix
* 4th vector component is implicitly '1'
*
* Params:
* mat - mat4_t to transform the vector with
* vec - vec3_t to transform
* dest - Optional, vec3_t receiving operation result. If NULL, result is written to vec
*
* Returns:
* dest if not NULL, vec otherwise
*/
mat4_t mat4_multiplyVec3(mat4_t mat, vec3_t vec, mat4_t dest);
/*
* mat4_multiplyVec4
* Transforms a vec4 with the given matrix
*
* Params:
* mat - mat4_t to transform the vector with
* vec - vec4 to transform
* dest - Optional, vec4 receiving operation result. If NULL, result is written to vec
*
* Returns:
* dest if not NULL, vec otherwise
*/
mat4_t mat4_multiplyVec4(mat4_t mat, vec4_t vec, mat4_t dest);
/*
* mat4_translate
* Translates a matrix by the given vector
*
* Params:
* mat - mat4_t to translate
* vec - vec3_t specifying the translation
* dest - Optional, mat4_t receiving operation result. If NULL, result is written to mat
*
* Returns:
* dest if not NULL, mat otherwise
*/
mat4_t mat4_translate(mat4_t mat, vec3_t vec, mat4_t dest);
/*
* mat4_scale
* Scales a matrix by the given vector
*
* Params:
* mat - mat4_t to scale
* vec - vec3_t specifying the scale for each axis
* dest - Optional, mat4_t receiving operation result. If NULL, result is written to mat
*
* Returns:
* dest if not NULL, mat otherwise
*/
mat4_t mat4_scale(mat4_t mat, vec3_t vec, mat4_t dest);
/*
* mat4_rotate
* Rotates a matrix by the given angle around the specified axis
* If rotating around a primary axis (X,Y,Z) one of the specialized rotation functions should be used instead for performance
*
* Params:
* mat - mat4_t to rotate
* angle - angle (in radians) to rotate
* axis - vec3_t representing the axis to rotate around
* dest - Optional, mat4_t receiving operation result. If NULL, result is written to mat
*
* Returns:
* dest if not NULL, mat otherwise
*/
mat4_t mat4_rotate(mat4_t mat, double angle, vec3_t axis, mat4_t dest);
/*
* mat4_rotateX
* Rotates a matrix by the given angle around the X axis
*
* Params:
* mat - mat4_t to rotate
* angle - angle (in radians) to rotate
* dest - Optional, mat4_t receiving operation result. If NULL, result is written to mat
*
* Returns:
* dest if not NULL, mat otherwise
*/
mat4_t mat4_rotateX(mat4_t mat, double angle, mat4_t dest);
/*
* mat4_rotateY
* Rotates a matrix by the given angle around the Y axis
*
* Params:
* mat - mat4_t to rotate
* angle - angle (in radians) to rotate
* dest - Optional, mat4_t receiving operation result. If NULL, result is written to mat
*
* Returns:
* dest if not NULL, mat otherwise
*/
mat4_t mat4_rotateY(mat4_t mat, double angle, mat4_t dest);
/*
* mat4_rotateZ
* Rotates a matrix by the given angle around the Z axis
*
* Params:
* mat - mat4_t to rotate
* angle - angle (in radians) to rotate
* dest - Optional, mat4_t receiving operation result. If NULL, result is written to mat
*
* Returns:
* dest if not NULL, mat otherwise
*/
mat4_t mat4_rotateZ(mat4_t mat, double angle, mat4_t dest);
/*
* mat4_frustum
* Generates a frustum matrix with the given bounds
*
* Params:
* left, right - scalar, left and right bounds of the frustum
* bottom, top - scalar, bottom and top bounds of the frustum
* near, far - scalar, near and far bounds of the frustum
* dest - Optional, mat4_t frustum matrix will be written into
*
* Returns:
* dest if not NULL, a new mat4_t otherwise
*/
mat4_t mat4_frustum(double left, double right, double bottom, double top, double near, double far, mat4_t dest);
/*
* mat4_perspective
* Generates a perspective projection matrix with the given bounds
*
* Params:
* fovy - scalar, vertical field of view
* aspect - scalar, aspect ratio. typically viewport width/height
* near, far - scalar, near and far bounds of the frustum
* dest - Optional, mat4_t frustum matrix will be written into
*
* Returns:
* dest if not NULL, a new mat4_t otherwise
*/
mat4_t mat4_perspective(double fovy, double aspect, double near, double far, mat4_t dest);
/*
* mat4_ortho
* Generates a orthogonal projection matrix with the given bounds
*
* Params:
* left, right - scalar, left and right bounds of the frustum
* bottom, top - scalar, bottom and top bounds of the frustum
* near, far - scalar, near and far bounds of the frustum
* dest - Optional, mat4_t frustum matrix will be written into
*
* Returns:
* dest if not NULL, a new mat4_t otherwise
*/
mat4_t mat4_ortho(double left, double right, double bottom, double top, double near, double far, mat4_t dest);
/*
* mat4_lookAt
* Generates a look-at matrix with the given eye position, focal point, and up axis
*
* Params:
* eye - vec3, position of the viewer
* center - vec3, point the viewer is looking at
* up - vec3_t pointing "up"
* dest - Optional, mat4_t frustum matrix will be written into
*
* Returns:
* dest if not NULL, a new mat4_t otherwise
*/
mat4_t mat4_lookAt(vec3_t eye, vec3_t center, vec3_t up, mat4_t dest);
/*
* mat4_fromRotationTranslation
* Creates a matrix from a quaternion rotation and vector translation
* This is equivalent to (but much faster than):
*
* mat4_identity(dest);
* mat4_translate(dest, vec);
* mat4_t quatMat = mat4_create();
* quat_toMat4(quat, quatMat);
* mat4_multiply(dest, quatMat);
*
* Params:
* quat - quat specifying the rotation by
* vec - vec3_t specifying the translation
* dest - Optional, mat4_t receiving operation result. If NULL, result is written to a new mat4
*
* Returns:
* dest if not NULL, a new mat4_t otherwise
*/
mat4_t mat4_fromRotationTranslation(quat_t quat, vec3_t vec, mat4_t dest);
/*
* mat4_str
* Writes a string representation of a mat4
*
* Params:
* mat - mat4_t to represent as a string
* buffer - char * to store the results
*/
void mat4_str(mat4_t mat, char *buffer);
/*
* quat - Quaternions
*/
/*
* quat_create
* Creates a new instance of a quat_t
*
* Params:
* quat - Optional, quat_t containing values to initialize with
*
* Returns:
* New quat_t
*/
quat_t quat_create(quat_t quat);
/*
* quat_set
* Copies the values of one quat_t to another
*
* Params:
* quat - quat_t containing values to copy
* dest - quat_t receiving copied values
*
* Returns:
* dest
*/
quat_t quat_set(quat_t quat, quat_t dest);
/*
* quat_calculateW
* Calculates the W component of a quat_t from the X, Y, and Z components.
* Assumes that quaternion is 1 unit in length.
* Any existing W component will be ignored.
*
* Params:
* quat - quat_t to calculate W component of
* dest - Optional, quat_t receiving calculated values. If NULL, result is written to quat
*
* Returns:
* dest if not NULL, quat otherwise
*/
quat_t quat_calculateW(quat_t quat, quat_t dest);
/**
* quat_dot
* Calculates the dot product of two quaternions
*
* @param {quat4} quat First operand
* @param {quat4} quat2 Second operand
*
* @return {number} Dot product of quat and quat2
*/
double quat_dot(quat_t quat, quat_t quat2);
/*
* quat_inverse
* Calculates the inverse of a quat_t
*
* Params:
* quat - quat_t to calculate inverse of
* dest - Optional, quat_t receiving inverse values. If NULL, result is written to quat
*
* Returns:
* dest if not NULL, quat otherwise
*/
quat_t quat_inverse(quat_t quat, quat_t dest);
/*
* quat_conjugate
* Calculates the conjugate of a quat_t
*
* Params:
* quat - quat_t to calculate conjugate of
* dest - Optional, quat_t receiving conjugate values. If NULL, result is written to quat
*
* Returns:
* dest if not NULL, quat otherwise
*/
quat_t quat_conjugate(quat_t quat, quat_t dest);
/*
* quat_length
* Calculates the length of a quat_t
*
* Params:
* quat - quat_t to calculate length of
*
* Returns:
* Length of quat
*/
double quat_length(quat_t quat);
/*
* quat_normalize
* Generates a unit quaternion of the same direction as the provided quat_t
* If quaternion length is 0, returns [0, 0, 0, 0]
*
* Params:
* quat - quat_t to normalize
* dest - Optional, quat_ receiving operation result. If NULL, result is written to quat
*
* Returns:
* dest if not NULL, quat otherwise
*/
quat_t quat_normalize(quat_t quat, quat_t dest);
/*
* quat_multiply
* Performs a quaternion multiplication
*
* Params:
* quat - quat_t, first operand
* quat2 - quat_t, second operand
* dest - Optional, quat_t receiving operation result. If NULL, result is written to quat
*
* Returns:
* dest if not NULL, quat otherwise
*/
quat_t quat_multiply(quat_t quat, quat_t quat2, quat_t dest);
/*
* quat_multiplyVec3
* Transforms a vec3_t with the given quaternion
*
* Params:
* quat - quat_t to transform the vector with
* vec - vec3_t to transform
* dest - Optional, vec3_t receiving operation result. If NULL, result is written to vec
*
* Returns:
* dest if not NULL, vec otherwise
*/
quat_t quat_multiplyVec3(quat_t quat, vec3_t vec, vec3_t dest);
/*
* quat_toMat3
* Calculates a 3x3 matrix from the given quat_t
*
* Params:
* quat - quat_t to create matrix from
* dest - Optional, mat3_t receiving operation result
*
* Returns:
* dest if not NULL, a new mat3_t otherwise
*/
mat3_t quat_toMat3(quat_t quat, mat3_t dest);
/*
* quat_toMat4
* Calculates a 4x4 matrix from the given quat_t
*
* Params:
* quat - quat_t to create matrix from
* dest - Optional, mat4_t receiving operation result
*
* Returns:
* dest if not NULL, a new mat4_t otherwise
*/
quat_t quat_toMat4(quat_t quat, mat4_t dest);
/*
* quat_slerp
* Performs a spherical linear interpolation between two quat_t
*
* Params:
* quat - quat_t, first quaternion
* quat2 - quat_t, second quaternion
* slerp - interpolation amount between the two inputs
* dest - Optional, quat_t receiving operation result. If NULL, result is written to quat
*
* Returns:
* dest if not NULL, quat otherwise
*/
quat_t quat_slerp(quat_t quat, quat_t quat2, double slerp, quat_t dest);
/*
* quat_str
* Writes a string representation of a quaternion
*
* Params:
* quat - quat_t to represent as a string
* buffer - char * to store the results
*/
void quat_str(quat_t quat, char *buffer);
#ifdef __cplusplus
}
#endif
#endif