-
Notifications
You must be signed in to change notification settings - Fork 8
/
hypatia.h
4445 lines (3598 loc) · 114 KB
/
hypatia.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
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* SPDX-License-Identifier: MIT */
#ifndef _INC_HYPATIA
#define _INC_HYPATIA
#define HYPATIA_VERSION "2.0.0"
#ifndef HYPAPI
# ifdef HYP_STATIC
# define HYPAPI static
# else
# define HYPAPI extern
# endif
#endif
#ifndef HYP_DEF
# define HYPDEF HYPAPI
#endif
#ifndef HYP_INLINE
# ifdef _MSC_VER
# define HYP_INLINE __inline
# else
# define HYP_INLINE __inline__
# endif
#endif
#ifndef HYP_FLOAT
# ifdef HYPATIA_SINGLE_PRECISION_FLOATS
# define HYP_FLOAT float
# else
# define HYP_FLOAT double
# endif
#endif
#ifndef HYP_NO_C_MATH
# include <math.h> /* sin, cos, acos, fmod */
#endif
#ifndef HYP_NO_STDIO
# include <stdio.h> /* printf */
#endif
/**
* @ingroup _constants
* @{
*/
/** @brief PI to 100 digits (gets rounded off by the compiler) */
#ifndef HYP_PI
# define HYP_PI 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679f
#endif
/** @brief Tau to 100 digits, which is 2 * PI */
#ifndef HYP_TAU
# define HYP_TAU 6.2831853071795864769252867665590057683943387987502116419498891846156328125724179972560696506842341359f
#endif
/** @brief Half of PI */
#ifndef HYP_PI_HALF
# define HYP_PI_HALF 1.5707963267948966f
#endif
/** @brief PI * PI */
#ifndef HYP_PI_SQUARED
# define HYP_PI_SQUARED 9.8696044010893586f
#endif
/** @brief Log e is the Natural Logarithm in base 10 */
#ifndef HYP_E
# define HYP_E 2.71828182845904523536028747135266249775724709369995f
#endif
/** @brief Radians per Degree = PI/180 */
#ifndef HYP_RAD_PER_DEG
# define HYP_RAD_PER_DEG 0.0174532925199432957692369076848861f
#endif
/** @brief Degrees per Radian = 180/PI */
#ifndef HYP_DEG_PER_RAD
# define HYP_DEG_PER_RAD 57.2957795130823208767981548141052f
#endif
/** @brief PI/180 */
#ifndef HYP_PIOVER180
# define HYP_PIOVER180 HYP_RAD_PER_DEG
#endif
/** @brief 180/PI */
#ifndef HYP_PIUNDER180
# define HYP_PIUNDER180 HYP_DEG_PER_RAD
#endif
/** @brief Epsilon. This is the value that is used to determine how much
* rounding error is tolerated.
*/
#ifndef HYP_EPSILON
# ifdef HYPATIA_SINGLE_PRECISION_FLOATS
# define HYP_EPSILON 1E-5f
# else
# define HYP_EPSILON 1E-5
# endif
#endif
/*@}*/
/** @brief A macro that enabled you to override memset */
#ifndef HYP_MEMSET
# include <memory.h> /* memset */
# define HYP_MEMSET(a, b, c) memset(a, b, c)
#endif
/** @brief A function that returns the minimum of \a a and \a b */
static HYP_INLINE HYP_FLOAT HYP_MIN(HYP_FLOAT a, HYP_FLOAT b)
{
return (a < b) ? a : b;
}
/** @brief A macro that returns the maximum of \a a and \a b */
static HYP_INLINE HYP_FLOAT HYP_MAX(HYP_FLOAT a, HYP_FLOAT b)
{
return (a > b) ? b : a;
}
/** @brief A macro that swaps \a a and \a b */
static HYP_INLINE void HYP_SWAP(HYP_FLOAT *a, HYP_FLOAT *b)
{
HYP_FLOAT f = *a; *a = *b; *b = f;
}
/** @brief A macro that returns a random float point number up to RAND_MAX */
#ifndef HYP_RANDOM_FLOAT
# include <stdlib.h> /* RAND_MAX, rand */
# define HYP_RANDOM_FLOAT (((HYP_FLOAT)rand() - (HYP_FLOAT)rand()) / (HYP_FLOAT)RAND_MAX)
#endif
/** @brief A macro that converts an angle in degress to an angle in radians */
#ifndef HYP_DEG_TO_RAD
# define HYP_DEG_TO_RAD(angle) ((angle) * HYP_RAD_PER_DEG)
#endif
/** @brief A macro that converts an angle in radians to an angle in degrees */
#ifndef HYP_RAD_TO_DEG
# define HYP_RAD_TO_DEG(radians) ((radians) * HYP_DEG_PER_RAD)
#endif
/** @brief A macro that squares a value squared */
static HYP_INLINE HYP_FLOAT HYP_SQUARE(HYP_FLOAT number)
{
return number * number;
}
/** @brief A macro that finds the square root of a value */
#ifndef HYP_SQRT
# define HYP_SQRT(number) ((HYP_FLOAT)sqrt(number))
#endif
/** @brief A macro that returns the absolute value */
static HYP_INLINE HYP_FLOAT HYP_ABS(HYP_FLOAT value)
{
return (value < 0.0f) ? -value : value;
}
/** @brief A macro that wraps a value around and around in a range */
static HYP_INLINE HYP_FLOAT HYP_WRAP(HYP_FLOAT value, HYP_FLOAT start, HYP_FLOAT limit)
{
return (HYP_FLOAT)fmod(start + (value - start), (limit - start));
}
/** @brief A macro that constrains the value between two limits \a a and \a b */
static HYP_INLINE HYP_FLOAT HYP_CLAMP(HYP_FLOAT value, HYP_FLOAT start, HYP_FLOAT limit)
{
return ((value < start) ? start : (value > limit) ? limit : value);
}
#ifndef DOXYGEN_SHOULD_SKIP_THIS
/* forward declarations */
struct vector2;
struct vector3;
struct vector4;
struct matrix2;
struct matrix3;
struct matrix4;
struct quaternion;
#define HYP_REF_VECTOR2_ZERO 0
#define HYP_REF_VECTOR2_UNIT_X 1
#define HYP_REF_VECTOR2_UNIT_Y 2
#define HYP_REF_VECTOR2_UNIT_X_NEGATIVE 3
#define HYP_REF_VECTOR2_UNIT_Y_NEGATIVE 4
#define HYP_REF_VECTOR2_ONE 5
HYPAPI const struct vector2 *vector2_get_reference_vector2(int id);
#define HYP_REF_VECTOR3_ZERO 0
#define HYP_REF_VECTOR3_UNIT_X 1
#define HYP_REF_VECTOR3_UNIT_Y 2
#define HYP_REF_VECTOR3_UNIT_Z 3
#define HYP_REF_VECTOR3_UNIT_X_NEGATIVE 4
#define HYP_REF_VECTOR3_UNIT_Y_NEGATIVE 5
#define HYP_REF_VECTOR3_UNIT_Z_NEGATIVE 6
#define HYP_REF_VECTOR3_ONE 7
HYPAPI const struct vector3 *vector3_get_reference_vector3(int id);
#define HYP_REF_VECTOR4_ZERO 0
#define HYP_REF_VECTOR4_UNIT_X 1
#define HYP_REF_VECTOR4_UNIT_Y 2
#define HYP_REF_VECTOR4_UNIT_Z 3
#define HYP_REF_VECTOR4_UNIT_X_NEGATIVE 4
#define HYP_REF_VECTOR4_UNIT_Y_NEGATIVE 5
#define HYP_REF_VECTOR4_UNIT_Z_NEGATIVE 6
#define HYP_REF_VECTOR4_ONE 7
HYPAPI const struct vector4 *vector4_get_reference_vector4(int id);
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
/** @ingroup reference_vectors */
/** @brief {0,0,0} */
#define HYP_VECTOR3_ZERO vector3_get_reference_vector3(HYP_REF_VECTOR3_ZERO)
/** @ingroup reference_vectors */
/** @brief {1,0,0} */
#define HYP_VECTOR3_UNIT_X vector3_get_reference_vector3(HYP_REF_VECTOR3_UNIT_X)
/** @ingroup reference_vectors */
/** @brief {0,1,0} */
#define HYP_VECTOR3_UNIT_Y vector3_get_reference_vector3(HYP_REF_VECTOR3_UNIT_Y)
/** @ingroup reference_vectors */
/** @brief {0,0,1} */
#define HYP_VECTOR3_UNIT_Z vector3_get_reference_vector3(HYP_REF_VECTOR3_UNIT_Z)
/** @ingroup reference_vectors */
/** @brief {-1,0,0} */
#define HYP_VECTOR3_UNIT_X_NEGATIVE vector3_get_reference_vector3(HYP_REF_VECTOR3_UNIT_X_NEGATIVE)
/** @ingroup reference_vectors */
/** @brief {0,-1,0} */
#define HYP_VECTOR3_UNIT_Y_NEGATIVE vector3_get_reference_vector3(HYP_REF_VECTOR3_UNIT_Y_NEGATIVE)
/** @ingroup reference_vectors */
/** @brief {0,0,-1} */
#define HYP_VECTOR3_UNIT_Z_NEGATIVE vector3_get_reference_vector3(HYP_REF_VECTOR3_UNIT_Z_NEGATIVE)
/** @ingroup reference_vectors */
/** @brief {1,1,1} */
#define HYP_VECTOR3_ONE vector3_get_reference_vector3(HYP_REF_VECTOR3_ONE)
/* @} */
/** @ingroup reference_vectors */
/** @brief {0,0} */
#define HYP_VECTOR2_ZERO vector2_get_reference_vector2(HYP_REF_VECTOR2_ZERO)
/** @ingroup reference_vectors */
/** @brief {1,0} */
#define HYP_VECTOR2_UNIT_X vector2_get_reference_vector2(HYP_REF_VECTOR2_UNIT_X)
/** @ingroup reference_vectors */
/** @brief {0,1} */
#define HYP_VECTOR2_UNIT_Y vector2_get_reference_vector2(HYP_REF_VECTOR2_UNIT_Y)
/** @ingroup reference_vectors */
/** @brief {-1,0} */
#define HYP_VECTOR2_UNIT_X_NEGATIVE vector2_get_reference_vector2(HYP_REF_VECTOR2_UNIT_X_NEGATIVE)
/** @ingroup reference_vectors */
/** @brief {0,-1} */
#define HYP_VECTOR2_UNIT_Y_NEGATIVE vector2_get_reference_vector2(HYP_REF_VECTOR2_UNIT_Y_NEGATIVE)
/** @ingroup reference_vectors */
/** @brief {1,1} */
#define HYP_VECTOR2_ONE vector2_get_reference_vector2(HYP_REF_VECTOR2_ONE)
/* @} */
HYPAPI short scalar_equalsf(const HYP_FLOAT f1, const HYP_FLOAT f2);
HYPAPI short scalar_equals_epsilonf(const HYP_FLOAT f1, const HYP_FLOAT f2, const HYP_FLOAT epsilon);
#define scalar_equals scalar_equalsf
/**
* @ingroup trig
* @{
*/
#define HYP_SIN(x) ((HYP_FLOAT)sin(x))
#define HYP_COS(x) ((HYP_FLOAT)cos(x))
#define HYP_TAN(x) ((HYP_FLOAT)tan(x))
#define HYP_ASIN(x) ((HYP_FLOAT)asin(x))
#define HYP_ACOS(x) ((HYP_FLOAT)acos(x))
#define HYP_ATAN2(y, x) ((HYP_FLOAT)atan2(y, x))
#define HYP_COT(a) (1.0f / HYP_TAN(a))
/* @} */
/**
* @ingroup experimental
* @{
*/
HYPAPI void _matrix2_print_with_columnrow_indexer(struct matrix2 *self);
HYPAPI void _matrix2_print_with_rowcolumn_indexer(struct matrix2 *self);
HYPAPI struct matrix2 *_matrix2_set_random(struct matrix2 *self);
HYPAPI void _matrix3_print_with_columnrow_indexer(struct matrix3 *self);
HYPAPI void _matrix3_print_with_rowcolumn_indexer(struct matrix3 *self);
HYPAPI struct matrix3 *_matrix3_set_random(struct matrix3 *self);
HYPAPI void _matrix4_print_with_columnrow_indexer(struct matrix4 *self);
HYPAPI void _matrix4_print_with_rowcolumn_indexer(struct matrix4 *self);
HYPAPI struct matrix4 *_matrix4_set_random(struct matrix4 *self);
HYPAPI void _quaternion_print(const struct quaternion *self);
HYPAPI struct quaternion *_quaternion_set_random(struct quaternion *self);
HYPAPI void _vector3_print(const struct vector3 *self);
HYPAPI struct vector3 *_vector3_set_random(struct vector3 *self);
HYPAPI void _vector2_print(const struct vector2 *self);
HYPAPI struct vector2 *_vector2_set_random(struct vector2 *self);
HYPAPI void _vector4_print(const struct vector4 *self);
HYPAPI struct vector4 *_vector4_set_random(struct vector4 *self);
/* @} */
struct vector2 {
union {
HYP_FLOAT v[2];
struct {
HYP_FLOAT x, y;
};
};
};
HYPAPI int vector2_equals(const struct vector2 *self, const struct vector2 *vT);
HYPAPI struct vector2 *vector2_zero(struct vector2 *self);
HYPAPI struct vector2 *vector2_set(struct vector2 *self, const struct vector2 *vT);
HYPAPI struct vector2 *vector2_setf2(struct vector2 *self, HYP_FLOAT xT, HYP_FLOAT yT);
HYPAPI struct vector2 *vector2_negate(struct vector2 *self);
HYPAPI struct vector2 *vector2_add(struct vector2 *self, const struct vector2 *vT);
HYPAPI struct vector2 *vector2_addf(struct vector2 *self, HYP_FLOAT fT);
HYPAPI struct vector2 *vector2_subtract(struct vector2 *self, const struct vector2 *vT);
HYPAPI struct vector2 *vector2_subtractf(struct vector2 *self, HYP_FLOAT fT);
HYPAPI struct vector2 *vector2_multiply(struct vector2 *self, const struct vector2 *vT);
HYPAPI struct vector2 *vector2_multiplyf(struct vector2 *self, HYP_FLOAT fT);
HYPAPI struct vector2 *vector2_multiplym2(struct vector2 *self, const struct matrix2 *mT);
HYPAPI struct vector2 *vector2_multiplym3(struct vector2 *self, const struct matrix3 *mT);
HYPAPI struct vector2 *vector2_divide(struct vector2 *self, const struct vector2 *vT);
HYPAPI struct vector2 *vector2_dividef(struct vector2 *self, HYP_FLOAT fT);
HYPAPI struct vector2 *vector2_normalize(struct vector2 *self);
HYPAPI HYP_FLOAT vector2_magnitude(const struct vector2 *self);
HYPAPI HYP_FLOAT vector2_distance(const struct vector2 *v1, const struct vector2 *v2);
HYPAPI HYP_FLOAT vector2_dot_product(const struct vector2 *self, const struct vector2 *vT);
HYPAPI struct vector2 *vector2_cross_product(struct vector2 *vR, const struct vector2 *vT1, const struct vector2 *vT2);
HYPAPI HYP_FLOAT vector2_angle_between(const struct vector2 *self, const struct vector2 *vT);
HYPAPI struct vector2 *vector2_find_normal_axis_between(struct vector2 *vR, const struct vector2 *vT1, const struct vector2 *vT2);
/* the length is the same as "magnitude" */
#define vector2_length(v) vector2_magnitude(v)
#ifndef DOXYGEN_SHOULD_SKIP_THIS
/* BETA aliases */
#define vec2 struct vector2
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
struct vector3 {
union {
HYP_FLOAT v[3];
struct {
HYP_FLOAT x, y, z;
};
struct {
HYP_FLOAT yaw, pitch, roll;
};
};
};
HYPAPI int vector3_equals(const struct vector3 *self, const struct vector3 *vT);
HYPAPI struct vector3 *vector3_zero(struct vector3 *self);
HYPAPI struct vector3 *vector3_set(struct vector3 *self, const struct vector3 *vT);
HYPAPI struct vector3 *vector3_setf3(struct vector3 *self, HYP_FLOAT xT, HYP_FLOAT yT, HYP_FLOAT zT);
HYPAPI struct vector3 *vector3_negate(struct vector3 *self);
HYPAPI struct vector3 *vector3_add(struct vector3 *self, const struct vector3 *vT);
HYPAPI struct vector3 *vector3_addf(struct vector3 *self, HYP_FLOAT fT);
HYPAPI struct vector3 *vector3_subtract(struct vector3 *self, const struct vector3 *vT);
HYPAPI struct vector3 *vector3_subtractf(struct vector3 *self, HYP_FLOAT fT);
HYPAPI struct vector3 *vector3_multiply(struct vector3 *self, const struct vector3 *vT);
HYPAPI struct vector3 *vector3_multiplyf(struct vector3 *self, HYP_FLOAT fT);
HYPAPI struct vector3 *vector3_multiplym4(struct vector3 *self, const struct matrix4 *mT);
HYPAPI struct vector3 *vector3_divide(struct vector3 *self, const struct vector3 *vT);
HYPAPI struct vector3 *vector3_dividef(struct vector3 *self, HYP_FLOAT fT);
HYPAPI struct vector3 *vector3_normalize(struct vector3 *self);
HYPAPI HYP_FLOAT vector3_magnitude(const struct vector3 *self);
HYPAPI HYP_FLOAT vector3_distance(const struct vector3 *v1, const struct vector3 *v2);
HYPAPI HYP_FLOAT vector3_dot_product(const struct vector3 *self, const struct vector3 *vT);
HYPAPI struct vector3 *vector3_cross_product(struct vector3 *vR, const struct vector3 *vT1, const struct vector3 *vT2);
HYPAPI HYP_FLOAT vector3_angle_between(const struct vector3 *self, const struct vector3 *vT);
HYPAPI struct vector3 *vector3_find_normal_axis_between(struct vector3 *vR, const struct vector3 *vT1, const struct vector3 *vT2);
HYPAPI struct vector3 *vector3_rotate_by_quaternion(struct vector3 *self, const struct quaternion *qT);
HYPAPI struct vector3 *vector3_reflect_by_quaternion(struct vector3 *self, const struct quaternion *qT);
/*the length is the same as "magnitude" */
#define vector3_length(v) vector3_magnitude(v)
#ifndef DOXYGEN_SHOULD_SKIP_THIS
/*BETA aliases */
#define vec3 struct vector3
#endif /*DOXYGEN_SHOULD_SKIP_THIS */
struct vector4 {
union {
HYP_FLOAT v[4];
struct {
HYP_FLOAT x, y, z, w;
};
};
};
HYPAPI int vector4_equals(const struct vector4 *self, const struct vector4 *vT);
HYPAPI struct vector4 *vector4_zero(struct vector4 *self);
HYPAPI struct vector4 *vector4_set(struct vector4 *self, const struct vector4 *vT);
HYPAPI struct vector4 *vector4_setf4(struct vector4 *self, HYP_FLOAT xT, HYP_FLOAT yT, HYP_FLOAT zT, HYP_FLOAT wT);
HYPAPI struct vector4 *vector4_negate(struct vector4 *self);
HYPAPI struct vector4 *vector4_add(struct vector4 *self, const struct vector4 *vT);
HYPAPI struct vector4 *vector4_addf(struct vector4 *self, HYP_FLOAT fT);
HYPAPI struct vector4 *vector4_subtract(struct vector4 *self, const struct vector4 *vT);
HYPAPI struct vector4 *vector4_subtractf(struct vector4 *self, HYP_FLOAT fT);
HYPAPI struct vector4 *vector4_multiply(struct vector4 *self, const struct vector4 *vT);
HYPAPI struct vector4 *vector4_multiplyf(struct vector4 *self, HYP_FLOAT fT);
HYPAPI struct vector4 *vector4_divide(struct vector4 *self, const struct vector4 *vT);
HYPAPI struct vector4 *vector4_dividef(struct vector4 *self, HYP_FLOAT fT);
HYPAPI struct vector4 *vector4_normalize(struct vector4 *self);
HYPAPI HYP_FLOAT vector4_magnitude(const struct vector4 *self);
HYPAPI HYP_FLOAT vector4_distance(const struct vector4 *v1, const struct vector4 *v2);
HYPAPI HYP_FLOAT vector4_dot_product(const struct vector4 *self, const struct vector4 *vT);
HYPAPI struct vector4 *vector4_cross_product(struct vector4 *vR, const struct vector4 *vT1, const struct vector4 *vT2);
/* the length is the same as "magnitude" */
#define vector4_length(v) vector4_magnitude(v)
#ifndef DOXYGEN_SHOULD_SKIP_THIS
/* BETA aliases */
#define vec4 struct vector4
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
struct matrix2 {
union {
HYP_FLOAT m[4]; /* row-major numbering */
struct {
/* reference the matrix [row][column] */
HYP_FLOAT m22[2][2];
};
struct {
/* indexed (column-major numbering) */
HYP_FLOAT i00, i02;
HYP_FLOAT i01, i03;
};
struct {
/* col-row */
HYP_FLOAT c00, c10;
HYP_FLOAT c01, c11;
};
struct {
/* row-col */
HYP_FLOAT r00, r01;
HYP_FLOAT r10, r11;
};
};
};
HYPAPI int matrix2_equals(const struct matrix2 *self, const struct matrix2 *mT);
HYPAPI struct matrix2 *matrix2_zero(struct matrix2 *self);
HYPAPI struct matrix2 *matrix2_identity(struct matrix2 *self);
HYPAPI struct matrix2 *matrix2_set(struct matrix2 *self, const struct matrix2 *mT);
HYPAPI struct matrix2 *matrix2_add(struct matrix2 *self, const struct matrix2 *mT);
HYPAPI struct matrix2 *matrix2_subtract(struct matrix2 *self, const struct matrix2 *mT);
HYPAPI struct matrix2 *matrix2_multiply(struct matrix2 *self, const struct matrix2 *mT);
HYPAPI struct matrix2 *matrix2_multiplyf(struct matrix2 *self, HYP_FLOAT scalar);
HYPAPI struct vector2 *matrix2_multiplyv2(const struct matrix2 *self, const struct vector2 *vT, struct vector2 *vR);
HYPAPI struct matrix2 *matrix2_transpose(struct matrix2 *self);
HYPAPI HYP_FLOAT matrix2_determinant(const struct matrix2 *self);
HYPAPI struct matrix2 *matrix2_invert(struct matrix2 *self);
HYPAPI struct matrix2 *matrix2_inverse(const struct matrix2 *self, struct matrix2 *mR);
HYPAPI struct matrix2 *matrix2_make_transformation_scalingv2(struct matrix2 *self, const struct vector2 *scale);
HYPAPI struct matrix2 *matrix2_make_transformation_rotationf_z(struct matrix2 *self, HYP_FLOAT angle);
HYPAPI struct matrix2 *matrix2_rotate(struct matrix2 *self, HYP_FLOAT angle);
HYPAPI struct matrix2 *matrix2_scalev2(struct matrix2 *self, const struct vector2 *scale);
HYPAPI struct matrix2 *_matrix2_transpose_rowcolumn(struct matrix2 *self);
HYPAPI struct matrix2 *_matrix2_transpose_columnrow(struct matrix2 *self);
#ifndef DOXYGEN_SHOULD_SKIP_THIS
/* BETA aliases */
#define mat2 struct matrix2
#define mat2_equals matrix2_equals
#define mat2_zero matrix2_zero
#define mat2_identity matrix2_identity
#define mat2_set matrix2_setm2
#define mat2_add matrix2_add
#define mat2_sub matrix2_subtract
#define mat2_mul matrix2_multiply
#define mat2_transpose matrix2_transpose
#define mat2_rotate matrix2_rotate
#define mat2_scalev2 matrix2_scalev2
/*#define m2 struct matrix2*/
#define m2_equals matrix2_equals
#define m2_zero matrix2_zero
#define m2_identity matrix2_identity
#define m2_set matrix2_set
#define m2_add matrix2_add
#define m2_sub matrix2_subtract
#define m2_mul matrix2_multiply
#define m2_transpose matrix2_transpose
#define m2_rotate matrix2_rotate
#define m2_scalev2 matrix2_scalev2
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
struct matrix3 {
union {
HYP_FLOAT m[9]; /* row-major numbering */
struct {
/* reference the matrix [row][column] */
HYP_FLOAT m33[3][3];
};
struct {
/* indexed (column-major numbering) */
HYP_FLOAT i00, i03, i06;
HYP_FLOAT i01, i04, i07;
HYP_FLOAT i02, i05, i08;
};
struct {
/* col-row */
HYP_FLOAT c00, c10, c20;
HYP_FLOAT c01, c11, c21;
HYP_FLOAT c02, c12, c22;
};
struct {
/* row-col */
HYP_FLOAT r00, r01, r02;
HYP_FLOAT r10, r11, r12;
HYP_FLOAT r20, r21, r22;
};
};
};
HYPAPI int matrix3_equals(const struct matrix3 *self, const struct matrix3 *mT);
HYPAPI struct matrix3 *matrix3_zero(struct matrix3 *self);
HYPAPI struct matrix3 *matrix3_identity(struct matrix3 *self);
HYPAPI struct matrix3 *matrix3_set(struct matrix3 *self, const struct matrix3 *mT);
HYPAPI struct matrix3 *matrix3_add(struct matrix3 *self, const struct matrix3 *mT);
HYPAPI struct matrix3 *matrix3_subtract(struct matrix3 *self, const struct matrix3 *mT);
HYPAPI struct matrix3 *matrix3_multiply(struct matrix3 *self, const struct matrix3 *mT);
HYPAPI struct matrix3 *matrix3_multiplyf(struct matrix3 *self, HYP_FLOAT scalar);
HYPAPI struct vector2 *matrix3_multiplyv2(const struct matrix3 *self, const struct vector2 *vT, struct vector2 *vR);
HYPAPI struct matrix3 *matrix3_transpose(struct matrix3 *self);
HYPAPI HYP_FLOAT matrix3_determinant(const struct matrix3 *self);
HYPAPI struct matrix3 *matrix3_invert(struct matrix3 *self);
HYPAPI struct matrix3 *matrix3_inverse(const struct matrix3 *self, struct matrix3 *mR);
HYPAPI struct matrix3 *matrix3_make_transformation_translationv2(struct matrix3 *self, const struct vector2 *translation);
HYPAPI struct matrix3 *matrix3_make_transformation_scalingv2(struct matrix3 *self, const struct vector2 *scale);
HYPAPI struct matrix3 *matrix3_make_transformation_rotationf_z(struct matrix3 *self, HYP_FLOAT angle);
HYPAPI struct matrix3 *matrix3_translatev2(struct matrix3 *self, const struct vector2 *translation);
HYPAPI struct matrix3 *matrix3_rotate(struct matrix3 *self, HYP_FLOAT angle);
HYPAPI struct matrix3 *matrix3_scalev2(struct matrix3 *self, const struct vector2 *scale);
HYPAPI struct matrix3 *_matrix3_transpose_rowcolumn(struct matrix3 *self);
HYPAPI struct matrix3 *_matrix3_transpose_columnrow(struct matrix3 *self);
#ifndef DOXYGEN_SHOULD_SKIP_THIS
/* BETA aliases */
#define mat3 struct matrix3
#define mat3_equals matrix3_equals
#define mat3_zero matrix3_zero
#define mat3_identity matrix3_identity
#define mat3_set matrix3_setm3
#define mat3_add matrix3_add
#define mat3_sub matrix3_subtract
#define mat3_mul matrix3_multiply
#define mat3_transpose matrix3_transpose
#define mat3_translatev2 matrix3_translatev2
#define mat3_rotate matrix3_rotate
#define mat3_scalev2 matrix3_scalev2
#define m3 struct matrix3
#define m3_equals matrix3_equals
#define m3_zero matrix3_zero
#define m3_identity matrix3_identity
#define m3_set matrix3_set
#define m3_add matrix3_add
#define m3_sub matrix3_subtract
#define m3_mul matrix3_multiply
#define m3_transpose matrix3_transpose
#define m3_translatev2 matrix3_translatev2
#define m3_rotate matrix3_rotate
#define m3_scalev2 matrix3_scalev2
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
struct matrix4 {
union {
HYP_FLOAT m[16]; /* row-major numbering */
struct {
/* reference the matrix [row][column] */
HYP_FLOAT m44[4][4];
};
struct {
/* indexed (column-major numbering) */
HYP_FLOAT i00, i04, i08, i12;
HYP_FLOAT i01, i05, i09, i13;
HYP_FLOAT i02, i06, i10, i14;
HYP_FLOAT i03, i07, i11, i15;
};
struct {
/* col-row */
HYP_FLOAT c00, c10, c20, c30;
HYP_FLOAT c01, c11, c21, c31;
HYP_FLOAT c02, c12, c22, c32;
HYP_FLOAT c03, c13, c23, c33;
};
struct {
/* row-col */
HYP_FLOAT r00, r01, r02, r03;
HYP_FLOAT r10, r11, r12, r13;
HYP_FLOAT r20, r21, r22, r23;
HYP_FLOAT r30, r31, r32, r33;
};
};
};
HYPAPI int matrix4_equals(const struct matrix4 *self, const struct matrix4 *mT);
HYPAPI struct matrix4 *matrix4_zero(struct matrix4 *self);
HYPAPI struct matrix4 *matrix4_identity(struct matrix4 *self);
HYPAPI struct matrix4 *matrix4_set(struct matrix4 *self, const struct matrix4 *mT);
HYPAPI struct matrix4 *matrix4_add(struct matrix4 *self, const struct matrix4 *mT);
HYPAPI struct matrix4 *matrix4_subtract(struct matrix4 *self, const struct matrix4 *mT);
HYPAPI struct matrix4 *matrix4_multiply(struct matrix4 *self, const struct matrix4 *mT);
HYPAPI struct matrix4 *matrix4_multiplyf(struct matrix4 *self, HYP_FLOAT scalar);
HYPAPI struct vector4 *matrix4_multiplyv4(const struct matrix4 *self, const struct vector4 *vT, struct vector4 *vR);
HYPAPI struct vector3 *matrix4_multiplyv3(const struct matrix4 *self, const struct vector3 *vT, struct vector3 *vR);
HYPAPI struct vector2 *matrix4_multiplyv2(const struct matrix4 *self, const struct vector2 *vT, struct vector2 *vR);
HYPAPI struct matrix4 *matrix4_transpose(struct matrix4 *self);
HYPAPI HYP_FLOAT matrix4_determinant(const struct matrix4 *self);
HYPAPI struct matrix4 *matrix4_invert(struct matrix4 *self);
HYPAPI struct matrix4 *matrix4_inverse(const struct matrix4 *self, struct matrix4 *mR);
HYPAPI struct matrix4 *matrix4_make_transformation_translationv3(struct matrix4 *self, const struct vector3 *translation);
HYPAPI struct matrix4 *matrix4_make_transformation_scalingv3(struct matrix4 *self, const struct vector3 *scale);
HYPAPI struct matrix4 *matrix4_make_transformation_rotationq(struct matrix4 *self, const struct quaternion *qT);
HYPAPI struct matrix4 *matrix4_make_transformation_rotationf_x(struct matrix4 *self, HYP_FLOAT angle);
HYPAPI struct matrix4 *matrix4_make_transformation_rotationf_y(struct matrix4 *self, HYP_FLOAT angle);
HYPAPI struct matrix4 *matrix4_make_transformation_rotationf_z(struct matrix4 *self, HYP_FLOAT angle);
HYPAPI struct matrix4 *matrix4_translatev3(struct matrix4 *self, const struct vector3 *translation);
HYPAPI struct matrix4 *matrix4_rotatev3(struct matrix4 *self, const struct vector3 *axis, HYP_FLOAT angle);
HYPAPI struct matrix4 *matrix4_scalev3(struct matrix4 *self, const struct vector3 *scale);
HYPAPI struct matrix4 *_matrix4_transpose_rowcolumn(struct matrix4 *self);
HYPAPI struct matrix4 *_matrix4_transpose_columnrow(struct matrix4 *self);
#ifndef DOXYGEN_SHOULD_SKIP_THIS
/* BETA aliases */
#define mat4 struct matrix4
#define mat4_equals matrix4_equals
#define mat4_zero matrix4_zero
#define mat4_identity matrix4_identity
#define mat4_set matrix4_setm4
#define mat4_add matrix4_add
#define mat4_sub matrix4_subtract
#define mat4_mul matrix4_multiply
#define mat4_transpose matrix4_transpose
#define mat4_translatev3 matrix3_translatev3
#define mat4_rotatev3 matrix3_rotatev3
#define mat4_scalev3 matrix3_scalev3
#define m4 struct matrix4
#define m4_equals matrix4_equals
#define m4_zero matrix4_zero
#define m4_identity matrix4_identity
#define m4_set matrix4_set
#define m4_add matrix4_add
#define m4_sub matrix4_subtract
#define m4_mul matrix4_multiply
#define m4_transpose matrix4_transpose
#define m4_translatev3 matrix3_translatev3
#define m4_rotatev3 matrix3_rotatev3
#define m4_scalev3 matrix3_scalev3
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
struct quaternion {
union {
HYP_FLOAT q[4];
struct {
HYP_FLOAT x, y, z, w;
};
struct {
HYP_FLOAT i, j, k, a;
};
};
};
HYPAPI int quaternion_equals(const struct quaternion *self, const struct quaternion *vT);
HYPAPI struct quaternion *quaternion_identity(struct quaternion *self);
HYPAPI struct quaternion *quaternion_setf4(struct quaternion *self, HYP_FLOAT x, HYP_FLOAT y, HYP_FLOAT z, HYP_FLOAT w);
HYPAPI struct quaternion *quaternion_set(struct quaternion *self, const struct quaternion *qT);
HYPAPI struct quaternion *quaternion_add(struct quaternion *self, const struct quaternion *qT);
HYPAPI struct quaternion *quaternion_multiply(struct quaternion *self, const struct quaternion *qT);
HYPAPI struct quaternion *quaternion_multiplyv3(struct quaternion *self, const struct vector3 *vT);
HYPAPI struct quaternion *quaternion_multiplyf(struct quaternion *self, HYP_FLOAT f);
HYPAPI struct quaternion *quaternion_subtract(struct quaternion *self, const struct quaternion *qT);
HYPAPI struct quaternion *quaternion_negate(struct quaternion *self);
HYPAPI struct quaternion *quaternion_conjugate(struct quaternion *self);
HYPAPI struct quaternion *quaternion_inverse(struct quaternion *self);
HYPAPI short quaternion_is_unit(struct quaternion *self);
HYPAPI short quaternion_is_pure(struct quaternion *self);
HYPAPI HYP_FLOAT quaternion_norm(const struct quaternion *self);
HYPAPI HYP_FLOAT quaternion_magnitude(const struct quaternion *self);
HYPAPI struct quaternion *quaternion_normalize(struct quaternion *self);
HYPAPI HYP_FLOAT quaternion_dot_product(const struct quaternion *self, const struct quaternion *qT);
HYPAPI struct quaternion *quaternion_lerp(const struct quaternion *start, const struct quaternion *end, HYP_FLOAT percent, struct quaternion *qR);
HYPAPI struct quaternion *quaternion_nlerp(const struct quaternion *start, const struct quaternion *end, HYP_FLOAT percent, struct quaternion *qR);
HYPAPI struct quaternion *quaternion_slerp(const struct quaternion *start, const struct quaternion *end, HYP_FLOAT percent, struct quaternion *qR);
HYPAPI void quaternion_get_axis_anglev3(const struct quaternion *self, struct vector3 *vR, HYP_FLOAT *angle);
HYPAPI struct quaternion *quaternion_set_from_axis_anglev3(struct quaternion *self, const struct vector3 *axis, HYP_FLOAT angle);
HYPAPI struct quaternion *quaternion_set_from_axis_anglef3(struct quaternion *self, HYP_FLOAT x, HYP_FLOAT y, HYP_FLOAT z, HYP_FLOAT angle);
HYPAPI struct quaternion *quaternion_set_from_euler_anglesf3(struct quaternion *self, HYP_FLOAT ax, HYP_FLOAT ay, HYP_FLOAT az);
HYPAPI void quaternion_get_euler_anglesf3(const struct quaternion *self, HYP_FLOAT *ax, HYP_FLOAT *ay, HYP_FLOAT *az);
HYPAPI struct quaternion *quaternion_get_rotation_tov3(const struct vector3 *from, const struct vector3 *to, struct quaternion *qR);
#ifndef DOXYGEN_SHOULD_SKIP_THIS
/* BETA aliases */
#define quat struct quaternion
#define quat_equals quaternion_equals
#define quat_identity quaternion_identity
#define quat_lerp quaternion_lerp
#define quat_nlerp quaternion_nlerp
#define quat_slerp quaternion_slerp
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
#include <stdint.h>
HYPAPI struct quaternion *quaternion_rotate_by_quaternion_EXP(struct quaternion *self, const struct quaternion *qT);
HYPAPI struct quaternion *quaternion_rotate_by_axis_angle_EXP(struct quaternion *self, const struct vector3 *axis, HYP_FLOAT angle);
HYPAPI struct quaternion *quaternion_rotate_by_euler_angles_EXP(struct quaternion *self, HYP_FLOAT ax, HYP_FLOAT ay, HYP_FLOAT az);
HYPAPI HYP_FLOAT quaternion_difference_EXP(const struct quaternion *q1, const struct quaternion *q2);
HYPAPI HYP_FLOAT quaternion_angle_between_EXP(const struct quaternion *self, const struct quaternion *qT);
HYPAPI void quaternion_axis_between_EXP(const struct quaternion *self, const struct quaternion *qT, struct quaternion *qR);
HYPAPI struct matrix4 *matrix4_projection_perspective_fovy_rh_EXP(struct matrix4 *self, HYP_FLOAT fovy, HYP_FLOAT aspect, HYP_FLOAT zNear, HYP_FLOAT zFar);
HYPAPI struct matrix4 *matrix4_projection_ortho3d_rh_EXP(struct matrix4 *self, HYP_FLOAT xmin, HYP_FLOAT xmax, HYP_FLOAT ymin, HYP_FLOAT ymax, HYP_FLOAT zNear, HYP_FLOAT zFar);
HYPAPI struct matrix4 *matrix4_view_lookat_rh_EXP(struct matrix4 *self, const struct vector3 *eye, const struct vector3 *target, const struct vector3 *up);
HYPAPI struct vector3 *matrix4_multiplyv3_EXP(const struct matrix4 *m, const struct vector3 *vT, struct vector3 *vR);
HYPAPI struct quaternion quaternion_cross_product_EXP(const struct quaternion *self, const struct quaternion *vT);
HYPAPI struct matrix4 *matrix4_set_from_quaternion_EXP(struct matrix4 *self, const struct quaternion *qT);
HYPAPI struct matrix4 *matrix4_set_from_axisv3_angle_EXP(struct matrix4 *self, const struct vector3 *axis, HYP_FLOAT angle);
HYPAPI struct matrix4 *matrix4_set_from_axisf3_angle_EXP(struct matrix4 *self, HYP_FLOAT x, HYP_FLOAT y, HYP_FLOAT z, const HYP_FLOAT angle);
HYPAPI struct matrix4 *matrix4_set_from_euler_anglesf3_EXP(struct matrix4 *self, const HYP_FLOAT x, const HYP_FLOAT y, const HYP_FLOAT z);
HYPAPI struct vector3 *matrix4_get_translation_EXP(const struct matrix4 *self, struct vector3 *vT);
HYPAPI struct matrix4 *matrix4_make_transformation_rotationv3_EXP(struct matrix4 *self, const struct vector3 *vR);
HYPAPI struct matrix4 *matrix4_transformation_compose_EXP(struct matrix4 *self, const struct vector3 *scale, const struct quaternion *rotation, const struct vector3 *translation);
HYPAPI uint8_t matrix4_transformation_decompose_EXP(struct matrix4 *self, struct vector3 *scale, struct quaternion *rotation, struct vector3 *translation);
#ifdef HYPATIA_IMPLEMENTATION
/**
* @brief This checks for mathematical equality within HYP_EPSILON.
*
*/
HYPAPI short scalar_equalsf(const HYP_FLOAT f1, const HYP_FLOAT f2)
{
return scalar_equals_epsilonf(f1, f2, HYP_EPSILON);
}
/**
* @brief This checks for mathematical equality within a custom epsilon.
*
*/
HYPAPI short scalar_equals_epsilonf(const HYP_FLOAT f1, const HYP_FLOAT f2, const HYP_FLOAT epsilon)
{
if ((HYP_ABS(f1 - f2) < epsilon) == 0) {
return 0;
}
return 1;
}
static struct vector2 _vector2_zero = { { {0.0f, 0.0f} } };
static struct vector2 _vector2_one = { { {1.0f, 1.0f} } };
static struct vector2 _vector2_unit_x = { { {1.0f, 0.0f} } };
static struct vector2 _vector2_unit_y = { { {0.0f, 1.0f} } };
static struct vector2 _vector2_unit_x_negative = { { {-1.0f, 0.0f} } };
static struct vector2 _vector2_unit_y_negative = { { {0.0f, -1.0f} } };
HYPAPI const struct vector2 *vector2_get_reference_vector2(int id)
{
switch (id) {
case HYP_REF_VECTOR2_ZERO:
return &_vector2_zero;
case HYP_REF_VECTOR2_ONE:
return &_vector2_one;
case HYP_REF_VECTOR2_UNIT_X:
return &_vector2_unit_x;
case HYP_REF_VECTOR2_UNIT_Y:
return &_vector2_unit_y;
case HYP_REF_VECTOR2_UNIT_X_NEGATIVE:
return &_vector2_unit_x_negative;
case HYP_REF_VECTOR2_UNIT_Y_NEGATIVE:
return &_vector2_unit_y_negative;
default:
/* undefined case */
return &_vector2_zero;
}
}
HYPAPI struct vector2 *vector2_set(struct vector2 *self, const struct vector2 *vT)
{
self->x = vT->x;
self->y = vT->y;
return self;
}
HYPAPI struct vector2 *vector2_setf2(struct vector2 *self, HYP_FLOAT xT, HYP_FLOAT yT)
{
self->x = xT;
self->y = yT;
return self;
}
HYPAPI struct vector2 *vector2_zero(struct vector2 *self)
{
return vector2_setf2(self, 0.0f, 0.0f);
}
HYPAPI int vector2_equals(const struct vector2 *self, const struct vector2 *vT)
{
return scalar_equals(self->x, vT->x) && scalar_equals(self->y, vT->y);
}
HYPAPI struct vector2 *vector2_negate(struct vector2 *self)
{
self->v[0] = -self->v[0];
self->v[1] = -self->v[1];
return self;
}
HYPAPI struct vector2 *vector2_add(struct vector2 *self, const struct vector2 *vT)
{
self->v[0] += vT->v[0];
self->v[1] += vT->v[1];
return self;
}
HYPAPI struct vector2 *vector2_addf(struct vector2 *self, HYP_FLOAT fT)
{
self->v[0] += fT;
self->v[1] += fT;
return self;
}
HYPAPI struct vector2 *vector2_subtract(struct vector2 *self, const struct vector2 *vT)
{
self->v[0] -= vT->v[0];
self->v[1] -= vT->v[1];
return self;
}
HYPAPI struct vector2 *vector2_subtractf(struct vector2 *self, HYP_FLOAT fT)
{
self->v[0] -= fT;
self->v[1] -= fT;
return self;
}
HYPAPI struct vector2 *vector2_multiply(struct vector2 *self, const struct vector2 *vT)
{
self->v[0] *= vT->v[0];
self->v[1] *= vT->v[1];
return self;
}
HYPAPI struct vector2 *vector2_multiplyf(struct vector2 *self, HYP_FLOAT fT)
{
self->v[0] *= fT;
self->v[1] *= fT;
return self;
}
HYPAPI struct vector2 *vector2_divide(struct vector2 *self, const struct vector2 *vT)
{
self->v[0] /= vT->v[0];
self->v[1] /= vT->v[1];
return self;
}
HYPAPI struct vector2 *vector2_dividef(struct vector2 *self, HYP_FLOAT fT)
{
self->v[0] /= fT;
self->v[1] /= fT;
return self;
}
HYPAPI HYP_FLOAT vector2_magnitude(const struct vector2 *self)
{
return HYP_SQRT((self->x * self->x) + (self->y * self->y));
}
HYPAPI struct vector2 *vector2_normalize(struct vector2 *self)
{
HYP_FLOAT mag = vector2_magnitude(self);
self->x = self->x / mag;
self->y = self->y / mag;
return self;
}
HYPAPI HYP_FLOAT vector2_dot_product(const struct vector2 *self, const struct vector2 *vT)
{
return (self->x * vT->x) + (self->y * vT->y);
}