Compare commits

..

1 Commits

Author SHA1 Message Date
zak
5d1393e874 Add HMM_STATIC option to statically link instead of extern 2021-02-17 19:30:54 -08:00
5 changed files with 14 additions and 111 deletions

View File

@@ -1,5 +1,5 @@
/* /*
HandmadeMath.h v1.12.1 HandmadeMath.h v1.11.0
This is a single header file with a bunch of useful functions for game and This is a single header file with a bunch of useful functions for game and
graphics math operations. graphics math operations.
@@ -84,7 +84,7 @@
CREDITS CREDITS
Written by Zakary Strange (strangezak@protonmail.com && @strangezak) Written by Zakary Strange (strangezak@gmail.com && @strangezak)
Functionality: Functionality:
Matt Mascarenhas (@miblo_) Matt Mascarenhas (@miblo_)
@@ -217,10 +217,10 @@ extern "C"
#define HMM_PI32 3.14159265359f #define HMM_PI32 3.14159265359f
#define HMM_PI 3.14159265358979323846 #define HMM_PI 3.14159265358979323846
#define HMM_MIN(a, b) ((a) > (b) ? (b) : (a)) #define HMM_MIN(a, b) (a) > (b) ? (b) : (a)
#define HMM_MAX(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_ABS(a) ((a) > 0 ? (a) : -(a))
#define HMM_MOD(a, m) (((a) % (m)) >= 0 ? ((a) % (m)) : (((a) % (m)) + (m))) #define HMM_MOD(a, m) ((a) % (m)) >= 0 ? ((a) % (m)) : (((a) % (m)) + (m))
#define HMM_SQUARE(x) ((x) * (x)) #define HMM_SQUARE(x) ((x) * (x))
#ifndef HMM_PREFIX #ifndef HMM_PREFIX
@@ -2795,46 +2795,6 @@ HMM_INLINE hmm_bool operator!=(hmm_vec4 Left, hmm_vec4 Right)
return !HMM_PREFIX(EqualsVec4)(Left, Right); return !HMM_PREFIX(EqualsVec4)(Left, Right);
} }
COVERAGE(HMM_UnaryMinusVec2, 1)
HMM_INLINE hmm_vec2 operator-(hmm_vec2 In)
{
ASSERT_COVERED(HMM_UnaryMinusVec2);
hmm_vec2 Result;
Result.X = -In.X;
Result.Y = -In.Y;
return(Result);
}
COVERAGE(HMM_UnaryMinusVec3, 1)
HMM_INLINE hmm_vec3 operator-(hmm_vec3 In)
{
ASSERT_COVERED(HMM_UnaryMinusVec3);
hmm_vec3 Result;
Result.X = -In.X;
Result.Y = -In.Y;
Result.Z = -In.Z;
return(Result);
}
COVERAGE(HMM_UnaryMinusVec4, 1)
HMM_INLINE hmm_vec4 operator-(hmm_vec4 In)
{
ASSERT_COVERED(HMM_UnaryMinusVec4);
hmm_vec4 Result;
#if HANDMADE_MATH__USE_SSE
Result.InternalElementsSSE = _mm_xor_ps(In.InternalElementsSSE, _mm_set1_ps(-0.0f));
#else
Result.X = -In.X;
Result.Y = -In.Y;
Result.Z = -In.Z;
Result.W = -In.W;
#endif
return(Result);
}
#endif /* __cplusplus */ #endif /* __cplusplus */
#if defined(__GNUC__) || defined(__clang__) #if defined(__GNUC__) || defined(__clang__)

View File

@@ -10,8 +10,6 @@ To get started, go download [the latest release](https://github.com/HandmadeMath
Version | Changes | Version | Changes |
----------------|----------------| ----------------|----------------|
**1.12.1** | Added extra parentheses around some macros |
**1.12.0** | Added Unary Minus operator for `HMM_Vec2`, `HMM_Vec3`, and `HMM_Vec4`. |
**1.11.1** | Added HMM_PREFIX macro to a few functions that were missing it. | **1.11.1** | Added HMM_PREFIX macro to a few functions that were missing it. |
**1.11.0** | Added ability to customize or remove the default `HMM_` prefix on function names by defining a macro called `HMM_PREFIX(name)`. | **1.11.0** | Added ability to customize or remove the default `HMM_` prefix on function names by defining a macro called `HMM_PREFIX(name)`. |
**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.1** | Removed stdint.h, this doesn't exist on some really old compilers and we didn't really use it anyways. |

View File

@@ -58,7 +58,6 @@
#define HANDMADETEST_H #define HANDMADETEST_H
#include <float.h> #include <float.h>
#include <math.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@@ -153,7 +152,7 @@ INITIALIZER(_HMT_COVERCASE_FUNCNAME_INIT(name)) { \
_HMT_CASE_START(); \ _HMT_CASE_START(); \
float actual = (_actual); \ float actual = (_actual); \
float diff = actual - (_expected); \ float diff = actual - (_expected); \
if (isnan(actual) || diff < -FLT_EPSILON || FLT_EPSILON < diff) { \ if (diff < -FLT_EPSILON || FLT_EPSILON < diff) { \
_HMT_CASE_FAIL(); \ _HMT_CASE_FAIL(); \
printf("Expected %f, got %f", (_expected), actual); \ printf("Expected %f, got %f", (_expected), actual); \
} \ } \
@@ -163,7 +162,7 @@ INITIALIZER(_HMT_COVERCASE_FUNCNAME_INIT(name)) { \
_HMT_CASE_START(); \ _HMT_CASE_START(); \
float actual = (_actual); \ float actual = (_actual); \
float diff = actual - (_expected); \ float diff = actual - (_expected); \
if (isnan(actual) || diff < -(_epsilon) || (_epsilon) < diff) { \ if (diff < -(_epsilon) || (_epsilon) < diff) { \
_HMT_CASE_FAIL(); \ _HMT_CASE_FAIL(); \
printf("Expected %f, got %f", (_expected), actual); \ printf("Expected %f, got %f", (_expected), actual); \
} \ } \

View File

@@ -66,39 +66,14 @@ TEST(QuaternionOps, NLerp)
TEST(QuaternionOps, Slerp) TEST(QuaternionOps, Slerp)
{ {
// Normal operation hmm_quaternion from = HMM_Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
{ hmm_quaternion to = HMM_Quaternion(0.5f, 0.5f, -0.5f, 0.5f);
hmm_quaternion from = HMM_Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
hmm_quaternion to = HMM_Quaternion(0.5f, 0.5f, -0.5f, 0.5f);
hmm_quaternion result = HMM_Slerp(from, 0.5f, to); hmm_quaternion result = HMM_Slerp(from, 0.5f, to);
EXPECT_FLOAT_EQ(result.X, 0.28867513f); EXPECT_FLOAT_EQ(result.X, 0.28867513f);
EXPECT_FLOAT_EQ(result.Y, 0.28867513f); EXPECT_FLOAT_EQ(result.Y, 0.28867513f);
EXPECT_FLOAT_EQ(result.Z, -0.28867513f); EXPECT_FLOAT_EQ(result.Z, -0.28867513f);
EXPECT_FLOAT_EQ(result.W, 0.86602540f); EXPECT_FLOAT_EQ(result.W, 0.86602540f);
}
// Same quat twice
{
hmm_quaternion q = HMM_Quaternion(0.5f, 0.5f, 0.5f, 1.0f);
hmm_quaternion result = HMM_Slerp(q, 0.5f, q);
EXPECT_FLOAT_EQ(result.X, 0.5f);
EXPECT_FLOAT_EQ(result.Y, 0.5f);
EXPECT_FLOAT_EQ(result.Z, 0.5f);
EXPECT_FLOAT_EQ(result.W, 1.0f);
}
// Identity quat twice
{
hmm_quaternion q = HMM_Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
hmm_quaternion result = HMM_Slerp(q, 0.5f, q);
EXPECT_FLOAT_EQ(result.X, 0.0f);
EXPECT_FLOAT_EQ(result.Y, 1.0f);
EXPECT_FLOAT_EQ(result.Z, 0.0f);
EXPECT_FLOAT_EQ(result.W, 1.0f);
}
} }
TEST(QuaternionOps, QuatToMat4) TEST(QuaternionOps, QuatToMat4)

View File

@@ -199,32 +199,3 @@ TEST(Subtraction, Quaternion)
EXPECT_FLOAT_EQ(q1.W, -4.0f); EXPECT_FLOAT_EQ(q1.W, -4.0f);
#endif #endif
} }
#ifdef __cplusplus
TEST(UnaryMinus, Vec2)
{
hmm_vec2 VectorOne = {1.0f, 2.0f};
hmm_vec2 Result = -VectorOne;
EXPECT_FLOAT_EQ(Result.X, -1.0f);
EXPECT_FLOAT_EQ(Result.Y, -2.0f);
}
TEST(UnaryMinus, Vec3)
{
hmm_vec3 VectorOne = {1.0f, 2.0f, 3.0f};
hmm_vec3 Result = -VectorOne;
EXPECT_FLOAT_EQ(Result.X, -1.0f);
EXPECT_FLOAT_EQ(Result.Y, -2.0f);
EXPECT_FLOAT_EQ(Result.Z, -3.0f);
}
TEST(UnaryMinus, Vec4)
{
hmm_vec4 VectorOne = {1.0f, 2.0f, 3.0f, 4.0f};
hmm_vec4 Result = -VectorOne;
EXPECT_FLOAT_EQ(Result.X, -1.0f);
EXPECT_FLOAT_EQ(Result.Y, -2.0f);
EXPECT_FLOAT_EQ(Result.Z, -3.0f);
EXPECT_FLOAT_EQ(Result.W, -4.0f);
}
#endif