From 9d5baac382c6b5e0eb0bef9d84cd170e581c0b27 Mon Sep 17 00:00:00 2001 From: Zakary Strange Date: Sat, 11 Jan 2020 14:16:21 -0800 Subject: [PATCH 1/5] Removed use of stdint.h --- HandmadeMath.h | 6 ++---- README.md | 1 + 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/HandmadeMath.h b/HandmadeMath.h index 792257d..e2ba070 100644 --- a/HandmadeMath.h +++ b/HandmadeMath.h @@ -1,5 +1,5 @@ /* - HandmadeMath.h v1.9.0 + HandmadeMath.h v1.10.1 This is a single header file with a bunch of useful functions for game and graphics math operations. @@ -119,8 +119,6 @@ #endif /* #ifndef HANDMADE_MATH_NO_SSE */ -#include // This is for types - #ifdef HANDMADE_MATH__USE_SSE #include #endif @@ -399,7 +397,7 @@ typedef union hmm_quaternion #endif } hmm_quaternion; -typedef int32_t hmm_bool; +typedef signed int hmm_bool; typedef hmm_vec2 hmm_v2; typedef hmm_vec3 hmm_v3; diff --git a/README.md b/README.md index 062dbb2..f7b8e22 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ To get started, go download [the latest release](https://github.com/HandmadeMath Version | Changes | ----------------|----------------| +**1.10.1** | Removed stdint.h, this doesn't exist on some really old compilers and we didn't really use it anyways. | **1.10.0** | Made HMM_Perspective use vertical FOV instead of horizontal FOV for consistency with other graphics APIs. | **1.9.0** | Added SSE versions of quaternion operations. | **1.8.0** | Added fast vector normalization routines that use fast inverse square roots. From 81659df32d9c7d2268af1dc6d02401bf04fac15c Mon Sep 17 00:00:00 2001 From: Zakary Strange Date: Sat, 11 Jan 2020 18:56:15 -0800 Subject: [PATCH 2/5] SSE HMM_EqualsVec4 --- HandmadeMath.h | 8 +++++++- README.md | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/HandmadeMath.h b/HandmadeMath.h index e2ba070..c85b5b0 100644 --- a/HandmadeMath.h +++ b/HandmadeMath.h @@ -1002,8 +1002,14 @@ COVERAGE(HMM_EqualsVec4, 1) HMM_INLINE hmm_bool HMM_EqualsVec4(hmm_vec4 Left, hmm_vec4 Right) { ASSERT_COVERED(HMM_EqualsVec4); + + hmm_bool Result; - hmm_bool Result = (Left.X == Right.X && Left.Y == Right.Y && Left.Z == Right.Z && Left.W == Right.W); +#if HANDMADE_MATH__USE_SSE + Result = _mm_movemask_ps(_mm_cmpeq_ps(Left.InternalElementsSSE, Right.InternalElementsSSE)) == 0xF ? 1 : 0; +#else + Result = (Left.X == Right.X && Left.Y == Right.Y && Left.Z == Right.Z && Left.W == Right.W); +#endif return (Result); } diff --git a/README.md b/README.md index f7b8e22..c9372c7 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,8 @@ To get started, go download [the latest release](https://github.com/HandmadeMath Version | Changes | ----------------|----------------| -**1.10.1** | Removed stdint.h, this doesn't exist on some really old compilers and we didn't really use it anyways. | +**1.10.2** | Introduced safe floating point comparrision in HMM_EqualsVec2, HMM_EqualsVec3, HMM_EqualsVec4. | +**1.10.1** | Removed use of stdint.h, this doesn't exist on some really old compilers and we didn't really use it anyways. | **1.10.0** | Made HMM_Perspective use vertical FOV instead of horizontal FOV for consistency with other graphics APIs. | **1.9.0** | Added SSE versions of quaternion operations. | **1.8.0** | Added fast vector normalization routines that use fast inverse square roots. From f925f83683c4d75591ceb66399580198aa35f301 Mon Sep 17 00:00:00 2001 From: Zakary Strange Date: Sat, 11 Jan 2020 20:05:19 -0800 Subject: [PATCH 3/5] Fixed floating point comparision, and SIMD'd hmm_vec4 comparison --- HandmadeMath.h | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/HandmadeMath.h b/HandmadeMath.h index c85b5b0..e309ba7 100644 --- a/HandmadeMath.h +++ b/HandmadeMath.h @@ -150,7 +150,7 @@ extern "C" #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) + !defined(HMM_ACOSF) || !defined(HMM_ATANF)|| !defined(HMM_ATAN2F) || !defined(HMM_FABS) #include #endif @@ -190,8 +190,13 @@ extern "C" #define HMM_ATAN2F atan2f #endif +#ifndef HMM_FABS +#define HMM_FABS fabs +#endif + #define HMM_PI32 3.14159265359f #define HMM_PI 3.14159265358979323846 +#define HMM_FLOAT_EPSILON 1.19209290E-07F #define HMM_MIN(a, b) (a) > (b) ? (b) : (a) #define HMM_MAX(a, b) (a) < (b) ? (b) : (a) @@ -489,6 +494,12 @@ HMM_INLINE float HMM_LogF(float Float) return (Result); } +HMM_INLINE float HMM_FAbs(float Float) +{ + float Result = HMM_FABS(Float); + return(Result); +} + COVERAGE(HMM_SquareRootF, 1) HMM_INLINE float HMM_SquareRootF(float Float) { @@ -978,12 +989,17 @@ HMM_INLINE hmm_vec4 HMM_DivideVec4f(hmm_vec4 Left, float Right) return (Result); } +HMM_INLINE hmm_bool HMM_AreFloatsSame(float InputOne, float InputTwo) +{ + return(HMM_FAbs(InputOne - InputTwo) < HMM_FLOAT_EPSILON); +} + COVERAGE(HMM_EqualsVec2, 1) HMM_INLINE hmm_bool HMM_EqualsVec2(hmm_vec2 Left, hmm_vec2 Right) { ASSERT_COVERED(HMM_EqualsVec2); - hmm_bool Result = (Left.X == Right.X && Left.Y == Right.Y); + hmm_bool Result = (HMM_AreFloatsSame(Left.X, Right.X) && HMM_AreFloatsSame(Left.Y, Right.Y)); return (Result); } @@ -993,7 +1009,7 @@ HMM_INLINE hmm_bool HMM_EqualsVec3(hmm_vec3 Left, hmm_vec3 Right) { ASSERT_COVERED(HMM_EqualsVec3); - hmm_bool Result = (Left.X == Right.X && Left.Y == Right.Y && Left.Z == Right.Z); + hmm_bool Result = (HMM_AreFloatsSame(Left.X, Right.X) && HMM_AreFloatsSame(Left.Y, Right.Y) && HMM_AreFloatsSame(Left.Z, Right.Z)); return (Result); } From 69f8a3891232d4101fce67d7b339777cef74438a Mon Sep 17 00:00:00 2001 From: Zakary Strange Date: Sat, 11 Jan 2020 20:15:17 -0800 Subject: [PATCH 4/5] Updated docs, and fixed non-simd'd HMM_EqualsVec4 --- HandmadeMath.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/HandmadeMath.h b/HandmadeMath.h index e309ba7..b040425 100644 --- a/HandmadeMath.h +++ b/HandmadeMath.h @@ -44,6 +44,7 @@ #define HMM_ACOSF MyACosF #define HMM_ATANF MyATanF #define HMM_ATAN2F MYATan2F + #define HMM_FABS MyFAbs 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, @@ -58,6 +59,7 @@ #define HMM_ACOSF MyACosF #define HMM_ATANF MyATanF #define HMM_ATAN2F MyATan2F + #define HMM_FABS MyFAbs #define HANDMADE_MATH_IMPLEMENTATION #include "HandmadeMath.h" @@ -1024,7 +1026,7 @@ HMM_INLINE hmm_bool HMM_EqualsVec4(hmm_vec4 Left, hmm_vec4 Right) #if HANDMADE_MATH__USE_SSE Result = _mm_movemask_ps(_mm_cmpeq_ps(Left.InternalElementsSSE, Right.InternalElementsSSE)) == 0xF ? 1 : 0; #else - Result = (Left.X == Right.X && Left.Y == Right.Y && Left.Z == Right.Z && Left.W == Right.W); + Result = (HMM_AreFloatsSame(Left.X, Right.X) && HMM_AreFloatsSame(Left.Y, Right.Y) && HMM_AreFloatsSame(Left.Z, Right.Z) && HMM_AreFloatsSame(Left.W, Right.W)); #endif return (Result); From ea6ab8e64eceda4fab2cbdc313a4ed030f21735e Mon Sep 17 00:00:00 2001 From: Zakary Strange Date: Sat, 11 Jan 2020 20:25:14 -0800 Subject: [PATCH 5/5] Cleaned up styling in hmm_mat4 operator[] --- HandmadeMath.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/HandmadeMath.h b/HandmadeMath.h index b040425..93b0578 100644 --- a/HandmadeMath.h +++ b/HandmadeMath.h @@ -1,5 +1,5 @@ /* - HandmadeMath.h v1.10.1 + HandmadeMath.h v1.10.3 This is a single header file with a bunch of useful functions for game and graphics math operations. @@ -76,7 +76,7 @@ CREDITS - Written by Zakary Strange (zak@strangedev.net && @strangezak) + Written by Zakary Strange (zakarystrange@gmail.net && @strangezak) Functionality: Matt Mascarenhas (@miblo_) @@ -368,15 +368,15 @@ typedef union hmm_mat4 #ifdef __cplusplus inline hmm_vec4 operator[](const int &Index) { - float* col = Elements[Index]; + float* Column = Elements[Index]; - hmm_vec4 result; - result.Elements[0] = col[0]; - result.Elements[1] = col[1]; - result.Elements[2] = col[2]; - result.Elements[3] = col[3]; + hmm_vec4 Result; + Result.Elements[0] = Column[0]; + Result.Elements[1] = Column[1]; + Result.Elements[2] = Column[2]; + Result.Elements[3] = Column[3]; - return result; + return Result; } #endif } hmm_mat4;