-
Notifications
You must be signed in to change notification settings - Fork 0
/
HandmadeMath.h
3176 lines (2368 loc) · 73.7 KB
/
HandmadeMath.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
/*
HandmadeMath.h v1.13.0
This is a single header file with a bunch of useful functions for game and
graphics math operations.
=============================================================================
To disable SSE intrinsics, you MUST
#define HANDMADE_MATH_NO_SSE
in EXACTLY one C or C++ file that includes this header, BEFORE the
include, like this:
#define HANDMADE_MATH_NO_SSE
#include "HandmadeMath.h"
=============================================================================
If you would prefer not to use the HMM_ prefix on function names, you can
#define HMM_PREFIX
To use a custom prefix instead, you can
#define HMM_PREFIX(name) YOUR_PREFIX_##name
=============================================================================
To use HandmadeMath without the CRT, you MUST
#define HMM_SINF MySinF
#define HMM_COSF MyCosF
#define HMM_TANF MyTanF
#define HMM_SQRTF MySqrtF
#define HMM_EXPF MyExpF
#define HMM_LOGF MyLogF
#define HMM_ACOSF MyACosF
#define HMM_ATANF MyATanF
#define HMM_ATAN2F MYATan2F
Provide your own implementations of SinF, CosF, TanF, ACosF, ATanF, ATan2F,
ExpF, and LogF in EXACTLY one C or C++ file that includes this header,
BEFORE the include, like this:
#define HMM_SINF MySinF
#define HMM_COSF MyCosF
#define HMM_TANF MyTanF
#define HMM_SQRTF MySqrtF
#define HMM_EXPF MyExpF
#define HMM_LOGF MyLogF
#define HMM_ACOSF MyACosF
#define HMM_ATANF MyATanF
#define HMM_ATAN2F MyATan2F
#include "HandmadeMath.h"
If you do not define all of these, HandmadeMath.h will use the
versions of these functions that are provided by the CRT.
=============================================================================
LICENSE
This software is in the public domain. Where that dedication is not
recognized, you are granted a perpetual, irrevocable license to copy,
distribute, and modify this file as you see fit.
CREDITS
Written by Zakary Strange (strangezak@protonmail.com && @strangezak)
Functionality:
Matt Mascarenhas (@miblo_)
Aleph
FieryDrake (@fierydrake)
Gingerbill (@TheGingerBill)
Ben Visness (@bvisness)
Trinton Bullard (@Peliex_Dev)
@AntonDan
Fixes:
Jeroen van Rijn (@J_vanRijn)
Kiljacken (@Kiljacken)
Insofaras (@insofaras)
Daniel Gibson (@DanielGibson)
*/
// Dummy macros for when test framework is not present.
#ifndef COVERAGE
#define COVERAGE(a, b)
#endif
#ifndef ASSERT_COVERED
#define ASSERT_COVERED(a)
#endif
/* let's figure out if SSE is really available (unless disabled anyway)
(it isn't on non-x86/x86_64 platforms or even x86 without explicit SSE support)
=> only use "#ifdef HANDMADE_MATH__USE_SSE" to check for SSE support below this block! */
#ifndef HANDMADE_MATH_NO_SSE
# ifdef _MSC_VER
/* MSVC supports SSE in amd64 mode or _M_IX86_FP >= 1 (2 means SSE2) */
# if defined(_M_AMD64) || ( defined(_M_IX86_FP) && _M_IX86_FP >= 1 )
# define HANDMADE_MATH__USE_SSE 1
# endif
# else /* not MSVC, probably GCC, clang, icc or something that doesn't support SSE anyway */
# ifdef __SSE__ /* they #define __SSE__ if it's supported */
# define HANDMADE_MATH__USE_SSE 1
# endif /* __SSE__ */
# endif /* not _MSC_VER */
#endif /* #ifndef HANDMADE_MATH_NO_SSE */
#ifdef HANDMADE_MATH__USE_SSE
#include <xmmintrin.h>
#endif
#ifndef HANDMADE_MATH_H
#define HANDMADE_MATH_H
#ifdef _MSC_VER
#pragma warning(disable:4201)
#endif
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal"
#if (defined(__GNUC__) && (__GNUC__ == 4 && __GNUC_MINOR__ < 8)) || defined(__clang__)
#pragma GCC diagnostic ignored "-Wmissing-braces"
#endif
#ifdef __clang__
#pragma GCC diagnostic ignored "-Wgnu-anonymous-struct"
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
#endif
#endif
#if defined(__GNUC__) || defined(__clang__)
#define HMM_DEPRECATED(msg) __attribute__((deprecated(msg)))
#elif defined(_MSC_VER)
#define HMM_DEPRECATED(msg) __declspec(deprecated(msg))
#else
#define HMM_DEPRECATED(msg)
#endif
#ifdef __cplusplus
extern "C"
{
#endif
#define HMM_INLINE static inline
#if !defined(HMM_SINF) || !defined(HMM_COSF) || !defined(HMM_TANF) || \
!defined(HMM_SQRTF) || !defined(HMM_EXPF) || !defined(HMM_LOGF) || \
!defined(HMM_ACOSF) || !defined(HMM_ATANF)|| !defined(HMM_ATAN2F)
#include <math.h>
#endif
#ifndef HMM_SINF
#define HMM_SINF sinf
#endif
#ifndef HMM_COSF
#define HMM_COSF cosf
#endif
#ifndef HMM_TANF
#define HMM_TANF tanf
#endif
#ifndef HMM_SQRTF
#define HMM_SQRTF sqrtf
#endif
#ifndef HMM_EXPF
#define HMM_EXPF expf
#endif
#ifndef HMM_LOGF
#define HMM_LOGF logf
#endif
#ifndef HMM_ACOSF
#define HMM_ACOSF acosf
#endif
#ifndef HMM_ATANF
#define HMM_ATANF atanf
#endif
#ifndef HMM_ATAN2F
#define HMM_ATAN2F atan2f
#endif
#define HMM_PI32 3.14159265359f
#define HMM_PI 3.14159265358979323846
#define HMM_MIN(a, b) ((a) > (b) ? (b) : (a))
#define HMM_MAX(a, b) ((a) < (b) ? (b) : (a))
#define HMM_ABS(a) ((a) > 0 ? (a) : -(a))
#define HMM_MOD(a, m) (((a) % (m)) >= 0 ? ((a) % (m)) : (((a) % (m)) + (m)))
#define HMM_SQUARE(x) ((x) * (x))
#ifndef HMM_PREFIX
#define HMM_PREFIX(name) HMM_##name
#endif
typedef union hmm_vec2
{
struct
{
float X, Y;
};
struct
{
float U, V;
};
struct
{
float Left, Right;
};
struct
{
float Width, Height;
};
float Elements[2];
#ifdef __cplusplus
inline float &operator[](const int &Index)
{
return Elements[Index];
}
#endif
} hmm_vec2;
typedef union hmm_vec3
{
struct
{
float X, Y, Z;
};
struct
{
float U, V, W;
};
struct
{
float R, G, B;
};
struct
{
hmm_vec2 XY;
float Ignored0_;
};
struct
{
float Ignored1_;
hmm_vec2 YZ;
};
struct
{
hmm_vec2 UV;
float Ignored2_;
};
struct
{
float Ignored3_;
hmm_vec2 VW;
};
float Elements[3];
#ifdef __cplusplus
inline float &operator[](const int &Index)
{
return Elements[Index];
}
#endif
} hmm_vec3;
typedef union hmm_vec4
{
struct
{
union
{
hmm_vec3 XYZ;
struct
{
float X, Y, Z;
};
};
float W;
};
struct
{
union
{
hmm_vec3 RGB;
struct
{
float R, G, B;
};
};
float A;
};
struct
{
hmm_vec2 XY;
float Ignored0_;
float Ignored1_;
};
struct
{
float Ignored2_;
hmm_vec2 YZ;
float Ignored3_;
};
struct
{
float Ignored4_;
float Ignored5_;
hmm_vec2 ZW;
};
float Elements[4];
#ifdef HANDMADE_MATH__USE_SSE
__m128 InternalElementsSSE;
#endif
#ifdef __cplusplus
inline float &operator[](const int &Index)
{
return Elements[Index];
}
#endif
} hmm_vec4;
typedef union hmm_mat4
{
float Elements[4][4];
#ifdef HANDMADE_MATH__USE_SSE
__m128 Columns[4];
HMM_DEPRECATED("Our matrices are column-major, so this was named incorrectly. Use Columns instead.")
__m128 Rows[4];
#endif
#ifdef __cplusplus
inline hmm_vec4 operator[](const int &Index)
{
hmm_vec4 Result;
float* Column = Elements[Index];
Result.Elements[0] = Column[0];
Result.Elements[1] = Column[1];
Result.Elements[2] = Column[2];
Result.Elements[3] = Column[3];
return Result;
}
#endif
} hmm_mat4;
typedef union hmm_quaternion
{
struct
{
union
{
hmm_vec3 XYZ;
struct
{
float X, Y, Z;
};
};
float W;
};
float Elements[4];
#ifdef HANDMADE_MATH__USE_SSE
__m128 InternalElementsSSE;
#endif
} hmm_quaternion;
typedef signed int hmm_bool;
typedef hmm_vec2 hmm_v2;
typedef hmm_vec3 hmm_v3;
typedef hmm_vec4 hmm_v4;
typedef hmm_mat4 hmm_m4;
/*
* Floating-point math functions
*/
COVERAGE(HMM_SinF, 1)
HMM_INLINE float HMM_PREFIX(SinF)(float Radians)
{
ASSERT_COVERED(HMM_SinF);
float Result = HMM_SINF(Radians);
return (Result);
}
COVERAGE(HMM_CosF, 1)
HMM_INLINE float HMM_PREFIX(CosF)(float Radians)
{
ASSERT_COVERED(HMM_CosF);
float Result = HMM_COSF(Radians);
return (Result);
}
COVERAGE(HMM_TanF, 1)
HMM_INLINE float HMM_PREFIX(TanF)(float Radians)
{
ASSERT_COVERED(HMM_TanF);
float Result = HMM_TANF(Radians);
return (Result);
}
COVERAGE(HMM_ACosF, 1)
HMM_INLINE float HMM_PREFIX(ACosF)(float Radians)
{
ASSERT_COVERED(HMM_ACosF);
float Result = HMM_ACOSF(Radians);
return (Result);
}
COVERAGE(HMM_ATanF, 1)
HMM_INLINE float HMM_PREFIX(ATanF)(float Radians)
{
ASSERT_COVERED(HMM_ATanF);
float Result = HMM_ATANF(Radians);
return (Result);
}
COVERAGE(HMM_ATan2F, 1)
HMM_INLINE float HMM_PREFIX(ATan2F)(float Left, float Right)
{
ASSERT_COVERED(HMM_ATan2F);
float Result = HMM_ATAN2F(Left, Right);
return (Result);
}
COVERAGE(HMM_ExpF, 1)
HMM_INLINE float HMM_PREFIX(ExpF)(float Float)
{
ASSERT_COVERED(HMM_ExpF);
float Result = HMM_EXPF(Float);
return (Result);
}
COVERAGE(HMM_LogF, 1)
HMM_INLINE float HMM_PREFIX(LogF)(float Float)
{
ASSERT_COVERED(HMM_LogF);
float Result = HMM_LOGF(Float);
return (Result);
}
COVERAGE(HMM_SquareRootF, 1)
HMM_INLINE float HMM_PREFIX(SquareRootF)(float Float)
{
ASSERT_COVERED(HMM_SquareRootF);
float Result;
#ifdef HANDMADE_MATH__USE_SSE
__m128 In = _mm_set_ss(Float);
__m128 Out = _mm_sqrt_ss(In);
Result = _mm_cvtss_f32(Out);
#else
Result = HMM_SQRTF(Float);
#endif
return(Result);
}
COVERAGE(HMM_RSquareRootF, 1)
HMM_INLINE float HMM_PREFIX(RSquareRootF)(float Float)
{
ASSERT_COVERED(HMM_RSquareRootF);
float Result;
#ifdef HANDMADE_MATH__USE_SSE
__m128 In = _mm_set_ss(Float);
__m128 Out = _mm_rsqrt_ss(In);
Result = _mm_cvtss_f32(Out);
#else
Result = 1.0f/HMM_PREFIX(SquareRootF)(Float);
#endif
return(Result);
}
COVERAGE(HMM_Power, 2)
HMM_INLINE float HMM_PREFIX(Power)(float Base, int Exponent)
{
ASSERT_COVERED(HMM_Power);
float Result = 1.0f;
float Mul = Exponent < 0 ? 1.f / Base : Base;
int X = Exponent < 0 ? -Exponent : Exponent;
while (X)
{
if (X & 1)
{
ASSERT_COVERED(HMM_Power);
Result *= Mul;
}
Mul *= Mul;
X >>= 1;
}
return (Result);
}
COVERAGE(HMM_PowerF, 1)
HMM_INLINE float HMM_PREFIX(PowerF)(float Base, float Exponent)
{
ASSERT_COVERED(HMM_PowerF);
float Result = HMM_EXPF(Exponent * HMM_LOGF(Base));
return (Result);
}
/*
* Utility functions
*/
COVERAGE(HMM_ToRadians, 1)
HMM_INLINE float HMM_PREFIX(ToRadians)(float Degrees)
{
ASSERT_COVERED(HMM_ToRadians);
float Result = Degrees * (HMM_PI32 / 180.0f);
return (Result);
}
COVERAGE(HMM_Lerp, 1)
HMM_INLINE float HMM_PREFIX(Lerp)(float A, float Time, float B)
{
ASSERT_COVERED(HMM_Lerp);
float Result = (1.0f - Time) * A + Time * B;
return (Result);
}
COVERAGE(HMM_Clamp, 1)
HMM_INLINE float HMM_PREFIX(Clamp)(float Min, float Value, float Max)
{
ASSERT_COVERED(HMM_Clamp);
float Result = Value;
if(Result < Min)
{
Result = Min;
}
if(Result > Max)
{
Result = Max;
}
return (Result);
}
/*
* Vector initialization
*/
COVERAGE(HMM_Vec2, 1)
HMM_INLINE hmm_vec2 HMM_PREFIX(Vec2)(float X, float Y)
{
ASSERT_COVERED(HMM_Vec2);
hmm_vec2 Result;
Result.X = X;
Result.Y = Y;
return (Result);
}
COVERAGE(HMM_Vec2i, 1)
HMM_INLINE hmm_vec2 HMM_PREFIX(Vec2i)(int X, int Y)
{
ASSERT_COVERED(HMM_Vec2i);
hmm_vec2 Result;
Result.X = (float)X;
Result.Y = (float)Y;
return (Result);
}
COVERAGE(HMM_Vec3, 1)
HMM_INLINE hmm_vec3 HMM_PREFIX(Vec3)(float X, float Y, float Z)
{
ASSERT_COVERED(HMM_Vec3);
hmm_vec3 Result;
Result.X = X;
Result.Y = Y;
Result.Z = Z;
return (Result);
}
COVERAGE(HMM_Vec3i, 1)
HMM_INLINE hmm_vec3 HMM_PREFIX(Vec3i)(int X, int Y, int Z)
{
ASSERT_COVERED(HMM_Vec3i);
hmm_vec3 Result;
Result.X = (float)X;
Result.Y = (float)Y;
Result.Z = (float)Z;
return (Result);
}
COVERAGE(HMM_Vec4, 1)
HMM_INLINE hmm_vec4 HMM_PREFIX(Vec4)(float X, float Y, float Z, float W)
{
ASSERT_COVERED(HMM_Vec4);
hmm_vec4 Result;
#ifdef HANDMADE_MATH__USE_SSE
Result.InternalElementsSSE = _mm_setr_ps(X, Y, Z, W);
#else
Result.X = X;
Result.Y = Y;
Result.Z = Z;
Result.W = W;
#endif
return (Result);
}
COVERAGE(HMM_Vec4i, 1)
HMM_INLINE hmm_vec4 HMM_PREFIX(Vec4i)(int X, int Y, int Z, int W)
{
ASSERT_COVERED(HMM_Vec4i);
hmm_vec4 Result;
#ifdef HANDMADE_MATH__USE_SSE
Result.InternalElementsSSE = _mm_setr_ps((float)X, (float)Y, (float)Z, (float)W);
#else
Result.X = (float)X;
Result.Y = (float)Y;
Result.Z = (float)Z;
Result.W = (float)W;
#endif
return (Result);
}
COVERAGE(HMM_Vec4v, 1)
HMM_INLINE hmm_vec4 HMM_PREFIX(Vec4v)(hmm_vec3 Vector, float W)
{
ASSERT_COVERED(HMM_Vec4v);
hmm_vec4 Result;
#ifdef HANDMADE_MATH__USE_SSE
Result.InternalElementsSSE = _mm_setr_ps(Vector.X, Vector.Y, Vector.Z, W);
#else
Result.XYZ = Vector;
Result.W = W;
#endif
return (Result);
}
/*
* Binary vector operations
*/
COVERAGE(HMM_AddVec2, 1)
HMM_INLINE hmm_vec2 HMM_PREFIX(AddVec2)(hmm_vec2 Left, hmm_vec2 Right)
{
ASSERT_COVERED(HMM_AddVec2);
hmm_vec2 Result;
Result.X = Left.X + Right.X;
Result.Y = Left.Y + Right.Y;
return (Result);
}
COVERAGE(HMM_AddVec3, 1)
HMM_INLINE hmm_vec3 HMM_PREFIX(AddVec3)(hmm_vec3 Left, hmm_vec3 Right)
{
ASSERT_COVERED(HMM_AddVec3);
hmm_vec3 Result;
Result.X = Left.X + Right.X;
Result.Y = Left.Y + Right.Y;
Result.Z = Left.Z + Right.Z;
return (Result);
}
COVERAGE(HMM_AddVec4, 1)
HMM_INLINE hmm_vec4 HMM_PREFIX(AddVec4)(hmm_vec4 Left, hmm_vec4 Right)
{
ASSERT_COVERED(HMM_AddVec4);
hmm_vec4 Result;
#ifdef HANDMADE_MATH__USE_SSE
Result.InternalElementsSSE = _mm_add_ps(Left.InternalElementsSSE, Right.InternalElementsSSE);
#else
Result.X = Left.X + Right.X;
Result.Y = Left.Y + Right.Y;
Result.Z = Left.Z + Right.Z;
Result.W = Left.W + Right.W;
#endif
return (Result);
}
COVERAGE(HMM_SubtractVec2, 1)
HMM_INLINE hmm_vec2 HMM_PREFIX(SubtractVec2)(hmm_vec2 Left, hmm_vec2 Right)
{
ASSERT_COVERED(HMM_SubtractVec2);
hmm_vec2 Result;
Result.X = Left.X - Right.X;
Result.Y = Left.Y - Right.Y;
return (Result);
}
COVERAGE(HMM_SubtractVec3, 1)
HMM_INLINE hmm_vec3 HMM_PREFIX(SubtractVec3)(hmm_vec3 Left, hmm_vec3 Right)
{
ASSERT_COVERED(HMM_SubtractVec3);
hmm_vec3 Result;
Result.X = Left.X - Right.X;
Result.Y = Left.Y - Right.Y;
Result.Z = Left.Z - Right.Z;
return (Result);
}
COVERAGE(HMM_SubtractVec4, 1)
HMM_INLINE hmm_vec4 HMM_PREFIX(SubtractVec4)(hmm_vec4 Left, hmm_vec4 Right)
{
ASSERT_COVERED(HMM_SubtractVec4);
hmm_vec4 Result;
#ifdef HANDMADE_MATH__USE_SSE
Result.InternalElementsSSE = _mm_sub_ps(Left.InternalElementsSSE, Right.InternalElementsSSE);
#else
Result.X = Left.X - Right.X;
Result.Y = Left.Y - Right.Y;
Result.Z = Left.Z - Right.Z;
Result.W = Left.W - Right.W;
#endif
return (Result);
}
COVERAGE(HMM_MultiplyVec2, 1)
HMM_INLINE hmm_vec2 HMM_PREFIX(MultiplyVec2)(hmm_vec2 Left, hmm_vec2 Right)
{
ASSERT_COVERED(HMM_MultiplyVec2);
hmm_vec2 Result;
Result.X = Left.X * Right.X;
Result.Y = Left.Y * Right.Y;
return (Result);
}
COVERAGE(HMM_MultiplyVec2f, 1)
HMM_INLINE hmm_vec2 HMM_PREFIX(MultiplyVec2f)(hmm_vec2 Left, float Right)
{
ASSERT_COVERED(HMM_MultiplyVec2f);
hmm_vec2 Result;
Result.X = Left.X * Right;
Result.Y = Left.Y * Right;
return (Result);
}
COVERAGE(HMM_MultiplyVec3, 1)
HMM_INLINE hmm_vec3 HMM_PREFIX(MultiplyVec3)(hmm_vec3 Left, hmm_vec3 Right)
{
ASSERT_COVERED(HMM_MultiplyVec3);
hmm_vec3 Result;
Result.X = Left.X * Right.X;
Result.Y = Left.Y * Right.Y;
Result.Z = Left.Z * Right.Z;
return (Result);
}
COVERAGE(HMM_MultiplyVec3f, 1)
HMM_INLINE hmm_vec3 HMM_PREFIX(MultiplyVec3f)(hmm_vec3 Left, float Right)
{
ASSERT_COVERED(HMM_MultiplyVec3f);
hmm_vec3 Result;
Result.X = Left.X * Right;
Result.Y = Left.Y * Right;
Result.Z = Left.Z * Right;
return (Result);
}
COVERAGE(HMM_MultiplyVec4, 1)
HMM_INLINE hmm_vec4 HMM_PREFIX(MultiplyVec4)(hmm_vec4 Left, hmm_vec4 Right)
{
ASSERT_COVERED(HMM_MultiplyVec4);
hmm_vec4 Result;
#ifdef HANDMADE_MATH__USE_SSE
Result.InternalElementsSSE = _mm_mul_ps(Left.InternalElementsSSE, Right.InternalElementsSSE);
#else
Result.X = Left.X * Right.X;
Result.Y = Left.Y * Right.Y;
Result.Z = Left.Z * Right.Z;
Result.W = Left.W * Right.W;
#endif
return (Result);
}
COVERAGE(HMM_MultiplyVec4f, 1)
HMM_INLINE hmm_vec4 HMM_PREFIX(MultiplyVec4f)(hmm_vec4 Left, float Right)
{
ASSERT_COVERED(HMM_MultiplyVec4f);
hmm_vec4 Result;
#ifdef HANDMADE_MATH__USE_SSE
__m128 Scalar = _mm_set1_ps(Right);
Result.InternalElementsSSE = _mm_mul_ps(Left.InternalElementsSSE, Scalar);
#else
Result.X = Left.X * Right;
Result.Y = Left.Y * Right;
Result.Z = Left.Z * Right;
Result.W = Left.W * Right;
#endif
return (Result);
}
COVERAGE(HMM_DivideVec2, 1)
HMM_INLINE hmm_vec2 HMM_PREFIX(DivideVec2)(hmm_vec2 Left, hmm_vec2 Right)
{
ASSERT_COVERED(HMM_DivideVec2);
hmm_vec2 Result;
Result.X = Left.X / Right.X;
Result.Y = Left.Y / Right.Y;
return (Result);
}
COVERAGE(HMM_DivideVec2f, 1)
HMM_INLINE hmm_vec2 HMM_PREFIX(DivideVec2f)(hmm_vec2 Left, float Right)
{
ASSERT_COVERED(HMM_DivideVec2f);
hmm_vec2 Result;
Result.X = Left.X / Right;
Result.Y = Left.Y / Right;
return (Result);
}
COVERAGE(HMM_DivideVec3, 1)
HMM_INLINE hmm_vec3 HMM_PREFIX(DivideVec3)(hmm_vec3 Left, hmm_vec3 Right)
{
ASSERT_COVERED(HMM_DivideVec3);
hmm_vec3 Result;
Result.X = Left.X / Right.X;
Result.Y = Left.Y / Right.Y;
Result.Z = Left.Z / Right.Z;
return (Result);
}
COVERAGE(HMM_DivideVec3f, 1)
HMM_INLINE hmm_vec3 HMM_PREFIX(DivideVec3f)(hmm_vec3 Left, float Right)
{
ASSERT_COVERED(HMM_DivideVec3f);
hmm_vec3 Result;
Result.X = Left.X / Right;
Result.Y = Left.Y / Right;
Result.Z = Left.Z / Right;
return (Result);
}
COVERAGE(HMM_DivideVec4, 1)
HMM_INLINE hmm_vec4 HMM_PREFIX(DivideVec4)(hmm_vec4 Left, hmm_vec4 Right)
{
ASSERT_COVERED(HMM_DivideVec4);
hmm_vec4 Result;
#ifdef HANDMADE_MATH__USE_SSE
Result.InternalElementsSSE = _mm_div_ps(Left.InternalElementsSSE, Right.InternalElementsSSE);
#else
Result.X = Left.X / Right.X;
Result.Y = Left.Y / Right.Y;
Result.Z = Left.Z / Right.Z;
Result.W = Left.W / Right.W;
#endif
return (Result);
}
COVERAGE(HMM_DivideVec4f, 1)
HMM_INLINE hmm_vec4 HMM_PREFIX(DivideVec4f)(hmm_vec4 Left, float Right)
{
ASSERT_COVERED(HMM_DivideVec4f);
hmm_vec4 Result;
#ifdef HANDMADE_MATH__USE_SSE
__m128 Scalar = _mm_set1_ps(Right);
Result.InternalElementsSSE = _mm_div_ps(Left.InternalElementsSSE, Scalar);