Project
Loading...
Searching...
No Matches
HandMadeMath.h
Go to the documentation of this file.
1/*
2 HandmadeMath.h v1.7.0
3
4 This is a single header file with a bunch of useful functions for game and
5 graphics math operations.
6
7 =============================================================================
8
9 You MUST
10
11 #define HANDMADE_MATH_IMPLEMENTATION
12
13 in EXACTLY one C or C++ file that includes this header, BEFORE the
14 include, like this:
15
16 #define HANDMADE_MATH_IMPLEMENTATION
17 #include "HandmadeMath.h"
18
19 All other files should just #include "HandmadeMath.h" without the #define.
20
21 =============================================================================
22
23 To disable SSE intrinsics, you MUST
24
25 #define HANDMADE_MATH_NO_SSE
26
27 in EXACTLY one C or C++ file that includes this header, BEFORE the
28 include, like this:
29
30 #define HANDMADE_MATH_IMPLEMENTATION
31 #define HANDMADE_MATH_NO_SSE
32 #include "HandmadeMath.h"
33
34 =============================================================================
35
36 To use HandmadeMath without the CRT, you MUST
37
38 #define HMM_SINF MySinF
39 #define HMM_COSF MyCosF
40 #define HMM_TANF MyTanF
41 #define HMM_SQRTF MySqrtF
42 #define HMM_EXPF MyExpF
43 #define HMM_LOGF MyLogF
44 #define HMM_ACOSF MyACosF
45 #define HMM_ATANF MyATanF
46 #define HMM_ATAN2F MYATan2F
47
48 Provide your own implementations of SinF, CosF, TanF, ACosF, ATanF, ATan2F,
49 ExpF, and LogF in EXACTLY one C or C++ file that includes this header,
50 BEFORE the include, like this:
51
52 #define HMM_SINF MySinF
53 #define HMM_COSF MyCosF
54 #define HMM_TANF MyTanF
55 #define HMM_SQRTF MySqrtF
56 #define HMM_EXPF MyExpF
57 #define HMM_LOGF MyLogF
58 #define HMM_ACOSF MyACosF
59 #define HMM_ATANF MyATanF
60 #define HMM_ATAN2F MyATan2F
61 #define HANDMADE_MATH_IMPLEMENTATION
62 #include "HandmadeMath.h"
63
64 If you do not define all of these, HandmadeMath.h will use the
65 versions of these functions that are provided by the CRT.
66
67 =============================================================================
68
69 Version History:
70 0.2 (*) Updated documentation
71 (*) Better C compliance
72 (*) Prefix all handmade math functions
73 (*) Better operator overloading
74 0.2a
75 (*) Prefixed Macros
76 0.2b
77 (*) Disabled warning 4201 on MSVC as it is legal is C11
78 (*) Removed the f at the end of HMM_PI to get 64bit precision
79 0.3
80 (*) Added +=, -=, *=, /= for hmm_vec2, hmm_vec3, hmm_vec4
81 0.4
82 (*) SSE Optimized HMM_SqrtF
83 (*) SSE Optimized HMM_RSqrtF
84 (*) Removed CRT
85 0.5
86 (*) Added scalar multiplication and division for vectors
87 and matrices
88 (*) Added matrix subtraction and += for hmm_mat4
89 (*) Reconciled all headers and implementations
90 (*) Tidied up, and filled in a few missing operators
91 0.5.1
92 (*) Ensured column-major order for matrices throughout
93 (*) Fixed HMM_Translate producing row-major matrices
94 0.5.2
95 (*) Fixed SSE code in HMM_SqrtF
96 (*) Fixed SSE code in HMM_RSqrtF
97 0.6
98 (*) Added Unit testing
99 (*) Made HMM_Power faster
100 (*) Fixed possible efficiency problem with HMM_Normalize
101 (*) RENAMED HMM_LengthSquareRoot to HMM_LengthSquared
102 (*) RENAMED HMM_RSqrtF to HMM_RSquareRootF
103 (*) RENAMED HMM_SqrtF to HMM_SquareRootF
104 (*) REMOVED Inner function (user should use Dot now)
105 (*) REMOVED HMM_FastInverseSquareRoot function declaration
106 0.7
107 (*) REMOVED HMM_LengthSquared in HANDMADE_MATH_IMPLEMENTATION (should
108 use HMM_LengthSquaredVec3, or HANDMADE_MATH_CPP_MODE for function
109 overloaded version)
110 (*) REMOVED HMM_Length in HANDMADE_MATH_IMPLEMENTATION (should use
111 HMM_LengthVec3, HANDMADE_MATH_CPP_MODE for function
112 overloaded version)
113 (*) REMOVED HMM_Normalize in HANDMADE_MATH_IMPLEMENTATION (should use
114 HMM_NormalizeVec3, or HANDMADE_MATH_CPP_MODE for function
115 overloaded version)
116 (*) Added HMM_LengthSquaredVec2
117 (*) Added HMM_LengthSquaredVec4
118 (*) Addd HMM_LengthVec2
119 (*) Added HMM_LengthVec4
120 (*) Added HMM_NormalizeVec2
121 (*) Added HMM_NormalizeVec4
122 1.0
123 (*) Lots of testing!
124 1.1
125 (*) Quaternion support
126 (*) Added type hmm_quaternion
127 (*) Added HMM_Quaternion
128 (*) Added HMM_QuaternionV4
129 (*) Added HMM_AddQuaternion
130 (*) Added HMM_SubtractQuaternion
131 (*) Added HMM_MultiplyQuaternion
132 (*) Added HMM_MultiplyQuaternionF
133 (*) Added HMM_DivideQuaternionF
134 (*) Added HMM_InverseQuaternion
135 (*) Added HMM_DotQuaternion
136 (*) Added HMM_NormalizeQuaternion
137 (*) Added HMM_Slerp
138 (*) Added HMM_QuaternionToMat4
139 (*) Added HMM_QuaternionFromAxisAngle
140 1.1.1
141 (*) Resolved compiler warnings on gcc and g++
142 1.1.2
143 (*) Fixed invalid HMMDEF's in the function definitions
144 1.1.3
145 (*) Fixed compile error in C mode
146 1.1.4
147 (*) Fixed SSE being included on platforms that don't support it
148 (*) Fixed divide-by-zero errors when normalizing zero vectors.
149 1.1.5
150 (*) Add Width and Height to HMM_Vec2
151 (*) Made it so you can supply your own SqrtF
152 1.2.0
153 (*) Added equality functions for HMM_Vec2, HMM_Vec3, and HMM_Vec4.
154 (*) Added HMM_EqualsVec2, HMM_EqualsVec3, and HMM_EqualsVec4
155 (*) Added C++ overloaded HMM_Equals for all three
156 (*) Added C++ == and != operators for all three
157 (*) SSE'd HMM_MultiplyMat4 (this is _WAY_ faster)
158 (*) SSE'd HMM_Transpose
159 1.3.0
160 (*) Remove need to #define HANDMADE_MATH_CPP_MODE
161 1.4.0
162 (*) Fixed bug when using HandmadeMath in C mode
163 (*) SSEd all vec4 operations
164 (*) Removed all zero-ing
165 1.5.0
166 (*) Changed internal structure for better performance and inlining.
167 (*) As a result, HANDMADE_MATH_NO_INLINE has been removed and no
168 longer has any effect.
169 1.5.1
170 (*) Fixed a bug with uninitialized elements in HMM_LookAt.
171 1.6.0
172 (*) Added array subscript operators for vector and matrix types in
173 C++. This is provided as a convenience, but be aware that it may
174 incur an extra function call in unoptimized builds.
175 1.7.0
176 (*) Renamed the 'Rows' member of hmm_mat4 to 'Columns'. Since our
177 matrices are column-major, this should have been named 'Columns'
178 from the start. 'Rows' is still present, but has been deprecated.
179
180
181 LICENSE
182
183 This software is in the public domain. Where that dedication is not
184 recognized, you are granted a perpetual, irrevocable license to copy,
185 distribute, and modify this file as you see fit.
186
187 CREDITS
188
189 Written by Zakary Strange (zak@strangedev.net && @strangezak)
190
191 Functionality:
192 Matt Mascarenhas (@miblo_)
193 Aleph
194 FieryDrake (@fierydrake)
195 Gingerbill (@TheGingerBill)
196 Ben Visness (@bvisness)
197 Trinton Bullard (@Peliex_Dev)
198
199 Fixes:
200 Jeroen van Rijn (@J_vanRijn)
201 Kiljacken (@Kiljacken)
202 Insofaras (@insofaras)
203 Daniel Gibson (@DanielGibson)
204*/
205
206/* let's figure out if SSE is really available (unless disabled anyway)
207 (it isn't on non-x86/x86_64 platforms or even x86 without explicit SSE support)
208 => only use "#ifdef HANDMADE_MATH__USE_SSE" to check for SSE support below this block! */
209#ifndef HANDMADE_MATH_NO_SSE
210
211#ifdef _MSC_VER
212/* MSVC supports SSE in amd64 mode or _M_IX86_FP >= 1 (2 means SSE2) */
213#if defined(_M_AMD64) || (defined(_M_IX86_FP) && _M_IX86_FP >= 1)
214#define HANDMADE_MATH__USE_SSE 1
215#endif
216#else /* not MSVC, probably GCC, clang, icc or something that doesn't support SSE anyway */
217#ifdef __SSE__ /* they #define __SSE__ if it's supported */
218#define HANDMADE_MATH__USE_SSE 1
219#endif /* __SSE__ */
220#endif /* not _MSC_VER */
221
222#endif /* #ifndef HANDMADE_MATH_NO_SSE */
223
224#include <stdint.h> // This is for types
225
226#ifdef HANDMADE_MATH__USE_SSE
227#include <xmmintrin.h>
228#endif
229
230#ifndef HANDMADE_MATH_H
231#define HANDMADE_MATH_H
232
233#ifdef _MSC_VER
234#pragma warning(disable : 4201)
235#endif
236
237#ifdef __clang__
238#pragma GCC diagnostic push
239#pragma GCC diagnostic ignored "-Wgnu-anonymous-struct"
240#endif
241
242#ifdef __cplusplus
243extern "C" {
244#endif
245
246#define HMM_INLINE static inline
247#define HMM_EXTERN extern
248
249#if !defined(HMM_SINF) || !defined(HMM_COSF) || !defined(HMM_TANF) || \
250 !defined(HMM_SQRTF) || !defined(HMM_EXPF) || !defined(HMM_LOGF) || \
251 !defined(HMM_ACOSF) || !defined(HMM_ATANF) || !defined(HMM_ATAN2F)
252#include <math.h>
253#endif
254
255#ifndef HMM_SINF
256#define HMM_SINF sinf
257#endif
258
259#ifndef HMM_COSF
260#define HMM_COSF cosf
261#endif
262
263#ifndef HMM_TANF
264#define HMM_TANF tanf
265#endif
266
267#ifndef HMM_SQRTF
268#define HMM_SQRTF sqrtf
269#endif
270
271#ifndef HMM_EXPF
272#define HMM_EXPF expf
273#endif
274
275#ifndef HMM_LOGF
276#define HMM_LOGF logf
277#endif
278
279#ifndef HMM_ACOSF
280#define HMM_ACOSF acosf
281#endif
282
283#ifndef HMM_ATANF
284#define HMM_ATANF atanf
285#endif
286
287#ifndef HMM_ATAN2F
288#define HMM_ATAN2F atan2f
289#endif
290
291#define HMM_PI32 3.14159265359f
292#define HMM_PI 3.14159265358979323846
293
294#define HMM_MIN(a, b) (a) > (b) ? (b) : (a)
295#define HMM_MAX(a, b) (a) < (b) ? (b) : (a)
296#define HMM_ABS(a) ((a) > 0 ? (a) : -(a))
297#define HMM_MOD(a, m) ((a) % (m)) >= 0 ? ((a) % (m)) : (((a) % (m)) + (m))
298#define HMM_SQUARE(x) ((x) * (x))
299
300typedef union hmm_vec2 {
301 struct
302 {
303 float X, Y;
304 };
305
306 struct
307 {
308 float U, V;
309 };
310
311 struct
312 {
313 float Left, Right;
314 };
315
316 struct
317 {
318 float Width, Height;
319 };
320
321 float Elements[2];
322
323#ifdef __cplusplus
324 inline float& operator[](int Index)
325 {
326 return Elements[Index];
327 }
328#endif
330
331typedef union hmm_vec3 {
332 struct
333 {
334 float X, Y, Z;
335 };
336
337 struct
338 {
339 float U, V, W;
340 };
341
342 struct
343 {
344 float R, G, B;
345 };
346
347 struct
348 {
351 };
352
353 struct
354 {
357 };
358
359 struct
360 {
363 };
364
365 struct
366 {
369 };
370
371 float Elements[3];
372
373#ifdef __cplusplus
374 inline float& operator[](int Index)
375 {
376 return Elements[Index];
377 }
378#endif
380
381typedef union hmm_vec4 {
382 struct
383 {
384 union {
386 struct
387 {
388 float X, Y, Z;
389 };
390 };
391
392 float W;
393 };
394 struct
395 {
396 union {
398 struct
399 {
400 float R, G, B;
401 };
402 };
403
404 float A;
405 };
406
407 struct
408 {
412 };
413
414 struct
415 {
419 };
420
421 struct
422 {
426 };
427
428 float Elements[4];
429
430#ifdef HANDMADE_MATH__USE_SSE
431 __m128 InternalElementsSSE;
432#endif
433
434#ifdef __cplusplus
435 inline float& operator[](int Index)
436 {
437 return Elements[Index];
438 }
439#endif
441
442typedef union hmm_mat4 {
443 float Elements[4][4];
444
445#ifdef HANDMADE_MATH__USE_SSE
446 __m128 Columns[4];
447
448 // DEPRECATED. Our matrices are column-major, so this was named
449 // incorrectly. Use Columns instead.
450 __m128 Rows[4];
451#endif
452
453#ifdef __cplusplus
454 inline hmm_vec4 operator[](const int Index)
455 {
456 float* col = Elements[Index];
457
459 result.Elements[0] = col[0];
460 result.Elements[1] = col[1];
461 result.Elements[2] = col[2];
462 result.Elements[3] = col[3];
463
464 return result;
465 }
466#endif
468
469typedef union hmm_quaternion {
470 struct
471 {
472 union {
474 struct
475 {
476 float X, Y, Z;
477 };
478 };
479
480 float W;
481 };
482
483 float Elements[4];
485
486typedef int32_t hmm_bool;
487
492
493/*
494 * Floating-point math functions
495 */
496
497HMM_INLINE float HMM_SinF(float Radians)
498{
499 float Result = HMM_SINF(Radians);
500
501 return (Result);
502}
503
504HMM_INLINE float HMM_CosF(float Radians)
505{
506 float Result = HMM_COSF(Radians);
507
508 return (Result);
509}
510
511HMM_INLINE float HMM_TanF(float Radians)
512{
513 float Result = HMM_TANF(Radians);
514
515 return (Result);
516}
517
518HMM_INLINE float HMM_ACosF(float Radians)
519{
520 float Result = HMM_ACOSF(Radians);
521
522 return (Result);
523}
524
525HMM_INLINE float HMM_ATanF(float Radians)
526{
527 float Result = HMM_ATANF(Radians);
528
529 return (Result);
530}
531
532HMM_INLINE float HMM_ATan2F(float Left, float Right)
533{
534 float Result = HMM_ATAN2F(Left, Right);
535
536 return (Result);
537}
538
539HMM_INLINE float HMM_ExpF(float Float)
540{
541 float Result = HMM_EXPF(Float);
542
543 return (Result);
544}
545
546HMM_INLINE float HMM_LogF(float Float)
547{
548 float Result = HMM_LOGF(Float);
549
550 return (Result);
551}
552
553HMM_INLINE float HMM_SquareRootF(float Float)
554{
555 float Result;
556
557#ifdef HANDMADE_MATH__USE_SSE
558 __m128 In = _mm_set_ss(Float);
559 __m128 Out = _mm_sqrt_ss(In);
560 Result = _mm_cvtss_f32(Out);
561#else
562 Result = HMM_SQRTF(Float);
563#endif
564
565 return (Result);
566}
567
568HMM_INLINE float HMM_RSquareRootF(float Float)
569{
570 float Result;
571
572#ifdef HANDMADE_MATH__USE_SSE
573 __m128 In = _mm_set_ss(Float);
574 __m128 Out = _mm_rsqrt_ss(In);
575 Result = _mm_cvtss_f32(Out);
576#else
577 Result = 1.0f / HMM_SquareRootF(Float);
578#endif
579
580 return (Result);
581}
582
583HMM_EXTERN float HMM_Power(float Base, int Exponent);
584
585HMM_INLINE float HMM_PowerF(float Base, float Exponent)
586{
587 float Result = HMM_EXPF(Exponent * HMM_LOGF(Base));
588
589 return (Result);
590}
591
592/*
593 * Utility functions
594 */
595HMM_INLINE float HMM_ToRadians(float Degrees)
596{
597 float Result = Degrees * (HMM_PI32 / 180.0f);
598
599 return (Result);
600}
601
602HMM_INLINE float HMM_Lerp(float A, float Time, float B)
603{
604 float Result = (1.0f - Time) * A + Time * B;
605
606 return (Result);
607}
608
609HMM_INLINE float HMM_Clamp(float Min, float Value, float Max)
610{
611 float Result = Value;
612
613 if (Result < Min) {
614 Result = Min;
615 } else if (Result > Max) {
616 Result = Max;
617 }
618
619 return (Result);
620}
621
622/*
623 * Vector initialization
624 */
625
626HMM_INLINE hmm_vec2 HMM_Vec2(float X, float Y)
627{
628 hmm_vec2 Result;
629
630 Result.X = X;
631 Result.Y = Y;
632
633 return (Result);
634}
635
637{
638 hmm_vec2 Result;
639
640 Result.X = (float)X;
641 Result.Y = (float)Y;
642
643 return (Result);
644}
645
646HMM_INLINE hmm_vec3 HMM_Vec3(float X, float Y, float Z)
647{
648 hmm_vec3 Result;
649
650 Result.X = X;
651 Result.Y = Y;
652 Result.Z = Z;
653
654 return (Result);
655}
656
657HMM_INLINE hmm_vec3 HMM_Vec3i(int X, int Y, int Z)
658{
659 hmm_vec3 Result;
660
661 Result.X = (float)X;
662 Result.Y = (float)Y;
663 Result.Z = (float)Z;
664
665 return (Result);
666}
667
668HMM_INLINE hmm_vec4 HMM_Vec4(float X, float Y, float Z, float W)
669{
670 hmm_vec4 Result;
671
672#ifdef HANDMADE_MATH__USE_SSE
673 Result.InternalElementsSSE = _mm_setr_ps(X, Y, Z, W);
674#else
675 Result.X = X;
676 Result.Y = Y;
677 Result.Z = Z;
678 Result.W = W;
679#endif
680
681 return (Result);
682}
683
684HMM_INLINE hmm_vec4 HMM_Vec4i(int X, int Y, int Z, int W)
685{
686 hmm_vec4 Result;
687
688#ifdef HANDMADE_MATH__USE_SSE
689 Result.InternalElementsSSE = _mm_setr_ps((float)X, (float)Y, (float)Z, (float)W);
690#else
691 Result.X = (float)X;
692 Result.Y = (float)Y;
693 Result.Z = (float)Z;
694 Result.W = (float)W;
695#endif
696
697 return (Result);
698}
699
701{
702 hmm_vec4 Result;
703
704#ifdef HANDMADE_MATH__USE_SSE
705 Result.InternalElementsSSE = _mm_setr_ps(Vector.X, Vector.Y, Vector.Z, W);
706#else
707 Result.XYZ = Vector;
708 Result.W = W;
709#endif
710
711 return (Result);
712}
713
714/*
715 * Binary vector operations
716 */
717
719{
720 hmm_vec2 Result;
721
722 Result.X = Left.X + Right.X;
723 Result.Y = Left.Y + Right.Y;
724
725 return (Result);
726}
727
729{
730 hmm_vec3 Result;
731
732 Result.X = Left.X + Right.X;
733 Result.Y = Left.Y + Right.Y;
734 Result.Z = Left.Z + Right.Z;
735
736 return (Result);
737}
738
740{
741 hmm_vec4 Result;
742
743#ifdef HANDMADE_MATH__USE_SSE
744 Result.InternalElementsSSE = _mm_add_ps(Left.InternalElementsSSE, Right.InternalElementsSSE);
745#else
746 Result.X = Left.X + Right.X;
747 Result.Y = Left.Y + Right.Y;
748 Result.Z = Left.Z + Right.Z;
749 Result.W = Left.W + Right.W;
750#endif
751
752 return (Result);
753}
754
756{
757 hmm_vec2 Result;
758
759 Result.X = Left.X - Right.X;
760 Result.Y = Left.Y - Right.Y;
761
762 return (Result);
763}
764
766{
767 hmm_vec3 Result;
768
769 Result.X = Left.X - Right.X;
770 Result.Y = Left.Y - Right.Y;
771 Result.Z = Left.Z - Right.Z;
772
773 return (Result);
774}
775
777{
778 hmm_vec4 Result;
779
780#ifdef HANDMADE_MATH__USE_SSE
781 Result.InternalElementsSSE = _mm_sub_ps(Left.InternalElementsSSE, Right.InternalElementsSSE);
782#else
783 Result.X = Left.X - Right.X;
784 Result.Y = Left.Y - Right.Y;
785 Result.Z = Left.Z - Right.Z;
786 Result.W = Left.W - Right.W;
787#endif
788
789 return (Result);
790}
791
793{
794 hmm_vec2 Result;
795
796 Result.X = Left.X * Right.X;
797 Result.Y = Left.Y * Right.Y;
798
799 return (Result);
800}
801
803{
804 hmm_vec2 Result;
805
806 Result.X = Left.X * Right;
807 Result.Y = Left.Y * Right;
808
809 return (Result);
810}
811
813{
814 hmm_vec3 Result;
815
816 Result.X = Left.X * Right.X;
817 Result.Y = Left.Y * Right.Y;
818 Result.Z = Left.Z * Right.Z;
819
820 return (Result);
821}
822
824{
825 hmm_vec3 Result;
826
827 Result.X = Left.X * Right;
828 Result.Y = Left.Y * Right;
829 Result.Z = Left.Z * Right;
830
831 return (Result);
832}
833
835{
836 hmm_vec4 Result;
837
838#ifdef HANDMADE_MATH__USE_SSE
839 Result.InternalElementsSSE = _mm_mul_ps(Left.InternalElementsSSE, Right.InternalElementsSSE);
840#else
841 Result.X = Left.X * Right.X;
842 Result.Y = Left.Y * Right.Y;
843 Result.Z = Left.Z * Right.Z;
844 Result.W = Left.W * Right.W;
845#endif
846
847 return (Result);
848}
849
851{
852 hmm_vec4 Result;
853
854#ifdef HANDMADE_MATH__USE_SSE
855 __m128 Scalar = _mm_set1_ps(Right);
856 Result.InternalElementsSSE = _mm_mul_ps(Left.InternalElementsSSE, Scalar);
857#else
858 Result.X = Left.X * Right;
859 Result.Y = Left.Y * Right;
860 Result.Z = Left.Z * Right;
861 Result.W = Left.W * Right;
862#endif
863
864 return (Result);
865}
866
868{
869 hmm_vec2 Result;
870
871 Result.X = Left.X / Right.X;
872 Result.Y = Left.Y / Right.Y;
873
874 return (Result);
875}
876
878{
879 hmm_vec2 Result;
880
881 Result.X = Left.X / Right;
882 Result.Y = Left.Y / Right;
883
884 return (Result);
885}
886
888{
889 hmm_vec3 Result;
890
891 Result.X = Left.X / Right.X;
892 Result.Y = Left.Y / Right.Y;
893 Result.Z = Left.Z / Right.Z;
894
895 return (Result);
896}
897
899{
900 hmm_vec3 Result;
901
902 Result.X = Left.X / Right;
903 Result.Y = Left.Y / Right;
904 Result.Z = Left.Z / Right;
905
906 return (Result);
907}
908
910{
911 hmm_vec4 Result;
912
913#ifdef HANDMADE_MATH__USE_SSE
914 Result.InternalElementsSSE = _mm_div_ps(Left.InternalElementsSSE, Right.InternalElementsSSE);
915#else
916 Result.X = Left.X / Right.X;
917 Result.Y = Left.Y / Right.Y;
918 Result.Z = Left.Z / Right.Z;
919 Result.W = Left.W / Right.W;
920#endif
921
922 return (Result);
923}
924
926{
927 hmm_vec4 Result;
928
929#ifdef HANDMADE_MATH__USE_SSE
930 __m128 Scalar = _mm_set1_ps(Right);
931 Result.InternalElementsSSE = _mm_div_ps(Left.InternalElementsSSE, Scalar);
932#else
933 Result.X = Left.X / Right;
934 Result.Y = Left.Y / Right;
935 Result.Z = Left.Z / Right;
936 Result.W = Left.W / Right;
937#endif
938
939 return (Result);
940}
941
943{
944 hmm_bool Result = (Left.X == Right.X && Left.Y == Right.Y);
945
946 return (Result);
947}
948
950{
951 hmm_bool Result = (Left.X == Right.X && Left.Y == Right.Y && Left.Z == Right.Z);
952
953 return (Result);
954}
955
957{
958 hmm_bool Result = (Left.X == Right.X && Left.Y == Right.Y && Left.Z == Right.Z && Left.W == Right.W);
959
960 return (Result);
961}
962
964{
965 float Result = (VecOne.X * VecTwo.X) + (VecOne.Y * VecTwo.Y);
966
967 return (Result);
968}
969
971{
972 float Result = (VecOne.X * VecTwo.X) + (VecOne.Y * VecTwo.Y) + (VecOne.Z * VecTwo.Z);
973
974 return (Result);
975}
976
978{
979 float Result;
980
981 // NOTE(zak): IN the future if we wanna check what version SSE is support
982 // we can use _mm_dp_ps (4.3) but for now we will use the old way.
983 // Or a r = _mm_mul_ps(v1, v2), r = _mm_hadd_ps(r, r), r = _mm_hadd_ps(r, r) for SSE3
984#ifdef HANDMADE_MATH__USE_SSE
985 __m128 SSEResultOne = _mm_mul_ps(VecOne.InternalElementsSSE, VecTwo.InternalElementsSSE);
986 __m128 SSEResultTwo = _mm_shuffle_ps(SSEResultOne, SSEResultOne, _MM_SHUFFLE(2, 3, 0, 1));
987 SSEResultOne = _mm_add_ps(SSEResultOne, SSEResultTwo);
988 SSEResultTwo = _mm_shuffle_ps(SSEResultOne, SSEResultOne, _MM_SHUFFLE(0, 1, 2, 3));
989 SSEResultOne = _mm_add_ps(SSEResultOne, SSEResultTwo);
990 _mm_store_ss(&Result, SSEResultOne);
991#else
992 Result = (VecOne.X * VecTwo.X) + (VecOne.Y * VecTwo.Y) + (VecOne.Z * VecTwo.Z) + (VecOne.W * VecTwo.W);
993#endif
994
995 return (Result);
996}
997
999{
1000 hmm_vec3 Result;
1001
1002 Result.X = (VecOne.Y * VecTwo.Z) - (VecOne.Z * VecTwo.Y);
1003 Result.Y = (VecOne.Z * VecTwo.X) - (VecOne.X * VecTwo.Z);
1004 Result.Z = (VecOne.X * VecTwo.Y) - (VecOne.Y * VecTwo.X);
1005
1006 return (Result);
1007}
1008
1009/*
1010 * Unary vector operations
1011 */
1012
1014{
1015 float Result = HMM_DotVec2(A, A);
1016
1017 return (Result);
1018}
1019
1021{
1022 float Result = HMM_DotVec3(A, A);
1023
1024 return (Result);
1025}
1026
1028{
1029 float Result = HMM_DotVec4(A, A);
1030
1031 return (Result);
1032}
1033
1035{
1036 float Result = HMM_SquareRootF(HMM_LengthSquaredVec2(A));
1037
1038 return (Result);
1039}
1040
1042{
1043 float Result = HMM_SquareRootF(HMM_LengthSquaredVec3(A));
1044
1045 return (Result);
1046}
1047
1049{
1050 float Result = HMM_SquareRootF(HMM_LengthSquaredVec4(A));
1051
1052 return (Result);
1053}
1054
1056{
1057 hmm_vec2 Result = {0, 0};
1058
1059 float VectorLength = HMM_LengthVec2(A);
1060
1061 /* NOTE(kiljacken): We need a zero check to not divide-by-zero */
1062 if (VectorLength != 0.0f) {
1063 Result.X = A.X * (1.0f / VectorLength);
1064 Result.Y = A.Y * (1.0f / VectorLength);
1065 }
1066
1067 return (Result);
1068}
1069
1071{
1072 hmm_vec3 Result = {0, 0, 0};
1073
1074 float VectorLength = HMM_LengthVec3(A);
1075
1076 /* NOTE(kiljacken): We need a zero check to not divide-by-zero */
1077 if (VectorLength != 0.0f) {
1078 Result.X = A.X * (1.0f / VectorLength);
1079 Result.Y = A.Y * (1.0f / VectorLength);
1080 Result.Z = A.Z * (1.0f / VectorLength);
1081 }
1082
1083 return (Result);
1084}
1085
1087{
1088 hmm_vec4 Result = {0, 0, 0, 0};
1089
1090 float VectorLength = HMM_LengthVec4(A);
1091
1092 /* NOTE(kiljacken): We need a zero check to not divide-by-zero */
1093 if (VectorLength != 0.0f) {
1094 float Multiplier = 1.0f / VectorLength;
1095
1096#ifdef HANDMADE_MATH__USE_SSE
1097 __m128 SSEMultiplier = _mm_set1_ps(Multiplier);
1098 Result.InternalElementsSSE = _mm_mul_ps(A.InternalElementsSSE, SSEMultiplier);
1099#else
1100 Result.X = A.X * Multiplier;
1101 Result.Y = A.Y * Multiplier;
1102 Result.Z = A.Z * Multiplier;
1103 Result.W = A.W * Multiplier;
1104#endif
1105 }
1106
1107 return (Result);
1108}
1109
1110/*
1111 * SSE stuff
1112 */
1113
1114#ifdef HANDMADE_MATH__USE_SSE
1115HMM_INLINE __m128 HMM_LinearCombineSSE(__m128 Left, hmm_mat4 Right)
1116{
1117 __m128 Result;
1118 Result = _mm_mul_ps(_mm_shuffle_ps(Left, Left, 0x00), Right.Columns[0]);
1119 Result = _mm_add_ps(Result, _mm_mul_ps(_mm_shuffle_ps(Left, Left, 0x55), Right.Columns[1]));
1120 Result = _mm_add_ps(Result, _mm_mul_ps(_mm_shuffle_ps(Left, Left, 0xaa), Right.Columns[2]));
1121 Result = _mm_add_ps(Result, _mm_mul_ps(_mm_shuffle_ps(Left, Left, 0xff), Right.Columns[3]));
1122
1123 return (Result);
1124}
1125#endif
1126
1127/*
1128 * Matrix functions
1129 */
1130
1132{
1133 hmm_mat4 Result = {0};
1134
1135 return (Result);
1136}
1137
1139{
1140 hmm_mat4 Result = HMM_Mat4();
1141
1142 Result.Elements[0][0] = Diagonal;
1143 Result.Elements[1][1] = Diagonal;
1144 Result.Elements[2][2] = Diagonal;
1145 Result.Elements[3][3] = Diagonal;
1146
1147 return (Result);
1148}
1149
1150#ifdef HANDMADE_MATH__USE_SSE
1152{
1153 hmm_mat4 Result = Matrix;
1154
1155 _MM_TRANSPOSE4_PS(Result.Columns[0], Result.Columns[1], Result.Columns[2], Result.Columns[3]);
1156
1157 return (Result);
1158}
1159#else
1161#endif
1162
1163#ifdef HANDMADE_MATH__USE_SSE
1165{
1166 hmm_mat4 Result;
1167
1168 Result.Columns[0] = _mm_add_ps(Left.Columns[0], Right.Columns[0]);
1169 Result.Columns[1] = _mm_add_ps(Left.Columns[1], Right.Columns[1]);
1170 Result.Columns[2] = _mm_add_ps(Left.Columns[2], Right.Columns[2]);
1171 Result.Columns[3] = _mm_add_ps(Left.Columns[3], Right.Columns[3]);
1172
1173 return (Result);
1174}
1175#else
1177#endif
1178
1179#ifdef HANDMADE_MATH__USE_SSE
1181{
1182 hmm_mat4 Result;
1183
1184 Result.Columns[0] = _mm_sub_ps(Left.Columns[0], Right.Columns[0]);
1185 Result.Columns[1] = _mm_sub_ps(Left.Columns[1], Right.Columns[1]);
1186 Result.Columns[2] = _mm_sub_ps(Left.Columns[2], Right.Columns[2]);
1187 Result.Columns[3] = _mm_sub_ps(Left.Columns[3], Right.Columns[3]);
1188
1189 return (Result);
1190}
1191#else
1193#endif
1194
1196
1197#ifdef HANDMADE_MATH__USE_SSE
1198HMM_INLINE hmm_mat4 HMM_MultiplyMat4f(hmm_mat4 Matrix, float Scalar)
1199{
1200 hmm_mat4 Result;
1201
1202 __m128 SSEScalar = _mm_set1_ps(Scalar);
1203 Result.Columns[0] = _mm_mul_ps(Matrix.Columns[0], SSEScalar);
1204 Result.Columns[1] = _mm_mul_ps(Matrix.Columns[1], SSEScalar);
1205 Result.Columns[2] = _mm_mul_ps(Matrix.Columns[2], SSEScalar);
1206 Result.Columns[3] = _mm_mul_ps(Matrix.Columns[3], SSEScalar);
1207
1208 return (Result);
1209}
1210#else
1212#endif
1213
1215
1216#ifdef HANDMADE_MATH__USE_SSE
1217HMM_INLINE hmm_mat4 HMM_DivideMat4f(hmm_mat4 Matrix, float Scalar)
1218{
1219 hmm_mat4 Result;
1220
1221 __m128 SSEScalar = _mm_set1_ps(Scalar);
1222 Result.Columns[0] = _mm_div_ps(Matrix.Columns[0], SSEScalar);
1223 Result.Columns[1] = _mm_div_ps(Matrix.Columns[1], SSEScalar);
1224 Result.Columns[2] = _mm_div_ps(Matrix.Columns[2], SSEScalar);
1225 Result.Columns[3] = _mm_div_ps(Matrix.Columns[3], SSEScalar);
1226
1227 return (Result);
1228}
1229#else
1231#endif
1232
1233/*
1234 * Common graphics transformations
1235 */
1236
1237HMM_INLINE hmm_mat4 HMM_Orthographic(float Left, float Right, float Bottom, float Top, float Near, float Far)
1238{
1239 hmm_mat4 Result = HMM_Mat4();
1240
1241 Result.Elements[0][0] = 2.0f / (Right - Left);
1242 Result.Elements[1][1] = 2.0f / (Top - Bottom);
1243 Result.Elements[2][2] = 2.0f / (Near - Far);
1244 Result.Elements[3][3] = 1.0f;
1245
1246 Result.Elements[3][0] = (Left + Right) / (Left - Right);
1247 Result.Elements[3][1] = (Bottom + Top) / (Bottom - Top);
1248 Result.Elements[3][2] = (Far + Near) / (Near - Far);
1249
1250 return (Result);
1251}
1252
1253HMM_INLINE hmm_mat4 HMM_Perspective(float FOV, float AspectRatio, float Near, float Far)
1254{
1255 hmm_mat4 Result = HMM_Mat4();
1256
1257 float TanThetaOver2 = HMM_TanF(FOV * (HMM_PI32 / 360.0f));
1258
1259 Result.Elements[0][0] = 1.0f / TanThetaOver2;
1260 Result.Elements[1][1] = AspectRatio / TanThetaOver2;
1261 Result.Elements[2][3] = -1.0f;
1262 Result.Elements[2][2] = (Near + Far) / (Near - Far);
1263 Result.Elements[3][2] = (2.0f * Near * Far) / (Near - Far);
1264 Result.Elements[3][3] = 0.0f;
1265
1266 return (Result);
1267}
1268
1270{
1271 hmm_mat4 Result = HMM_Mat4d(1.0f);
1272
1273 Result.Elements[3][0] = Translation.X;
1274 Result.Elements[3][1] = Translation.Y;
1275 Result.Elements[3][2] = Translation.Z;
1276
1277 return (Result);
1278}
1279
1281
1283{
1284 hmm_mat4 Result = HMM_Mat4d(1.0f);
1285
1286 Result.Elements[0][0] = Scale.X;
1287 Result.Elements[1][1] = Scale.Y;
1288 Result.Elements[2][2] = Scale.Z;
1289
1290 return (Result);
1291}
1292
1294
1295/*
1296 * Quaternion operations
1297 */
1298
1299HMM_INLINE hmm_quaternion HMM_Quaternion(float X, float Y, float Z, float W)
1300{
1301 hmm_quaternion Result;
1302
1303 Result.X = X;
1304 Result.Y = Y;
1305 Result.Z = Z;
1306 Result.W = W;
1307
1308 return (Result);
1309}
1310
1312{
1313 hmm_quaternion Result;
1314
1315 Result.X = Vector.X;
1316 Result.Y = Vector.Y;
1317 Result.Z = Vector.Z;
1318 Result.W = Vector.W;
1319
1320 return (Result);
1321}
1322
1324{
1325 hmm_quaternion Result;
1326
1327 Result.X = Left.X + Right.X;
1328 Result.Y = Left.Y + Right.Y;
1329 Result.Z = Left.Z + Right.Z;
1330 Result.W = Left.W + Right.W;
1331
1332 return (Result);
1333}
1334
1336{
1337 hmm_quaternion Result;
1338
1339 Result.X = Left.X - Right.X;
1340 Result.Y = Left.Y - Right.Y;
1341 Result.Z = Left.Z - Right.Z;
1342 Result.W = Left.W - Right.W;
1343
1344 return (Result);
1345}
1346
1348{
1349 hmm_quaternion Result;
1350
1351 Result.X = (Left.X * Right.W) + (Left.Y * Right.Z) - (Left.Z * Right.Y) + (Left.W * Right.X);
1352 Result.Y = (-Left.X * Right.Z) + (Left.Y * Right.W) + (Left.Z * Right.X) + (Left.W * Right.Y);
1353 Result.Z = (Left.X * Right.Y) - (Left.Y * Right.X) + (Left.Z * Right.W) + (Left.W * Right.Z);
1354 Result.W = (-Left.X * Right.X) - (Left.Y * Right.Y) - (Left.Z * Right.Z) + (Left.W * Right.W);
1355
1356 return (Result);
1357}
1358
1360{
1361 hmm_quaternion Result;
1362
1363 Result.X = Left.X * Multiplicative;
1364 Result.Y = Left.Y * Multiplicative;
1365 Result.Z = Left.Z * Multiplicative;
1366 Result.W = Left.W * Multiplicative;
1367
1368 return (Result);
1369}
1370
1372{
1373 hmm_quaternion Result;
1374
1375 Result.X = Left.X / Dividend;
1376 Result.Y = Left.Y / Dividend;
1377 Result.Z = Left.Z / Dividend;
1378 Result.W = Left.W / Dividend;
1379
1380 return (Result);
1381}
1382
1384
1386{
1387 float Result = (Left.X * Right.X) + (Left.Y * Right.Y) + (Left.Z * Right.Z) + (Left.W * Right.W);
1388
1389 return (Result);
1390}
1391
1393{
1394 hmm_quaternion Result;
1395
1396 float Length = HMM_SquareRootF(HMM_DotQuaternion(Left, Left));
1397 Result = HMM_DivideQuaternionF(Left, Length);
1398
1399 return (Result);
1400}
1401
1403{
1404 hmm_quaternion Result;
1405
1406 Result.X = HMM_Lerp(Left.X, Time, Right.X);
1407 Result.Y = HMM_Lerp(Left.Y, Time, Right.Y);
1408 Result.Z = HMM_Lerp(Left.Z, Time, Right.Z);
1409 Result.W = HMM_Lerp(Left.W, Time, Right.W);
1410
1411 Result = HMM_NormalizeQuaternion(Result);
1412
1413 return (Result);
1414}
1415
1419
1420#ifdef __cplusplus
1421}
1422#endif
1423
1424#ifdef __cplusplus
1425
1426HMM_INLINE float HMM_Length(hmm_vec2 A)
1427{
1428 float Result = HMM_LengthVec2(A);
1429
1430 return (Result);
1431}
1432
1433HMM_INLINE float HMM_Length(hmm_vec3 A)
1434{
1435 float Result = HMM_LengthVec3(A);
1436
1437 return (Result);
1438}
1439
1440HMM_INLINE float HMM_Length(hmm_vec4 A)
1441{
1442 float Result = HMM_LengthVec4(A);
1443
1444 return (Result);
1445}
1446
1447HMM_INLINE float HMM_LengthSquared(hmm_vec2 A)
1448{
1449 float Result = HMM_LengthSquaredVec2(A);
1450
1451 return (Result);
1452}
1453
1454HMM_INLINE float HMM_LengthSquared(hmm_vec3 A)
1455{
1456 float Result = HMM_LengthSquaredVec3(A);
1457
1458 return (Result);
1459}
1460
1461HMM_INLINE float HMM_LengthSquared(hmm_vec4 A)
1462{
1463 float Result = HMM_LengthSquaredVec4(A);
1464
1465 return (Result);
1466}
1467
1468HMM_INLINE hmm_vec2 HMM_Normalize(hmm_vec2 A)
1469{
1470 hmm_vec2 Result = HMM_NormalizeVec2(A);
1471
1472 return (Result);
1473}
1474
1475HMM_INLINE hmm_vec3 HMM_Normalize(hmm_vec3 A)
1476{
1477 hmm_vec3 Result = HMM_NormalizeVec3(A);
1478
1479 return (Result);
1480}
1481
1482HMM_INLINE hmm_vec4 HMM_Normalize(hmm_vec4 A)
1483{
1484 hmm_vec4 Result = HMM_NormalizeVec4(A);
1485
1486 return (Result);
1487}
1488
1490{
1492
1493 return (Result);
1494}
1495
1496HMM_INLINE float HMM_Dot(hmm_vec2 VecOne, hmm_vec2 VecTwo)
1497{
1498 float Result = HMM_DotVec2(VecOne, VecTwo);
1499
1500 return (Result);
1501}
1502
1503HMM_INLINE float HMM_Dot(hmm_vec3 VecOne, hmm_vec3 VecTwo)
1504{
1505 float Result = HMM_DotVec3(VecOne, VecTwo);
1506
1507 return (Result);
1508}
1509
1510HMM_INLINE float HMM_Dot(hmm_vec4 VecOne, hmm_vec4 VecTwo)
1511{
1512 float Result = HMM_DotVec4(VecOne, VecTwo);
1513
1514 return (Result);
1515}
1516
1517HMM_INLINE float HMM_Dot(hmm_quaternion QuatOne, hmm_quaternion QuatTwo)
1518{
1519 float Result = HMM_DotQuaternion(QuatOne, QuatTwo);
1520
1521 return (Result);
1522}
1523
1524HMM_INLINE hmm_vec2 HMM_Add(hmm_vec2 Left, hmm_vec2 Right)
1525{
1526 hmm_vec2 Result = HMM_AddVec2(Left, Right);
1527
1528 return (Result);
1529}
1530
1531HMM_INLINE hmm_vec3 HMM_Add(hmm_vec3 Left, hmm_vec3 Right)
1532{
1533 hmm_vec3 Result = HMM_AddVec3(Left, Right);
1534
1535 return (Result);
1536}
1537
1538HMM_INLINE hmm_vec4 HMM_Add(hmm_vec4 Left, hmm_vec4 Right)
1539{
1540 hmm_vec4 Result = HMM_AddVec4(Left, Right);
1541
1542 return (Result);
1543}
1544
1545HMM_INLINE hmm_mat4 HMM_Add(hmm_mat4 Left, hmm_mat4 Right)
1546{
1547 hmm_mat4 Result = HMM_AddMat4(Left, Right);
1548
1549 return (Result);
1550}
1551
1553{
1554 hmm_quaternion Result = HMM_AddQuaternion(Left, Right);
1555
1556 return (Result);
1557}
1558
1559HMM_INLINE hmm_vec2 HMM_Subtract(hmm_vec2 Left, hmm_vec2 Right)
1560{
1561 hmm_vec2 Result = HMM_SubtractVec2(Left, Right);
1562
1563 return (Result);
1564}
1565
1566HMM_INLINE hmm_vec3 HMM_Subtract(hmm_vec3 Left, hmm_vec3 Right)
1567{
1568 hmm_vec3 Result = HMM_SubtractVec3(Left, Right);
1569
1570 return (Result);
1571}
1572
1573HMM_INLINE hmm_vec4 HMM_Subtract(hmm_vec4 Left, hmm_vec4 Right)
1574{
1575 hmm_vec4 Result = HMM_SubtractVec4(Left, Right);
1576
1577 return (Result);
1578}
1579
1580HMM_INLINE hmm_mat4 HMM_Subtract(hmm_mat4 Left, hmm_mat4 Right)
1581{
1582 hmm_mat4 Result = HMM_SubtractMat4(Left, Right);
1583
1584 return (Result);
1585}
1586
1588{
1589 hmm_quaternion Result = HMM_SubtractQuaternion(Left, Right);
1590
1591 return (Result);
1592}
1593
1594HMM_INLINE hmm_vec2 HMM_Multiply(hmm_vec2 Left, hmm_vec2 Right)
1595{
1596 hmm_vec2 Result = HMM_MultiplyVec2(Left, Right);
1597
1598 return (Result);
1599}
1600
1601HMM_INLINE hmm_vec2 HMM_Multiply(hmm_vec2 Left, float Right)
1602{
1603 hmm_vec2 Result = HMM_MultiplyVec2f(Left, Right);
1604
1605 return (Result);
1606}
1607
1608HMM_INLINE hmm_vec3 HMM_Multiply(hmm_vec3 Left, hmm_vec3 Right)
1609{
1610 hmm_vec3 Result = HMM_MultiplyVec3(Left, Right);
1611
1612 return (Result);
1613}
1614
1615HMM_INLINE hmm_vec3 HMM_Multiply(hmm_vec3 Left, float Right)
1616{
1617 hmm_vec3 Result = HMM_MultiplyVec3f(Left, Right);
1618
1619 return (Result);
1620}
1621
1622HMM_INLINE hmm_vec4 HMM_Multiply(hmm_vec4 Left, hmm_vec4 Right)
1623{
1624 hmm_vec4 Result = HMM_MultiplyVec4(Left, Right);
1625
1626 return (Result);
1627}
1628
1629HMM_INLINE hmm_vec4 HMM_Multiply(hmm_vec4 Left, float Right)
1630{
1631 hmm_vec4 Result = HMM_MultiplyVec4f(Left, Right);
1632
1633 return (Result);
1634}
1635
1636HMM_INLINE hmm_mat4 HMM_Multiply(hmm_mat4 Left, hmm_mat4 Right)
1637{
1638 hmm_mat4 Result = HMM_MultiplyMat4(Left, Right);
1639
1640 return (Result);
1641}
1642
1643HMM_INLINE hmm_mat4 HMM_Multiply(hmm_mat4 Left, float Right)
1644{
1645 hmm_mat4 Result = HMM_MultiplyMat4f(Left, Right);
1646
1647 return (Result);
1648}
1649
1650HMM_INLINE hmm_vec4 HMM_Multiply(hmm_mat4 Matrix, hmm_vec4 Vector)
1651{
1652 hmm_vec4 Result = HMM_MultiplyMat4ByVec4(Matrix, Vector);
1653
1654 return (Result);
1655}
1656
1658{
1659 hmm_quaternion Result = HMM_MultiplyQuaternion(Left, Right);
1660
1661 return (Result);
1662}
1663
1664HMM_INLINE hmm_quaternion HMM_Multiply(hmm_quaternion Left, float Right)
1665{
1666 hmm_quaternion Result = HMM_MultiplyQuaternionF(Left, Right);
1667
1668 return (Result);
1669}
1670
1671HMM_INLINE hmm_vec2 HMM_Divide(hmm_vec2 Left, hmm_vec2 Right)
1672{
1673 hmm_vec2 Result = HMM_DivideVec2(Left, Right);
1674
1675 return (Result);
1676}
1677
1678HMM_INLINE hmm_vec2 HMM_Divide(hmm_vec2 Left, float Right)
1679{
1680 hmm_vec2 Result = HMM_DivideVec2f(Left, Right);
1681
1682 return (Result);
1683}
1684
1685HMM_INLINE hmm_vec3 HMM_Divide(hmm_vec3 Left, hmm_vec3 Right)
1686{
1687 hmm_vec3 Result = HMM_DivideVec3(Left, Right);
1688
1689 return (Result);
1690}
1691
1692HMM_INLINE hmm_vec3 HMM_Divide(hmm_vec3 Left, float Right)
1693{
1694 hmm_vec3 Result = HMM_DivideVec3f(Left, Right);
1695
1696 return (Result);
1697}
1698
1699HMM_INLINE hmm_vec4 HMM_Divide(hmm_vec4 Left, hmm_vec4 Right)
1700{
1701 hmm_vec4 Result = HMM_DivideVec4(Left, Right);
1702
1703 return (Result);
1704}
1705
1706HMM_INLINE hmm_vec4 HMM_Divide(hmm_vec4 Left, float Right)
1707{
1708 hmm_vec4 Result = HMM_DivideVec4f(Left, Right);
1709
1710 return (Result);
1711}
1712
1713HMM_INLINE hmm_mat4 HMM_Divide(hmm_mat4 Left, float Right)
1714{
1715 hmm_mat4 Result = HMM_DivideMat4f(Left, Right);
1716
1717 return (Result);
1718}
1719
1720HMM_INLINE hmm_quaternion HMM_Divide(hmm_quaternion Left, float Right)
1721{
1722 hmm_quaternion Result = HMM_DivideQuaternionF(Left, Right);
1723
1724 return (Result);
1725}
1726
1727HMM_INLINE hmm_bool HMM_Equals(hmm_vec2 Left, hmm_vec2 Right)
1728{
1729 hmm_bool Result = HMM_EqualsVec2(Left, Right);
1730
1731 return (Result);
1732}
1733
1734HMM_INLINE hmm_bool HMM_Equals(hmm_vec3 Left, hmm_vec3 Right)
1735{
1736 hmm_bool Result = HMM_EqualsVec3(Left, Right);
1737
1738 return (Result);
1739}
1740
1741HMM_INLINE hmm_bool HMM_Equals(hmm_vec4 Left, hmm_vec4 Right)
1742{
1743 hmm_bool Result = HMM_EqualsVec4(Left, Right);
1744
1745 return (Result);
1746}
1747
1749{
1750 hmm_vec2 Result = HMM_AddVec2(Left, Right);
1751
1752 return (Result);
1753}
1754
1756{
1757 hmm_vec3 Result = HMM_AddVec3(Left, Right);
1758
1759 return (Result);
1760}
1761
1763{
1764 hmm_vec4 Result = HMM_AddVec4(Left, Right);
1765
1766 return (Result);
1767}
1768
1770{
1771 hmm_mat4 Result = HMM_AddMat4(Left, Right);
1772
1773 return (Result);
1774}
1775
1777{
1778 hmm_quaternion Result = HMM_AddQuaternion(Left, Right);
1779
1780 return (Result);
1781}
1782
1784{
1785 hmm_vec2 Result = HMM_SubtractVec2(Left, Right);
1786
1787 return (Result);
1788}
1789
1791{
1792 hmm_vec3 Result = HMM_SubtractVec3(Left, Right);
1793
1794 return (Result);
1795}
1796
1798{
1799 hmm_vec4 Result = HMM_SubtractVec4(Left, Right);
1800
1801 return (Result);
1802}
1803
1805{
1806 hmm_mat4 Result = HMM_SubtractMat4(Left, Right);
1807
1808 return (Result);
1809}
1810
1812{
1813 hmm_quaternion Result = HMM_SubtractQuaternion(Left, Right);
1814
1815 return (Result);
1816}
1817
1819{
1820 hmm_vec2 Result = HMM_MultiplyVec2(Left, Right);
1821
1822 return (Result);
1823}
1824
1826{
1827 hmm_vec3 Result = HMM_MultiplyVec3(Left, Right);
1828
1829 return (Result);
1830}
1831
1833{
1834 hmm_vec4 Result = HMM_MultiplyVec4(Left, Right);
1835
1836 return (Result);
1837}
1838
1840{
1841 hmm_mat4 Result = HMM_MultiplyMat4(Left, Right);
1842
1843 return (Result);
1844}
1845
1847{
1848 hmm_quaternion Result = HMM_MultiplyQuaternion(Left, Right);
1849
1850 return (Result);
1851}
1852
1853HMM_INLINE hmm_vec2 operator*(hmm_vec2 Left, float Right)
1854{
1855 hmm_vec2 Result = HMM_MultiplyVec2f(Left, Right);
1856
1857 return (Result);
1858}
1859
1860HMM_INLINE hmm_vec3 operator*(hmm_vec3 Left, float Right)
1861{
1862 hmm_vec3 Result = HMM_MultiplyVec3f(Left, Right);
1863
1864 return (Result);
1865}
1866
1867HMM_INLINE hmm_vec4 operator*(hmm_vec4 Left, float Right)
1868{
1869 hmm_vec4 Result = HMM_MultiplyVec4f(Left, Right);
1870
1871 return (Result);
1872}
1873
1874HMM_INLINE hmm_mat4 operator*(hmm_mat4 Left, float Right)
1875{
1876 hmm_mat4 Result = HMM_MultiplyMat4f(Left, Right);
1877
1878 return (Result);
1879}
1880
1882{
1883 hmm_quaternion Result = HMM_MultiplyQuaternionF(Left, Right);
1884
1885 return (Result);
1886}
1887
1888HMM_INLINE hmm_vec2 operator*(float Left, hmm_vec2 Right)
1889{
1890 hmm_vec2 Result = HMM_MultiplyVec2f(Right, Left);
1891
1892 return (Result);
1893}
1894
1895HMM_INLINE hmm_vec3 operator*(float Left, hmm_vec3 Right)
1896{
1897 hmm_vec3 Result = HMM_MultiplyVec3f(Right, Left);
1898
1899 return (Result);
1900}
1901
1902HMM_INLINE hmm_vec4 operator*(float Left, hmm_vec4 Right)
1903{
1904 hmm_vec4 Result = HMM_MultiplyVec4f(Right, Left);
1905
1906 return (Result);
1907}
1908
1909HMM_INLINE hmm_mat4 operator*(float Left, hmm_mat4 Right)
1910{
1911 hmm_mat4 Result = HMM_MultiplyMat4f(Right, Left);
1912
1913 return (Result);
1914}
1915
1917{
1918 hmm_quaternion Result = HMM_MultiplyQuaternionF(Right, Left);
1919
1920 return (Result);
1921}
1922
1924{
1925 hmm_vec4 Result = HMM_MultiplyMat4ByVec4(Matrix, Vector);
1926
1927 return (Result);
1928}
1929
1930HMM_INLINE hmm_vec2 operator/(hmm_vec2 Left, hmm_vec2 Right)
1931{
1932 hmm_vec2 Result = HMM_DivideVec2(Left, Right);
1933
1934 return (Result);
1935}
1936
1937HMM_INLINE hmm_vec3 operator/(hmm_vec3 Left, hmm_vec3 Right)
1938{
1939 hmm_vec3 Result = HMM_DivideVec3(Left, Right);
1940
1941 return (Result);
1942}
1943
1944HMM_INLINE hmm_vec4 operator/(hmm_vec4 Left, hmm_vec4 Right)
1945{
1946 hmm_vec4 Result = HMM_DivideVec4(Left, Right);
1947
1948 return (Result);
1949}
1950
1951HMM_INLINE hmm_vec2 operator/(hmm_vec2 Left, float Right)
1952{
1953 hmm_vec2 Result = HMM_DivideVec2f(Left, Right);
1954
1955 return (Result);
1956}
1957
1958HMM_INLINE hmm_vec3 operator/(hmm_vec3 Left, float Right)
1959{
1960 hmm_vec3 Result = HMM_DivideVec3f(Left, Right);
1961
1962 return (Result);
1963}
1964
1965HMM_INLINE hmm_vec4 operator/(hmm_vec4 Left, float Right)
1966{
1967 hmm_vec4 Result = HMM_DivideVec4f(Left, Right);
1968
1969 return (Result);
1970}
1971
1972HMM_INLINE hmm_mat4 operator/(hmm_mat4 Left, float Right)
1973{
1974 hmm_mat4 Result = HMM_DivideMat4f(Left, Right);
1975
1976 return (Result);
1977}
1978
1979HMM_INLINE hmm_quaternion operator/(hmm_quaternion Left, float Right)
1980{
1981 hmm_quaternion Result = HMM_DivideQuaternionF(Left, Right);
1982
1983 return (Result);
1984}
1985
1987{
1988 return (Left = Left + Right);
1989}
1990
1992{
1993 return (Left = Left + Right);
1994}
1995
1997{
1998 return (Left = Left + Right);
1999}
2000
2002{
2003 return (Left = Left + Right);
2004}
2005
2007{
2008 return (Left = Left + Right);
2009}
2010
2011HMM_INLINE hmm_vec2& operator-=(hmm_vec2& Left, hmm_vec2 Right)
2012{
2013 return (Left = Left - Right);
2014}
2015
2016HMM_INLINE hmm_vec3& operator-=(hmm_vec3& Left, hmm_vec3 Right)
2017{
2018 return (Left = Left - Right);
2019}
2020
2021HMM_INLINE hmm_vec4& operator-=(hmm_vec4& Left, hmm_vec4 Right)
2022{
2023 return (Left = Left - Right);
2024}
2025
2026HMM_INLINE hmm_mat4& operator-=(hmm_mat4& Left, hmm_mat4 Right)
2027{
2028 return (Left = Left - Right);
2029}
2030
2032{
2033 return (Left = Left - Right);
2034}
2035
2036HMM_INLINE hmm_vec2& operator*=(hmm_vec2& Left, hmm_vec2 Right)
2037{
2038 return (Left = Left * Right);
2039}
2040
2041HMM_INLINE hmm_vec3& operator*=(hmm_vec3& Left, hmm_vec3 Right)
2042{
2043 return (Left = Left * Right);
2044}
2045
2046HMM_INLINE hmm_vec4& operator*=(hmm_vec4& Left, hmm_vec4 Right)
2047{
2048 return (Left = Left * Right);
2049}
2050
2051HMM_INLINE hmm_vec2& operator*=(hmm_vec2& Left, float Right)
2052{
2053 return (Left = Left * Right);
2054}
2055
2056HMM_INLINE hmm_vec3& operator*=(hmm_vec3& Left, float Right)
2057{
2058 return (Left = Left * Right);
2059}
2060
2061HMM_INLINE hmm_vec4& operator*=(hmm_vec4& Left, float Right)
2062{
2063 return (Left = Left * Right);
2064}
2065
2066HMM_INLINE hmm_mat4& operator*=(hmm_mat4& Left, float Right)
2067{
2068 return (Left = Left * Right);
2069}
2070
2071HMM_INLINE hmm_quaternion& operator*=(hmm_quaternion& Left, float Right)
2072{
2073 return (Left = Left * Right);
2074}
2075
2076HMM_INLINE hmm_vec2& operator/=(hmm_vec2& Left, hmm_vec2 Right)
2077{
2078 return (Left = Left / Right);
2079}
2080
2081HMM_INLINE hmm_vec3& operator/=(hmm_vec3& Left, hmm_vec3 Right)
2082{
2083 return (Left = Left / Right);
2084}
2085
2086HMM_INLINE hmm_vec4& operator/=(hmm_vec4& Left, hmm_vec4 Right)
2087{
2088 return (Left = Left / Right);
2089}
2090
2091HMM_INLINE hmm_vec2& operator/=(hmm_vec2& Left, float Right)
2092{
2093 return (Left = Left / Right);
2094}
2095
2096HMM_INLINE hmm_vec3& operator/=(hmm_vec3& Left, float Right)
2097{
2098 return (Left = Left / Right);
2099}
2100
2101HMM_INLINE hmm_vec4& operator/=(hmm_vec4& Left, float Right)
2102{
2103 return (Left = Left / Right);
2104}
2105
2106HMM_INLINE hmm_mat4& operator/=(hmm_mat4& Left, float Right)
2107{
2108 return (Left = Left / Right);
2109}
2110
2111HMM_INLINE hmm_quaternion& operator/=(hmm_quaternion& Left, float Right)
2112{
2113 return (Left = Left / Right);
2114}
2115
2117{
2118 return HMM_EqualsVec2(Left, Right);
2119}
2120
2122{
2123 return HMM_EqualsVec3(Left, Right);
2124}
2125
2127{
2128 return HMM_EqualsVec4(Left, Right);
2129}
2130
2132{
2133 return !HMM_EqualsVec2(Left, Right);
2134}
2135
2137{
2138 return !HMM_EqualsVec3(Left, Right);
2139}
2140
2142{
2143 return !HMM_EqualsVec4(Left, Right);
2144}
2145
2146#endif /* __cplusplus */
2147
2148#ifdef __clang__
2149#pragma GCC diagnostic pop
2150#endif
2151
2152#endif /* HANDMADE_MATH_H */
2153
2154#ifdef HANDMADE_MATH_IMPLEMENTATION
2155
2156float HMM_Power(float Base, int Exponent)
2157{
2158 float Result = 1.0f;
2159 float Mul = Exponent < 0 ? 1.f / Base : Base;
2160 unsigned int X = Exponent < 0 ? -Exponent : Exponent;
2161 while (X) {
2162 if (X & 1) {
2163 Result *= Mul;
2164 }
2165
2166 Mul *= Mul;
2167 X >>= 1;
2168 }
2169
2170 return (Result);
2171}
2172
2173#ifndef HANDMADE_MATH__USE_SSE
2175{
2176 hmm_mat4 Result;
2177
2178 int Columns;
2179 for (Columns = 0; Columns < 4; ++Columns) {
2180 int Rows;
2181 for (Rows = 0; Rows < 4; ++Rows) {
2182 Result.Elements[Rows][Columns] = Matrix.Elements[Columns][Rows];
2183 }
2184 }
2185
2186 return (Result);
2187}
2188#endif
2189
2190#ifndef HANDMADE_MATH__USE_SSE
2192{
2193 hmm_mat4 Result;
2194
2195 int Columns;
2196 for (Columns = 0; Columns < 4; ++Columns) {
2197 int Rows;
2198 for (Rows = 0; Rows < 4; ++Rows) {
2199 Result.Elements[Columns][Rows] = Left.Elements[Columns][Rows] + Right.Elements[Columns][Rows];
2200 }
2201 }
2202
2203 return (Result);
2204}
2205#endif
2206
2207#ifndef HANDMADE_MATH__USE_SSE
2209{
2210 hmm_mat4 Result;
2211
2212 int Columns;
2213 for (Columns = 0; Columns < 4; ++Columns) {
2214 int Rows;
2215 for (Rows = 0; Rows < 4; ++Rows) {
2216 Result.Elements[Columns][Rows] = Left.Elements[Columns][Rows] - Right.Elements[Columns][Rows];
2217 }
2218 }
2219
2220 return (Result);
2221}
2222#endif
2223
2225{
2226 hmm_mat4 Result;
2227
2228#ifdef HANDMADE_MATH__USE_SSE
2229
2230 Result.Columns[0] = HMM_LinearCombineSSE(Right.Columns[0], Left);
2231 Result.Columns[1] = HMM_LinearCombineSSE(Right.Columns[1], Left);
2232 Result.Columns[2] = HMM_LinearCombineSSE(Right.Columns[2], Left);
2233 Result.Columns[3] = HMM_LinearCombineSSE(Right.Columns[3], Left);
2234
2235#else
2236 int Columns;
2237 for (Columns = 0; Columns < 4; ++Columns) {
2238 int Rows;
2239 for (Rows = 0; Rows < 4; ++Rows) {
2240 float Sum = 0;
2241 int CurrentMatrice;
2242 for (CurrentMatrice = 0; CurrentMatrice < 4; ++CurrentMatrice) {
2243 Sum += Left.Elements[CurrentMatrice][Rows] * Right.Elements[Columns][CurrentMatrice];
2244 }
2245
2246 Result.Elements[Columns][Rows] = Sum;
2247 }
2248 }
2249#endif
2250
2251 return (Result);
2252}
2253
2254#ifndef HANDMADE_MATH__USE_SSE
2255hmm_mat4 HMM_MultiplyMat4f(hmm_mat4 Matrix, float Scalar)
2256{
2257 hmm_mat4 Result;
2258
2259 int Columns;
2260 for (Columns = 0; Columns < 4; ++Columns) {
2261 int Rows;
2262 for (Rows = 0; Rows < 4; ++Rows) {
2263 Result.Elements[Columns][Rows] = Matrix.Elements[Columns][Rows] * Scalar;
2264 }
2265 }
2266
2267 return (Result);
2268}
2269#endif
2270
2272{
2273 hmm_vec4 Result;
2274
2275#ifdef HANDMADE_MATH__USE_SSE
2276 Result.InternalElementsSSE = HMM_LinearCombineSSE(Vector.InternalElementsSSE, Matrix);
2277#else
2278 int Columns, Rows;
2279 for (Rows = 0; Rows < 4; ++Rows) {
2280 float Sum = 0;
2281 for (Columns = 0; Columns < 4; ++Columns) {
2282 Sum += Matrix.Elements[Columns][Rows] * Vector.Elements[Columns];
2283 }
2284
2285 Result.Elements[Rows] = Sum;
2286 }
2287#endif
2288
2289 return (Result);
2290}
2291
2292#ifndef HANDMADE_MATH__USE_SSE
2293hmm_mat4 HMM_DivideMat4f(hmm_mat4 Matrix, float Scalar)
2294{
2295 hmm_mat4 Result;
2296
2297 int Columns;
2298 for (Columns = 0; Columns < 4; ++Columns) {
2299 int Rows;
2300 for (Rows = 0; Rows < 4; ++Rows) {
2301 Result.Elements[Columns][Rows] = Matrix.Elements[Columns][Rows] / Scalar;
2302 }
2303 }
2304
2305 return (Result);
2306}
2307#endif
2308
2309hmm_mat4 HMM_Rotate(float Angle, hmm_vec3 Axis)
2310{
2311 hmm_mat4 Result = HMM_Mat4d(1.0f);
2312
2313 Axis = HMM_NormalizeVec3(Axis);
2314
2315 float SinTheta = HMM_SinF(HMM_ToRadians(Angle));
2316 float CosTheta = HMM_CosF(HMM_ToRadians(Angle));
2317 float CosValue = 1.0f - CosTheta;
2318
2319 Result.Elements[0][0] = (Axis.X * Axis.X * CosValue) + CosTheta;
2320 Result.Elements[0][1] = (Axis.X * Axis.Y * CosValue) + (Axis.Z * SinTheta);
2321 Result.Elements[0][2] = (Axis.X * Axis.Z * CosValue) - (Axis.Y * SinTheta);
2322
2323 Result.Elements[1][0] = (Axis.Y * Axis.X * CosValue) - (Axis.Z * SinTheta);
2324 Result.Elements[1][1] = (Axis.Y * Axis.Y * CosValue) + CosTheta;
2325 Result.Elements[1][2] = (Axis.Y * Axis.Z * CosValue) + (Axis.X * SinTheta);
2326
2327 Result.Elements[2][0] = (Axis.Z * Axis.X * CosValue) + (Axis.Y * SinTheta);
2328 Result.Elements[2][1] = (Axis.Z * Axis.Y * CosValue) - (Axis.X * SinTheta);
2329 Result.Elements[2][2] = (Axis.Z * Axis.Z * CosValue) + CosTheta;
2330
2331 return (Result);
2332}
2333
2335{
2336 hmm_mat4 Result;
2337
2340 hmm_vec3 U = HMM_Cross(S, F);
2341
2342 Result.Elements[0][0] = S.X;
2343 Result.Elements[0][1] = U.X;
2344 Result.Elements[0][2] = -F.X;
2345 Result.Elements[0][3] = 0.0f;
2346
2347 Result.Elements[1][0] = S.Y;
2348 Result.Elements[1][1] = U.Y;
2349 Result.Elements[1][2] = -F.Y;
2350 Result.Elements[1][3] = 0.0f;
2351
2352 Result.Elements[2][0] = S.Z;
2353 Result.Elements[2][1] = U.Z;
2354 Result.Elements[2][2] = -F.Z;
2355 Result.Elements[2][3] = 0.0f;
2356
2357 Result.Elements[3][0] = -HMM_DotVec3(S, Eye);
2358 Result.Elements[3][1] = -HMM_DotVec3(U, Eye);
2359 Result.Elements[3][2] = HMM_DotVec3(F, Eye);
2360 Result.Elements[3][3] = 1.0f;
2361
2362 return (Result);
2363}
2364
2366{
2367 hmm_quaternion Conjugate;
2368 hmm_quaternion Result;
2369 float Norm = 0;
2370 float NormSquared = 0;
2371
2372 Conjugate.X = -Left.X;
2373 Conjugate.Y = -Left.Y;
2374 Conjugate.Z = -Left.Z;
2375 Conjugate.W = Left.W;
2376
2377 Norm = HMM_SquareRootF(HMM_DotQuaternion(Left, Left));
2378 NormSquared = Norm * Norm;
2379
2380 Result.X = Conjugate.X / NormSquared;
2381 Result.Y = Conjugate.Y / NormSquared;
2382 Result.Z = Conjugate.Z / NormSquared;
2383 Result.W = Conjugate.W / NormSquared;
2384
2385 return (Result);
2386}
2387
2389{
2390 hmm_quaternion Result;
2391 hmm_quaternion QuaternionLeft;
2392 hmm_quaternion QuaternionRight;
2393
2394 float Cos_Theta = HMM_DotQuaternion(Left, Right);
2395 float Angle = HMM_ACosF(Cos_Theta);
2396
2397 float S1 = HMM_SinF((1.0f - Time) * Angle);
2398 float S2 = HMM_SinF(Time * Angle);
2399 float Is = 1.0f / HMM_SinF(Angle);
2400
2401 QuaternionLeft = HMM_MultiplyQuaternionF(Left, S1);
2402 QuaternionRight = HMM_MultiplyQuaternionF(Right, S2);
2403
2404 Result = HMM_AddQuaternion(QuaternionLeft, QuaternionRight);
2405 Result = HMM_MultiplyQuaternionF(Result, Is);
2406
2407 return (Result);
2408}
2409
2411{
2412 hmm_mat4 Result;
2413 Result = HMM_Mat4d(1);
2414
2415 hmm_quaternion NormalizedQuaternion = HMM_NormalizeQuaternion(Left);
2416
2417 float XX, YY, ZZ,
2418 XY, XZ, YZ,
2419 WX, WY, WZ;
2420
2421 XX = NormalizedQuaternion.X * NormalizedQuaternion.X;
2422 YY = NormalizedQuaternion.Y * NormalizedQuaternion.Y;
2423 ZZ = NormalizedQuaternion.Z * NormalizedQuaternion.Z;
2424 XY = NormalizedQuaternion.X * NormalizedQuaternion.Y;
2425 XZ = NormalizedQuaternion.X * NormalizedQuaternion.Z;
2426 YZ = NormalizedQuaternion.Y * NormalizedQuaternion.Z;
2427 WX = NormalizedQuaternion.W * NormalizedQuaternion.X;
2428 WY = NormalizedQuaternion.W * NormalizedQuaternion.Y;
2429 WZ = NormalizedQuaternion.W * NormalizedQuaternion.Z;
2430
2431 Result.Elements[0][0] = 1.0f - 2.0f * (YY + ZZ);
2432 Result.Elements[0][1] = 2.0f * (XY + WZ);
2433 Result.Elements[0][2] = 2.0f * (XZ - WY);
2434
2435 Result.Elements[1][0] = 2.0f * (XY - WZ);
2436 Result.Elements[1][1] = 1.0f - 2.0f * (XX + ZZ);
2437 Result.Elements[1][2] = 2.0f * (YZ + WX);
2438
2439 Result.Elements[2][0] = 2.0f * (XZ + WY);
2440 Result.Elements[2][1] = 2.0f * (YZ - WX);
2441 Result.Elements[2][2] = 1.0f - 2.0f * (XX + YY);
2442
2443 return (Result);
2444}
2445
2446hmm_quaternion HMM_QuaternionFromAxisAngle(hmm_vec3 Axis, float AngleOfRotation)
2447{
2448 hmm_quaternion Result;
2449
2450 hmm_vec3 RotatedVector;
2451
2452 float AxisNorm = 0;
2453 float SineOfRotation = 0;
2454
2455 AxisNorm = HMM_SquareRootF(HMM_DotVec3(Axis, Axis));
2456 SineOfRotation = HMM_SinF(AngleOfRotation / 2.0f);
2457 RotatedVector = HMM_MultiplyVec3f(Axis, SineOfRotation);
2458
2459 Result.W = HMM_CosF(AngleOfRotation / 2.0f);
2460 Result.XYZ = HMM_DivideVec3f(RotatedVector, AxisNorm);
2461
2462 return (Result);
2463}
2464
2465#endif /* HANDMADE_MATH_IMPLEMENTATION */
o2::monitoring::tags::Value Value
Hit operator+(const Hit &lhs, const Hit &rhs)
Definition Hit.cxx:46
HMM_INLINE hmm_mat4 HMM_Orthographic(float Left, float Right, float Bottom, float Top, float Near, float Far)
HMM_INLINE hmm_vec2 HMM_Vec2(float X, float Y)
HMM_INLINE hmm_vec3 HMM_DivideVec3(hmm_vec3 Left, hmm_vec3 Right)
HMM_INLINE float HMM_LogF(float Float)
HMM_EXTERN float HMM_Power(float Base, int Exponent)
HMM_INLINE hmm_vec3 HMM_AddVec3(hmm_vec3 Left, hmm_vec3 Right)
HMM_INLINE hmm_vec2 HMM_DivideVec2(hmm_vec2 Left, hmm_vec2 Right)
HMM_INLINE hmm_vec4 HMM_Vec4i(int X, int Y, int Z, int W)
HMM_INLINE float HMM_Lerp(float A, float Time, float B)
#define HMM_COSF
HMM_INLINE hmm_bool HMM_EqualsVec2(hmm_vec2 Left, hmm_vec2 Right)
HMM_INLINE float HMM_DotVec4(hmm_vec4 VecOne, hmm_vec4 VecTwo)
HMM_INLINE float HMM_TanF(float Radians)
HMM_EXTERN hmm_mat4 HMM_DivideMat4f(hmm_mat4 Matrix, float Scalar)
HMM_INLINE hmm_vec4 HMM_Vec4(float X, float Y, float Z, float W)
HMM_INLINE float HMM_ATan2F(float Left, float Right)
HMM_INLINE hmm_vec2 HMM_NormalizeVec2(hmm_vec2 A)
HMM_INLINE float HMM_DotQuaternion(hmm_quaternion Left, hmm_quaternion Right)
HMM_INLINE hmm_vec4 HMM_MultiplyVec4f(hmm_vec4 Left, float Right)
HMM_INLINE hmm_vec3 HMM_MultiplyVec3(hmm_vec3 Left, hmm_vec3 Right)
HMM_INLINE hmm_mat4 HMM_Mat4d(float Diagonal)
HMM_INLINE hmm_vec4 HMM_NormalizeVec4(hmm_vec4 A)
HMM_INLINE hmm_vec2 HMM_MultiplyVec2f(hmm_vec2 Left, float Right)
HMM_INLINE hmm_quaternion HMM_DivideQuaternionF(hmm_quaternion Left, float Dividend)
#define HMM_LOGF
HMM_INLINE hmm_vec4 HMM_Vec4v(hmm_vec3 Vector, float W)
HMM_INLINE float HMM_DotVec3(hmm_vec3 VecOne, hmm_vec3 VecTwo)
HMM_INLINE float HMM_LengthVec3(hmm_vec3 A)
HMM_INLINE hmm_mat4 HMM_Perspective(float FOV, float AspectRatio, float Near, float Far)
#define HMM_SINF
HMM_INLINE float HMM_LengthSquaredVec3(hmm_vec3 A)
HMM_INLINE hmm_mat4 HMM_Mat4()
HMM_INLINE hmm_quaternion HMM_Quaternion(float X, float Y, float Z, float W)
HMM_INLINE hmm_quaternion HMM_MultiplyQuaternionF(hmm_quaternion Left, float Multiplicative)
HMM_INLINE hmm_quaternion HMM_SubtractQuaternion(hmm_quaternion Left, hmm_quaternion Right)
HMM_EXTERN hmm_quaternion HMM_QuaternionFromAxisAngle(hmm_vec3 Axis, float AngleOfRotation)
hmm_vec4 hmm_v4
HMM_INLINE hmm_vec2 HMM_AddVec2(hmm_vec2 Left, hmm_vec2 Right)
int32_t hmm_bool
HMM_INLINE float HMM_LengthVec4(hmm_vec4 A)
HMM_INLINE hmm_vec4 HMM_SubtractVec4(hmm_vec4 Left, hmm_vec4 Right)
HMM_EXTERN hmm_mat4 HMM_MultiplyMat4f(hmm_mat4 Matrix, float Scalar)
HMM_INLINE hmm_quaternion HMM_QuaternionV4(hmm_vec4 Vector)
HMM_INLINE float HMM_Clamp(float Min, float Value, float Max)
HMM_INLINE hmm_vec3 HMM_SubtractVec3(hmm_vec3 Left, hmm_vec3 Right)
#define HMM_PI32
HMM_INLINE float HMM_SquareRootF(float Float)
HMM_EXTERN hmm_vec4 HMM_MultiplyMat4ByVec4(hmm_mat4 Matrix, hmm_vec4 Vector)
HMM_EXTERN hmm_mat4 HMM_SubtractMat4(hmm_mat4 Left, hmm_mat4 Right)
HMM_INLINE float HMM_RSquareRootF(float Float)
#define HMM_EXPF
HMM_INLINE float HMM_LengthSquaredVec4(hmm_vec4 A)
HMM_INLINE hmm_vec3 HMM_DivideVec3f(hmm_vec3 Left, float Right)
HMM_INLINE float HMM_PowerF(float Base, float Exponent)
hmm_vec3 hmm_v3
HMM_INLINE float HMM_ATanF(float Radians)
HMM_INLINE hmm_vec2 HMM_DivideVec2f(hmm_vec2 Left, float Right)
HMM_EXTERN hmm_mat4 HMM_Transpose(hmm_mat4 Matrix)
HMM_INLINE hmm_vec4 HMM_MultiplyVec4(hmm_vec4 Left, hmm_vec4 Right)
HMM_INLINE hmm_vec4 HMM_DivideVec4f(hmm_vec4 Left, float Right)
#define HMM_SQRTF
HMM_INLINE hmm_vec4 HMM_AddVec4(hmm_vec4 Left, hmm_vec4 Right)
HMM_INLINE hmm_mat4 HMM_Translate(hmm_vec3 Translation)
HMM_EXTERN hmm_mat4 HMM_QuaternionToMat4(hmm_quaternion Left)
hmm_vec2 hmm_v2
HMM_INLINE float HMM_ACosF(float Radians)
HMM_INLINE hmm_bool HMM_EqualsVec4(hmm_vec4 Left, hmm_vec4 Right)
HMM_INLINE hmm_vec2 HMM_SubtractVec2(hmm_vec2 Left, hmm_vec2 Right)
HMM_EXTERN hmm_quaternion HMM_InverseQuaternion(hmm_quaternion Left)
HMM_INLINE float HMM_SinF(float Radians)
#define HMM_INLINE
HMM_INLINE hmm_quaternion HMM_NLerp(hmm_quaternion Left, float Time, hmm_quaternion Right)
hmm_mat4 hmm_m4
HMM_INLINE hmm_quaternion HMM_AddQuaternion(hmm_quaternion Left, hmm_quaternion Right)
HMM_EXTERN hmm_mat4 HMM_LookAt(hmm_vec3 Eye, hmm_vec3 Center, hmm_vec3 Up)
HMM_INLINE hmm_quaternion HMM_NormalizeQuaternion(hmm_quaternion Left)
#define HMM_EXTERN
HMM_INLINE float HMM_LengthSquaredVec2(hmm_vec2 A)
HMM_EXTERN hmm_quaternion HMM_Slerp(hmm_quaternion Left, float Time, hmm_quaternion Right)
HMM_INLINE hmm_bool HMM_EqualsVec3(hmm_vec3 Left, hmm_vec3 Right)
HMM_INLINE hmm_vec4 HMM_DivideVec4(hmm_vec4 Left, hmm_vec4 Right)
HMM_INLINE hmm_vec3 HMM_Cross(hmm_vec3 VecOne, hmm_vec3 VecTwo)
HMM_INLINE hmm_vec3 HMM_NormalizeVec3(hmm_vec3 A)
HMM_INLINE hmm_vec3 HMM_Vec3i(int X, int Y, int Z)
#define HMM_TANF
HMM_EXTERN hmm_mat4 HMM_MultiplyMat4(hmm_mat4 Left, hmm_mat4 Right)
HMM_INLINE float HMM_ExpF(float Float)
#define HMM_ACOSF
HMM_INLINE hmm_vec3 HMM_Vec3(float X, float Y, float Z)
#define HMM_ATANF
HMM_EXTERN hmm_mat4 HMM_Rotate(float Angle, hmm_vec3 Axis)
HMM_INLINE hmm_mat4 HMM_Scale(hmm_vec3 Scale)
HMM_INLINE hmm_vec2 HMM_Vec2i(int X, int Y)
HMM_EXTERN hmm_mat4 HMM_AddMat4(hmm_mat4 Left, hmm_mat4 Right)
#define HMM_ATAN2F
HMM_INLINE hmm_quaternion HMM_MultiplyQuaternion(hmm_quaternion Left, hmm_quaternion Right)
HMM_INLINE float HMM_CosF(float Radians)
HMM_INLINE float HMM_ToRadians(float Degrees)
HMM_INLINE hmm_vec2 HMM_MultiplyVec2(hmm_vec2 Left, hmm_vec2 Right)
HMM_INLINE float HMM_LengthVec2(hmm_vec2 A)
HMM_INLINE hmm_vec3 HMM_MultiplyVec3f(hmm_vec3 Left, float Right)
HMM_INLINE float HMM_DotVec2(hmm_vec2 VecOne, hmm_vec2 VecTwo)
uint32_t col
Definition RawData.h:4
Definition A.h:16
Definition B.h:16
GLuint64EXT * result
Definition glcorearb.h:5662
auto operator+=(std::string &lhs, StringRef rhs) -> std::string &
MultPolicyGPU< T, R1, R2 >::RepType operator*(const SMatrixGPU< T, D1, D, R1 > &lhs, const SMatrixGPU< T, D, D2, R2 > &rhs)
Definition SMatrixGPU.h:748
Vertex< T > operator-(const Vertex< T > &a, const Vertex< T > &b)
Definition Vertex.h:98
bool operator!=(const observer_ptr< W1 > &p1, const observer_ptr< W2 > &p2)
bool operator==(const CoarseLocation &a, const CoarseLocation &b)
float Elements[4][4]
float Elements[4]
float Elements[2]
float Right
float Width
float Height
hmm_vec2 VW
float Ignored0_
float Ignored3_
hmm_vec2 XY
hmm_vec2 YZ
float Ignored2_
float Elements[3]
hmm_vec2 UV
float Ignored1_
float Ignored4_
float Ignored1_
float Ignored2_
hmm_vec3 RGB
hmm_vec2 ZW
float Elements[4]
float Ignored3_
hmm_vec3 XYZ
hmm_vec2 YZ
hmm_vec2 XY
float Ignored5_
float Ignored0_