mirror of
https://github.com/HandmadeMath/HandmadeMath.git
synced 2025-12-30 16:32:02 +00:00
Compare commits
12 Commits
2-dev
...
full_inlin
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e88b625a31 | ||
|
|
9f6ddd6039 | ||
|
|
8c18186b3b | ||
|
|
5f816bf9b3 | ||
|
|
c5bc802042 | ||
|
|
43afc87fa7 | ||
|
|
5bbac2167e | ||
|
|
655c662528 | ||
|
|
1f0c6ba493 | ||
|
|
1d82b4f0bc | ||
|
|
2fa0b36715 | ||
|
|
ad169e649c |
@@ -1,6 +1,8 @@
|
|||||||
# Understanding the structure of Handmade Math
|
# Understanding the structure of Handmade Math
|
||||||
|
|
||||||
Most of the functions in Handmade Math are very short, and all are the kind of functions you want to be easily inlined for performance. Because of this, all functions in Handmade Math are defined with `HMM_INLINE`, which is defined as `static inline`.
|
Most of the functions in Handmade Math are very short, and are the kind of functions you want to have inlined. Because of this, most functions in Handmade Math are defined with `HINLINE`, which is defined as `static inline`.
|
||||||
|
|
||||||
|
The exceptions are functions like `HMM_Rotate`, which are long enough that it doesn't make sense to inline them. These functions are defined with an `HEXTERN` prototype, and implemented in the `#ifdef HANDMADE_MATH_IMPLEMENTATION` block.
|
||||||
|
|
||||||
# Quick style guide
|
# Quick style guide
|
||||||
|
|
||||||
|
|||||||
186
HandmadeMath.h
186
HandmadeMath.h
@@ -1,18 +1,17 @@
|
|||||||
/*
|
/*
|
||||||
HandmadeMath.h v1.11.0
|
HandmadeMath.h v1.13.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.
|
||||||
|
|
||||||
All angles are in radians.
|
|
||||||
|
|
||||||
=============================================================================
|
=============================================================================
|
||||||
|
|
||||||
To disable SSE intrinsics, you MUST
|
To disable SSE intrinsics, you MUST
|
||||||
|
|
||||||
#define HANDMADE_MATH_NO_SSE
|
#define HANDMADE_MATH_NO_SSE
|
||||||
|
|
||||||
BEFORE the include, like this:
|
in EXACTLY one C or C++ file that includes this header, BEFORE the
|
||||||
|
include, like this:
|
||||||
|
|
||||||
#define HANDMADE_MATH_NO_SSE
|
#define HANDMADE_MATH_NO_SSE
|
||||||
#include "HandmadeMath.h"
|
#include "HandmadeMath.h"
|
||||||
@@ -42,7 +41,8 @@
|
|||||||
#define HMM_ATAN2F MYATan2F
|
#define HMM_ATAN2F MYATan2F
|
||||||
|
|
||||||
Provide your own implementations of SinF, CosF, TanF, ACosF, ATanF, ATan2F,
|
Provide your own implementations of SinF, CosF, TanF, ACosF, ATanF, ATan2F,
|
||||||
ExpF, and LogF BEFORE the include, like this:
|
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_SINF MySinF
|
||||||
#define HMM_COSF MyCosF
|
#define HMM_COSF MyCosF
|
||||||
@@ -68,15 +68,14 @@
|
|||||||
|
|
||||||
CREDITS
|
CREDITS
|
||||||
|
|
||||||
Written by:
|
Written by Zakary Strange (strangezak@protonmail.com && @strangezak)
|
||||||
Zakary Strange (zakarystrange@gmail.com && @strangezak)
|
|
||||||
Ben Visness (ben@bvisness.me && @its_bvisness)
|
|
||||||
|
|
||||||
Functionality:
|
Functionality:
|
||||||
Matt Mascarenhas (@miblo_)
|
Matt Mascarenhas (@miblo_)
|
||||||
Aleph
|
Aleph
|
||||||
FieryDrake (@fierydrake)
|
FieryDrake (@fierydrake)
|
||||||
Gingerbill (@TheGingerBill)
|
Gingerbill (@TheGingerBill)
|
||||||
|
Ben Visness (@bvisness)
|
||||||
Trinton Bullard (@Peliex_Dev)
|
Trinton Bullard (@Peliex_Dev)
|
||||||
@AntonDan
|
@AntonDan
|
||||||
|
|
||||||
@@ -128,11 +127,12 @@
|
|||||||
#if defined(__GNUC__) || defined(__clang__)
|
#if defined(__GNUC__) || defined(__clang__)
|
||||||
#pragma GCC diagnostic push
|
#pragma GCC diagnostic push
|
||||||
#pragma GCC diagnostic ignored "-Wfloat-equal"
|
#pragma GCC diagnostic ignored "-Wfloat-equal"
|
||||||
#if defined(__GNUC__) && (__GNUC__ == 4 && __GNUC_MINOR__ < 8)
|
#if (defined(__GNUC__) && (__GNUC__ == 4 && __GNUC_MINOR__ < 8)) || defined(__clang__)
|
||||||
#pragma GCC diagnostic ignored "-Wmissing-braces"
|
#pragma GCC diagnostic ignored "-Wmissing-braces"
|
||||||
#endif
|
#endif
|
||||||
#ifdef __clang__
|
#ifdef __clang__
|
||||||
#pragma GCC diagnostic ignored "-Wgnu-anonymous-struct"
|
#pragma GCC diagnostic ignored "-Wgnu-anonymous-struct"
|
||||||
|
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -196,10 +196,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
|
||||||
@@ -367,15 +367,16 @@ typedef union hmm_mat4
|
|||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
inline hmm_vec4 operator[](const int &Index)
|
inline hmm_vec4 operator[](const int &Index)
|
||||||
{
|
{
|
||||||
float* col = Elements[Index];
|
hmm_vec4 Result;
|
||||||
|
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];
|
|
||||||
|
|
||||||
return result;
|
Result.Elements[0] = Column[0];
|
||||||
|
Result.Elements[1] = Column[1];
|
||||||
|
Result.Elements[2] = Column[2];
|
||||||
|
Result.Elements[3] = Column[3];
|
||||||
|
|
||||||
|
return Result;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
} hmm_mat4;
|
} hmm_mat4;
|
||||||
@@ -570,16 +571,6 @@ HMM_INLINE float HMM_PREFIX(PowerF)(float Base, float Exponent)
|
|||||||
* Utility functions
|
* Utility functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
COVERAGE(HMM_ToDegrees, 1)
|
|
||||||
HMM_INLINE float HMM_ToDegrees(float Radians)
|
|
||||||
{
|
|
||||||
ASSERT_COVERED(HMM_ToDegrees);
|
|
||||||
|
|
||||||
float Result = Radians * (180.0f / HMM_PI32);
|
|
||||||
|
|
||||||
return (Result);
|
|
||||||
}
|
|
||||||
|
|
||||||
COVERAGE(HMM_ToRadians, 1)
|
COVERAGE(HMM_ToRadians, 1)
|
||||||
HMM_INLINE float HMM_PREFIX(ToRadians)(float Degrees)
|
HMM_INLINE float HMM_PREFIX(ToRadians)(float Degrees)
|
||||||
{
|
{
|
||||||
@@ -611,7 +602,8 @@ HMM_INLINE float HMM_PREFIX(Clamp)(float Min, float Value, float Max)
|
|||||||
{
|
{
|
||||||
Result = Min;
|
Result = Min;
|
||||||
}
|
}
|
||||||
else if(Result > Max)
|
|
||||||
|
if(Result > Max)
|
||||||
{
|
{
|
||||||
Result = Max;
|
Result = Max;
|
||||||
}
|
}
|
||||||
@@ -1322,15 +1314,11 @@ HMM_INLINE hmm_mat4 HMM_PREFIX(Transpose)(hmm_mat4 Matrix)
|
|||||||
{
|
{
|
||||||
ASSERT_COVERED(HMM_Transpose);
|
ASSERT_COVERED(HMM_Transpose);
|
||||||
|
|
||||||
#ifdef HANDMADE_MATH__USE_SSE
|
|
||||||
hmm_mat4 Result = Matrix;
|
hmm_mat4 Result = Matrix;
|
||||||
|
|
||||||
|
#ifdef HANDMADE_MATH__USE_SSE
|
||||||
_MM_TRANSPOSE4_PS(Result.Columns[0], Result.Columns[1], Result.Columns[2], Result.Columns[3]);
|
_MM_TRANSPOSE4_PS(Result.Columns[0], Result.Columns[1], Result.Columns[2], Result.Columns[3]);
|
||||||
|
|
||||||
return (Result);
|
|
||||||
#else
|
#else
|
||||||
hmm_mat4 Result;
|
|
||||||
|
|
||||||
int Columns;
|
int Columns;
|
||||||
for(Columns = 0; Columns < 4; ++Columns)
|
for(Columns = 0; Columns < 4; ++Columns)
|
||||||
{
|
{
|
||||||
@@ -1340,9 +1328,10 @@ HMM_INLINE hmm_mat4 HMM_PREFIX(Transpose)(hmm_mat4 Matrix)
|
|||||||
Result.Elements[Rows][Columns] = Matrix.Elements[Columns][Rows];
|
Result.Elements[Rows][Columns] = Matrix.Elements[Columns][Rows];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
return (Result);
|
return (Result);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
COVERAGE(HMM_AddMat4, 1)
|
COVERAGE(HMM_AddMat4, 1)
|
||||||
@@ -1350,19 +1339,15 @@ HMM_INLINE hmm_mat4 HMM_PREFIX(AddMat4)(hmm_mat4 Left, hmm_mat4 Right)
|
|||||||
{
|
{
|
||||||
ASSERT_COVERED(HMM_AddMat4);
|
ASSERT_COVERED(HMM_AddMat4);
|
||||||
|
|
||||||
#ifdef HANDMADE_MATH__USE_SSE
|
|
||||||
hmm_mat4 Result;
|
hmm_mat4 Result;
|
||||||
|
|
||||||
|
#ifdef HANDMADE_MATH__USE_SSE
|
||||||
Result.Columns[0] = _mm_add_ps(Left.Columns[0], Right.Columns[0]);
|
Result.Columns[0] = _mm_add_ps(Left.Columns[0], Right.Columns[0]);
|
||||||
Result.Columns[1] = _mm_add_ps(Left.Columns[1], Right.Columns[1]);
|
Result.Columns[1] = _mm_add_ps(Left.Columns[1], Right.Columns[1]);
|
||||||
Result.Columns[2] = _mm_add_ps(Left.Columns[2], Right.Columns[2]);
|
Result.Columns[2] = _mm_add_ps(Left.Columns[2], Right.Columns[2]);
|
||||||
Result.Columns[3] = _mm_add_ps(Left.Columns[3], Right.Columns[3]);
|
Result.Columns[3] = _mm_add_ps(Left.Columns[3], Right.Columns[3]);
|
||||||
|
|
||||||
return (Result);
|
|
||||||
#else
|
#else
|
||||||
hmm_mat4 Result;
|
int Columns;
|
||||||
|
|
||||||
int Columns;
|
|
||||||
for(Columns = 0; Columns < 4; ++Columns)
|
for(Columns = 0; Columns < 4; ++Columns)
|
||||||
{
|
{
|
||||||
int Rows;
|
int Rows;
|
||||||
@@ -1371,9 +1356,10 @@ HMM_INLINE hmm_mat4 HMM_PREFIX(AddMat4)(hmm_mat4 Left, hmm_mat4 Right)
|
|||||||
Result.Elements[Columns][Rows] = Left.Elements[Columns][Rows] + Right.Elements[Columns][Rows];
|
Result.Elements[Columns][Rows] = Left.Elements[Columns][Rows] + Right.Elements[Columns][Rows];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
return (Result);
|
return (Result);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
COVERAGE(HMM_SubtractMat4, 1)
|
COVERAGE(HMM_SubtractMat4, 1)
|
||||||
@@ -1381,18 +1367,14 @@ HMM_INLINE hmm_mat4 HMM_PREFIX(SubtractMat4)(hmm_mat4 Left, hmm_mat4 Right)
|
|||||||
{
|
{
|
||||||
ASSERT_COVERED(HMM_SubtractMat4);
|
ASSERT_COVERED(HMM_SubtractMat4);
|
||||||
|
|
||||||
#ifdef HANDMADE_MATH__USE_SSE
|
|
||||||
hmm_mat4 Result;
|
hmm_mat4 Result;
|
||||||
|
|
||||||
|
#ifdef HANDMADE_MATH__USE_SSE
|
||||||
Result.Columns[0] = _mm_sub_ps(Left.Columns[0], Right.Columns[0]);
|
Result.Columns[0] = _mm_sub_ps(Left.Columns[0], Right.Columns[0]);
|
||||||
Result.Columns[1] = _mm_sub_ps(Left.Columns[1], Right.Columns[1]);
|
Result.Columns[1] = _mm_sub_ps(Left.Columns[1], Right.Columns[1]);
|
||||||
Result.Columns[2] = _mm_sub_ps(Left.Columns[2], Right.Columns[2]);
|
Result.Columns[2] = _mm_sub_ps(Left.Columns[2], Right.Columns[2]);
|
||||||
Result.Columns[3] = _mm_sub_ps(Left.Columns[3], Right.Columns[3]);
|
Result.Columns[3] = _mm_sub_ps(Left.Columns[3], Right.Columns[3]);
|
||||||
|
|
||||||
return (Result);
|
|
||||||
#else
|
#else
|
||||||
hmm_mat4 Result;
|
|
||||||
|
|
||||||
int Columns;
|
int Columns;
|
||||||
for(Columns = 0; Columns < 4; ++Columns)
|
for(Columns = 0; Columns < 4; ++Columns)
|
||||||
{
|
{
|
||||||
@@ -1402,9 +1384,9 @@ HMM_INLINE hmm_mat4 HMM_PREFIX(SubtractMat4)(hmm_mat4 Left, hmm_mat4 Right)
|
|||||||
Result.Elements[Columns][Rows] = Left.Elements[Columns][Rows] - Right.Elements[Columns][Rows];
|
Result.Elements[Columns][Rows] = Left.Elements[Columns][Rows] - Right.Elements[Columns][Rows];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return (Result);
|
return (Result);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
COVERAGE(HMM_MultiplyMat4, 1)
|
COVERAGE(HMM_MultiplyMat4, 1)
|
||||||
@@ -1441,24 +1423,21 @@ HMM_INLINE hmm_mat4 HMM_PREFIX(MultiplyMat4)(hmm_mat4 Left, hmm_mat4 Right)
|
|||||||
return (Result);
|
return (Result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
COVERAGE(HMM_MultiplyMat4f, 1)
|
COVERAGE(HMM_MultiplyMat4f, 1)
|
||||||
HMM_INLINE hmm_mat4 HMM_PREFIX(MultiplyMat4f)(hmm_mat4 Matrix, float Scalar)
|
HMM_INLINE hmm_mat4 HMM_PREFIX(MultiplyMat4f)(hmm_mat4 Matrix, float Scalar)
|
||||||
{
|
{
|
||||||
ASSERT_COVERED(HMM_MultiplyMat4f);
|
ASSERT_COVERED(HMM_MultiplyMat4f);
|
||||||
|
|
||||||
#ifdef HANDMADE_MATH__USE_SSE
|
|
||||||
hmm_mat4 Result;
|
hmm_mat4 Result;
|
||||||
|
|
||||||
|
#ifdef HANDMADE_MATH__USE_SSE
|
||||||
__m128 SSEScalar = _mm_set1_ps(Scalar);
|
__m128 SSEScalar = _mm_set1_ps(Scalar);
|
||||||
Result.Columns[0] = _mm_mul_ps(Matrix.Columns[0], SSEScalar);
|
Result.Columns[0] = _mm_mul_ps(Matrix.Columns[0], SSEScalar);
|
||||||
Result.Columns[1] = _mm_mul_ps(Matrix.Columns[1], SSEScalar);
|
Result.Columns[1] = _mm_mul_ps(Matrix.Columns[1], SSEScalar);
|
||||||
Result.Columns[2] = _mm_mul_ps(Matrix.Columns[2], SSEScalar);
|
Result.Columns[2] = _mm_mul_ps(Matrix.Columns[2], SSEScalar);
|
||||||
Result.Columns[3] = _mm_mul_ps(Matrix.Columns[3], SSEScalar);
|
Result.Columns[3] = _mm_mul_ps(Matrix.Columns[3], SSEScalar);
|
||||||
|
|
||||||
return (Result);
|
|
||||||
#else
|
#else
|
||||||
hmm_mat4 Result;
|
|
||||||
|
|
||||||
int Columns;
|
int Columns;
|
||||||
for(Columns = 0; Columns < 4; ++Columns)
|
for(Columns = 0; Columns < 4; ++Columns)
|
||||||
{
|
{
|
||||||
@@ -1468,9 +1447,9 @@ HMM_INLINE hmm_mat4 HMM_PREFIX(MultiplyMat4f)(hmm_mat4 Matrix, float Scalar)
|
|||||||
Result.Elements[Columns][Rows] = Matrix.Elements[Columns][Rows] * Scalar;
|
Result.Elements[Columns][Rows] = Matrix.Elements[Columns][Rows] * Scalar;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return (Result);
|
return (Result);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
COVERAGE(HMM_MultiplyMat4ByVec4, 1)
|
COVERAGE(HMM_MultiplyMat4ByVec4, 1)
|
||||||
@@ -1499,24 +1478,21 @@ HMM_INLINE hmm_vec4 HMM_PREFIX(MultiplyMat4ByVec4)(hmm_mat4 Matrix, hmm_vec4 Vec
|
|||||||
return (Result);
|
return (Result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
COVERAGE(HMM_DivideMat4f, 1)
|
COVERAGE(HMM_DivideMat4f, 1)
|
||||||
HMM_INLINE hmm_mat4 HMM_PREFIX(DivideMat4f)(hmm_mat4 Matrix, float Scalar)
|
HMM_INLINE hmm_mat4 HMM_PREFIX(DivideMat4f)(hmm_mat4 Matrix, float Scalar)
|
||||||
{
|
{
|
||||||
ASSERT_COVERED(HMM_DivideMat4f);
|
ASSERT_COVERED(HMM_DivideMat4f);
|
||||||
|
|
||||||
#ifdef HANDMADE_MATH__USE_SSE
|
|
||||||
hmm_mat4 Result;
|
hmm_mat4 Result;
|
||||||
|
|
||||||
|
#ifdef HANDMADE_MATH__USE_SSE
|
||||||
__m128 SSEScalar = _mm_set1_ps(Scalar);
|
__m128 SSEScalar = _mm_set1_ps(Scalar);
|
||||||
Result.Columns[0] = _mm_div_ps(Matrix.Columns[0], SSEScalar);
|
Result.Columns[0] = _mm_div_ps(Matrix.Columns[0], SSEScalar);
|
||||||
Result.Columns[1] = _mm_div_ps(Matrix.Columns[1], SSEScalar);
|
Result.Columns[1] = _mm_div_ps(Matrix.Columns[1], SSEScalar);
|
||||||
Result.Columns[2] = _mm_div_ps(Matrix.Columns[2], SSEScalar);
|
Result.Columns[2] = _mm_div_ps(Matrix.Columns[2], SSEScalar);
|
||||||
Result.Columns[3] = _mm_div_ps(Matrix.Columns[3], SSEScalar);
|
Result.Columns[3] = _mm_div_ps(Matrix.Columns[3], SSEScalar);
|
||||||
|
|
||||||
return (Result);
|
|
||||||
#else
|
#else
|
||||||
hmm_mat4 Result;
|
|
||||||
|
|
||||||
int Columns;
|
int Columns;
|
||||||
for(Columns = 0; Columns < 4; ++Columns)
|
for(Columns = 0; Columns < 4; ++Columns)
|
||||||
{
|
{
|
||||||
@@ -1526,12 +1502,11 @@ HMM_INLINE hmm_mat4 HMM_PREFIX(DivideMat4f)(hmm_mat4 Matrix, float Scalar)
|
|||||||
Result.Elements[Columns][Rows] = Matrix.Elements[Columns][Rows] / Scalar;
|
Result.Elements[Columns][Rows] = Matrix.Elements[Columns][Rows] / Scalar;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return (Result);
|
return (Result);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Common graphics transformations
|
* Common graphics transformations
|
||||||
*/
|
*/
|
||||||
@@ -1556,7 +1531,7 @@ HMM_INLINE hmm_mat4 HMM_PREFIX(Orthographic)(float Left, float Right, float Bott
|
|||||||
}
|
}
|
||||||
|
|
||||||
COVERAGE(HMM_Perspective, 1)
|
COVERAGE(HMM_Perspective, 1)
|
||||||
HMM_INLINE hmm_mat4 HMM_PREFIX(Perspective)(float FOVRadians, float AspectRatio, float Near, float Far)
|
HMM_INLINE hmm_mat4 HMM_PREFIX(Perspective)(float FOV, float AspectRatio, float Near, float Far)
|
||||||
{
|
{
|
||||||
ASSERT_COVERED(HMM_Perspective);
|
ASSERT_COVERED(HMM_Perspective);
|
||||||
|
|
||||||
@@ -1564,7 +1539,7 @@ HMM_INLINE hmm_mat4 HMM_PREFIX(Perspective)(float FOVRadians, float AspectRatio,
|
|||||||
|
|
||||||
// See https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/gluPerspective.xml
|
// See https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/gluPerspective.xml
|
||||||
|
|
||||||
float Cotangent = 1.0f / HMM_PREFIX(TanF)(FOVRadians / 2.0f);
|
float Cotangent = 1.0f / HMM_PREFIX(TanF)(FOV * (HMM_PI32 / 360.0f));
|
||||||
|
|
||||||
Result.Elements[0][0] = Cotangent / AspectRatio;
|
Result.Elements[0][0] = Cotangent / AspectRatio;
|
||||||
Result.Elements[1][1] = Cotangent;
|
Result.Elements[1][1] = Cotangent;
|
||||||
@@ -1591,7 +1566,7 @@ HMM_INLINE hmm_mat4 HMM_PREFIX(Translate)(hmm_vec3 Translation)
|
|||||||
}
|
}
|
||||||
|
|
||||||
COVERAGE(HMM_Rotate, 1)
|
COVERAGE(HMM_Rotate, 1)
|
||||||
HMM_INLINE hmm_mat4 HMM_PREFIX(Rotate)(float AngleRadians, hmm_vec3 Axis)
|
HMM_INLINE hmm_mat4 HMM_PREFIX(Rotate)(float Angle, hmm_vec3 Axis)
|
||||||
{
|
{
|
||||||
ASSERT_COVERED(HMM_Rotate);
|
ASSERT_COVERED(HMM_Rotate);
|
||||||
|
|
||||||
@@ -1599,8 +1574,8 @@ HMM_INLINE hmm_mat4 HMM_PREFIX(Rotate)(float AngleRadians, hmm_vec3 Axis)
|
|||||||
|
|
||||||
Axis = HMM_PREFIX(NormalizeVec3)(Axis);
|
Axis = HMM_PREFIX(NormalizeVec3)(Axis);
|
||||||
|
|
||||||
float SinTheta = HMM_PREFIX(SinF)(AngleRadians);
|
float SinTheta = HMM_PREFIX(SinF)(HMM_PREFIX(ToRadians)(Angle));
|
||||||
float CosTheta = HMM_PREFIX(CosF)(AngleRadians);
|
float CosTheta = HMM_PREFIX(CosF)(HMM_PREFIX(ToRadians)(Angle));
|
||||||
float CosValue = 1.0f - CosTheta;
|
float CosValue = 1.0f - CosTheta;
|
||||||
|
|
||||||
Result.Elements[0][0] = (Axis.X * Axis.X * CosValue) + CosTheta;
|
Result.Elements[0][0] = (Axis.X * Axis.X * CosValue) + CosTheta;
|
||||||
@@ -1618,6 +1593,8 @@ HMM_INLINE hmm_mat4 HMM_PREFIX(Rotate)(float AngleRadians, hmm_vec3 Axis)
|
|||||||
return (Result);
|
return (Result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
COVERAGE(HMM_Scale, 1)
|
COVERAGE(HMM_Scale, 1)
|
||||||
HMM_INLINE hmm_mat4 HMM_PREFIX(Scale)(hmm_vec3 Scale)
|
HMM_INLINE hmm_mat4 HMM_PREFIX(Scale)(hmm_vec3 Scale)
|
||||||
{
|
{
|
||||||
@@ -1666,7 +1643,6 @@ HMM_INLINE hmm_mat4 HMM_PREFIX(LookAt)(hmm_vec3 Eye, hmm_vec3 Center, hmm_vec3 U
|
|||||||
return (Result);
|
return (Result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Quaternion operations
|
* Quaternion operations
|
||||||
*/
|
*/
|
||||||
@@ -1843,29 +1819,25 @@ HMM_INLINE float HMM_PREFIX(DotQuaternion)(hmm_quaternion Left, hmm_quaternion R
|
|||||||
return (Result);
|
return (Result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
COVERAGE(HMM_InverseQuaternion, 1)
|
COVERAGE(HMM_InverseQuaternion, 1)
|
||||||
HMM_INLINE hmm_quaternion HMM_InverseQuaternion(hmm_quaternion Left)
|
HMM_INLINE hmm_quaternion HMM_PREFIX(InverseQuaternion)(hmm_quaternion Left)
|
||||||
{
|
{
|
||||||
ASSERT_COVERED(HMM_InverseQuaternion);
|
ASSERT_COVERED(HMM_InverseQuaternion);
|
||||||
|
|
||||||
hmm_quaternion Conjugate;
|
|
||||||
hmm_quaternion Result;
|
hmm_quaternion Result;
|
||||||
float Norm = 0;
|
|
||||||
float NormSquared = 0;
|
|
||||||
|
|
||||||
Conjugate.X = -Left.X;
|
Result.X = -Left.X;
|
||||||
Conjugate.Y = -Left.Y;
|
Result.Y = -Left.Y;
|
||||||
Conjugate.Z = -Left.Z;
|
Result.Z = -Left.Z;
|
||||||
Conjugate.W = Left.W;
|
Result.W = Left.W;
|
||||||
|
|
||||||
Norm = HMM_PREFIX(SquareRootF)(HMM_PREFIX(DotQuaternion)(Left, Left));
|
Result = HMM_PREFIX(DivideQuaternionF)(Result, (HMM_PREFIX(DotQuaternion)(Left, Left)));
|
||||||
NormSquared = Norm * Norm;
|
|
||||||
|
|
||||||
Result = HMM_PREFIX(DivideQuaternionF)(Conjugate, NormSquared);
|
|
||||||
|
|
||||||
return (Result);
|
return (Result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
COVERAGE(HMM_NormalizeQuaternion, 1)
|
COVERAGE(HMM_NormalizeQuaternion, 1)
|
||||||
HMM_INLINE hmm_quaternion HMM_PREFIX(NormalizeQuaternion)(hmm_quaternion Left)
|
HMM_INLINE hmm_quaternion HMM_PREFIX(NormalizeQuaternion)(hmm_quaternion Left)
|
||||||
{
|
{
|
||||||
@@ -1929,7 +1901,7 @@ HMM_INLINE hmm_quaternion HMM_PREFIX(Slerp)(hmm_quaternion Left, float Time, hmm
|
|||||||
}
|
}
|
||||||
|
|
||||||
COVERAGE(HMM_QuaternionToMat4, 1)
|
COVERAGE(HMM_QuaternionToMat4, 1)
|
||||||
HMM_INLINE hmm_mat4 HMM_QuaternionToMat4(hmm_quaternion Left)
|
HMM_INLINE hmm_mat4 HMM_PREFIX(QuaternionToMat4)(hmm_quaternion Left)
|
||||||
{
|
{
|
||||||
ASSERT_COVERED(HMM_QuaternionToMat4);
|
ASSERT_COVERED(HMM_QuaternionToMat4);
|
||||||
|
|
||||||
@@ -1989,7 +1961,7 @@ HMM_INLINE hmm_mat4 HMM_QuaternionToMat4(hmm_quaternion Left)
|
|||||||
// Don't be confused! Or if you must be confused, at least trust this
|
// Don't be confused! Or if you must be confused, at least trust this
|
||||||
// comment. :)
|
// comment. :)
|
||||||
COVERAGE(HMM_Mat4ToQuaternion, 4)
|
COVERAGE(HMM_Mat4ToQuaternion, 4)
|
||||||
HMM_INLINE hmm_quaternion HMM_Mat4ToQuaternion(hmm_mat4 M)
|
HMM_INLINE hmm_quaternion HMM_PREFIX(Mat4ToQuaternion)(hmm_mat4 M)
|
||||||
{
|
{
|
||||||
float T;
|
float T;
|
||||||
hmm_quaternion Q;
|
hmm_quaternion Q;
|
||||||
@@ -2046,17 +2018,17 @@ HMM_INLINE hmm_quaternion HMM_Mat4ToQuaternion(hmm_mat4 M)
|
|||||||
}
|
}
|
||||||
|
|
||||||
COVERAGE(HMM_QuaternionFromAxisAngle, 1)
|
COVERAGE(HMM_QuaternionFromAxisAngle, 1)
|
||||||
HMM_INLINE hmm_quaternion HMM_QuaternionFromAxisAngle(hmm_vec3 Axis, float AngleOfRotationRadians)
|
HMM_INLINE hmm_quaternion HMM_PREFIX(QuaternionFromAxisAngle)(hmm_vec3 Axis, float AngleOfRotation)
|
||||||
{
|
{
|
||||||
ASSERT_COVERED(HMM_QuaternionFromAxisAngle);
|
ASSERT_COVERED(HMM_QuaternionFromAxisAngle);
|
||||||
|
|
||||||
hmm_quaternion Result;
|
hmm_quaternion Result;
|
||||||
|
|
||||||
hmm_vec3 AxisNormalized = HMM_PREFIX(NormalizeVec3)(Axis);
|
hmm_vec3 AxisNormalized = HMM_PREFIX(NormalizeVec3)(Axis);
|
||||||
float SineOfRotation = HMM_PREFIX(SinF)(AngleOfRotationRadians / 2.0f);
|
float SineOfRotation = HMM_PREFIX(SinF)(AngleOfRotation / 2.0f);
|
||||||
|
|
||||||
Result.XYZ = HMM_PREFIX(MultiplyVec3f)(AxisNormalized, SineOfRotation);
|
Result.XYZ = HMM_PREFIX(MultiplyVec3f)(AxisNormalized, SineOfRotation);
|
||||||
Result.W = HMM_PREFIX(CosF)(AngleOfRotationRadians / 2.0f);
|
Result.W = HMM_PREFIX(CosF)(AngleOfRotation / 2.0f);
|
||||||
|
|
||||||
return (Result);
|
return (Result);
|
||||||
}
|
}
|
||||||
@@ -2073,7 +2045,6 @@ HMM_INLINE float HMM_PREFIX(Length)(hmm_vec2 A)
|
|||||||
ASSERT_COVERED(HMM_LengthVec2CPP);
|
ASSERT_COVERED(HMM_LengthVec2CPP);
|
||||||
|
|
||||||
float Result = HMM_PREFIX(LengthVec2)(A);
|
float Result = HMM_PREFIX(LengthVec2)(A);
|
||||||
|
|
||||||
return (Result);
|
return (Result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3153,6 +3124,46 @@ 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__)
|
||||||
@@ -3160,3 +3171,6 @@ HMM_INLINE hmm_bool operator!=(hmm_vec4 Left, hmm_vec4 Right)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* HANDMADE_MATH_H */
|
#endif /* HANDMADE_MATH_H */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,10 @@ To get started, go download [the latest release](https://github.com/HandmadeMath
|
|||||||
|
|
||||||
Version | Changes |
|
Version | Changes |
|
||||||
----------------|----------------|
|
----------------|----------------|
|
||||||
|
|
||||||
|
**1.13.0** | Fully inlined HandmadeMath.h. No need for HANDMADE_MATH_IMPLEMENTATION anymore |
|
||||||
|
**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. |
|
||||||
@@ -38,7 +42,7 @@ Version | Changes |
|
|||||||
**0.5** | Added scalar operations on vectors and matrices, added += and -= for hmm_mat4, reconciled headers and implementations, tidied up in general |
|
**0.5** | Added scalar operations on vectors and matrices, added += and -= for hmm_mat4, reconciled headers and implementations, tidied up in general |
|
||||||
**0.4** | Added SSE Optimized HMM_SqrtF, HMM_RSqrtF, Removed use of C Runtime |
|
**0.4** | Added SSE Optimized HMM_SqrtF, HMM_RSqrtF, Removed use of C Runtime |
|
||||||
**0.3** | Added +=,-=, *=, /= for hmm_vec2, hmm_vec3, hmm_vec4 |
|
**0.3** | Added +=,-=, *=, /= for hmm_vec2, hmm_vec3, hmm_vec4 |
|
||||||
**0.2b** | Disabled warning C4201 on MSVC, Added 64bit percision on HMM_PI |
|
**0.2b** | Disabled warning C4201 on MSVC, Added 64bit precision on HMM_PI |
|
||||||
**0.2a** | Prefixed Macros |
|
**0.2a** | Prefixed Macros |
|
||||||
**0.2** | Updated Documentation, Fixed C Compliance, Prefixed all functions, and added better operator overloading |
|
**0.2** | Updated Documentation, Fixed C Compliance, Prefixed all functions, and added better operator overloading |
|
||||||
**0.1** | Initial Version |
|
**0.1** | Initial Version |
|
||||||
|
|||||||
@@ -2,4 +2,6 @@
|
|||||||
#include "HandmadeTest.h"
|
#include "HandmadeTest.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define HANDMADE_MATH_IMPLEMENTATION
|
||||||
|
#define HANDMADE_MATH_NO_INLINE
|
||||||
#include "../HandmadeMath.h"
|
#include "../HandmadeMath.h"
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ TEST(Projection, Orthographic)
|
|||||||
|
|
||||||
TEST(Projection, Perspective)
|
TEST(Projection, Perspective)
|
||||||
{
|
{
|
||||||
hmm_mat4 projection = HMM_Perspective(HMM_ToRadians(90.0f), 2.0f, 5.0f, 15.0f);
|
hmm_mat4 projection = HMM_Perspective(90.0f, 2.0f, 5.0f, 15.0f);
|
||||||
|
|
||||||
{
|
{
|
||||||
hmm_vec3 original = HMM_Vec3(5.0f, 5.0f, -15.0f);
|
hmm_vec3 original = HMM_Vec3(5.0f, 5.0f, -15.0f);
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ TEST(QuaternionOps, Mat4ToQuat)
|
|||||||
|
|
||||||
// Rotate 90 degrees on the X axis
|
// Rotate 90 degrees on the X axis
|
||||||
{
|
{
|
||||||
hmm_mat4 m = HMM_Rotate(HMM_ToRadians(90.0f), HMM_Vec3(1, 0, 0));
|
hmm_mat4 m = HMM_Rotate(90, HMM_Vec3(1, 0, 0));
|
||||||
hmm_quaternion result = HMM_Mat4ToQuaternion(m);
|
hmm_quaternion result = HMM_Mat4ToQuaternion(m);
|
||||||
|
|
||||||
float cosf = 0.707107f; // cos(90/2 degrees)
|
float cosf = 0.707107f; // cos(90/2 degrees)
|
||||||
@@ -125,7 +125,7 @@ TEST(QuaternionOps, Mat4ToQuat)
|
|||||||
|
|
||||||
// Rotate 90 degrees on the Y axis (axis not normalized, just for fun)
|
// Rotate 90 degrees on the Y axis (axis not normalized, just for fun)
|
||||||
{
|
{
|
||||||
hmm_mat4 m = HMM_Rotate(HMM_ToRadians(90.0f), HMM_Vec3(0, 2, 0));
|
hmm_mat4 m = HMM_Rotate(90, HMM_Vec3(0, 2, 0));
|
||||||
hmm_quaternion result = HMM_Mat4ToQuaternion(m);
|
hmm_quaternion result = HMM_Mat4ToQuaternion(m);
|
||||||
|
|
||||||
float cosf = 0.707107f; // cos(90/2 degrees)
|
float cosf = 0.707107f; // cos(90/2 degrees)
|
||||||
@@ -139,7 +139,7 @@ TEST(QuaternionOps, Mat4ToQuat)
|
|||||||
|
|
||||||
// Rotate 90 degrees on the Z axis
|
// Rotate 90 degrees on the Z axis
|
||||||
{
|
{
|
||||||
hmm_mat4 m = HMM_Rotate(HMM_ToRadians(90.0f), HMM_Vec3(0, 0, 1));
|
hmm_mat4 m = HMM_Rotate(90, HMM_Vec3(0, 0, 1));
|
||||||
hmm_quaternion result = HMM_Mat4ToQuaternion(m);
|
hmm_quaternion result = HMM_Mat4ToQuaternion(m);
|
||||||
|
|
||||||
float cosf = 0.707107f; // cos(90/2 degrees)
|
float cosf = 0.707107f; // cos(90/2 degrees)
|
||||||
@@ -153,7 +153,7 @@ TEST(QuaternionOps, Mat4ToQuat)
|
|||||||
|
|
||||||
// Rotate 45 degrees on the X axis (this hits case 4)
|
// Rotate 45 degrees on the X axis (this hits case 4)
|
||||||
{
|
{
|
||||||
hmm_mat4 m = HMM_Rotate(HMM_ToRadians(45.0f), HMM_Vec3(1, 0, 0));
|
hmm_mat4 m = HMM_Rotate(45, HMM_Vec3(1, 0, 0));
|
||||||
hmm_quaternion result = HMM_Mat4ToQuaternion(m);
|
hmm_quaternion result = HMM_Mat4ToQuaternion(m);
|
||||||
|
|
||||||
float cosf = 0.9238795325f; // cos(90/2 degrees)
|
float cosf = 0.9238795325f; // cos(90/2 degrees)
|
||||||
|
|||||||
@@ -36,13 +36,6 @@ TEST(ScalarMath, Trigonometry)
|
|||||||
// checking that things work by default.
|
// checking that things work by default.
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(ScalarMath, ToDegrees)
|
|
||||||
{
|
|
||||||
EXPECT_FLOAT_EQ(HMM_ToDegrees(0.0f), 0.0f);
|
|
||||||
EXPECT_FLOAT_EQ(HMM_ToDegrees(HMM_PI32), 180.0f);
|
|
||||||
EXPECT_FLOAT_EQ(HMM_ToDegrees(-HMM_PI32), -180.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(ScalarMath, ToRadians)
|
TEST(ScalarMath, ToRadians)
|
||||||
{
|
{
|
||||||
EXPECT_FLOAT_EQ(HMM_ToRadians(0.0f), 0.0f);
|
EXPECT_FLOAT_EQ(HMM_ToRadians(0.0f), 0.0f);
|
||||||
|
|||||||
@@ -199,3 +199,32 @@ 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
|
||||||
|
|||||||
@@ -17,23 +17,21 @@ TEST(Transformations, Rotate)
|
|||||||
{
|
{
|
||||||
hmm_vec3 original = HMM_Vec3(1.0f, 1.0f, 1.0f);
|
hmm_vec3 original = HMM_Vec3(1.0f, 1.0f, 1.0f);
|
||||||
|
|
||||||
float angle = HMM_ToRadians(90.0f);
|
hmm_mat4 rotateX = HMM_Rotate(90, HMM_Vec3(1, 0, 0));
|
||||||
|
|
||||||
hmm_mat4 rotateX = HMM_Rotate(angle, HMM_Vec3(1, 0, 0));
|
|
||||||
hmm_vec4 rotatedX = HMM_MultiplyMat4ByVec4(rotateX, HMM_Vec4v(original, 1));
|
hmm_vec4 rotatedX = HMM_MultiplyMat4ByVec4(rotateX, HMM_Vec4v(original, 1));
|
||||||
EXPECT_FLOAT_EQ(rotatedX.X, 1.0f);
|
EXPECT_FLOAT_EQ(rotatedX.X, 1.0f);
|
||||||
EXPECT_FLOAT_EQ(rotatedX.Y, -1.0f);
|
EXPECT_FLOAT_EQ(rotatedX.Y, -1.0f);
|
||||||
EXPECT_FLOAT_EQ(rotatedX.Z, 1.0f);
|
EXPECT_FLOAT_EQ(rotatedX.Z, 1.0f);
|
||||||
EXPECT_FLOAT_EQ(rotatedX.W, 1.0f);
|
EXPECT_FLOAT_EQ(rotatedX.W, 1.0f);
|
||||||
|
|
||||||
hmm_mat4 rotateY = HMM_Rotate(angle, HMM_Vec3(0, 1, 0));
|
hmm_mat4 rotateY = HMM_Rotate(90, HMM_Vec3(0, 1, 0));
|
||||||
hmm_vec4 rotatedY = HMM_MultiplyMat4ByVec4(rotateY, HMM_Vec4v(original, 1));
|
hmm_vec4 rotatedY = HMM_MultiplyMat4ByVec4(rotateY, HMM_Vec4v(original, 1));
|
||||||
EXPECT_FLOAT_EQ(rotatedY.X, 1.0f);
|
EXPECT_FLOAT_EQ(rotatedY.X, 1.0f);
|
||||||
EXPECT_FLOAT_EQ(rotatedY.Y, 1.0f);
|
EXPECT_FLOAT_EQ(rotatedY.Y, 1.0f);
|
||||||
EXPECT_FLOAT_EQ(rotatedY.Z, -1.0f);
|
EXPECT_FLOAT_EQ(rotatedY.Z, -1.0f);
|
||||||
EXPECT_FLOAT_EQ(rotatedY.W, 1.0f);
|
EXPECT_FLOAT_EQ(rotatedY.W, 1.0f);
|
||||||
|
|
||||||
hmm_mat4 rotateZ = HMM_Rotate(angle, HMM_Vec3(0, 0, 1));
|
hmm_mat4 rotateZ = HMM_Rotate(90, HMM_Vec3(0, 0, 1));
|
||||||
hmm_vec4 rotatedZ = HMM_MultiplyMat4ByVec4(rotateZ, HMM_Vec4v(original, 1));
|
hmm_vec4 rotatedZ = HMM_MultiplyMat4ByVec4(rotateZ, HMM_Vec4v(original, 1));
|
||||||
EXPECT_FLOAT_EQ(rotatedZ.X, -1.0f);
|
EXPECT_FLOAT_EQ(rotatedZ.X, -1.0f);
|
||||||
EXPECT_FLOAT_EQ(rotatedZ.Y, 1.0f);
|
EXPECT_FLOAT_EQ(rotatedZ.Y, 1.0f);
|
||||||
|
|||||||
18
test/run_test_clang.bat
Normal file
18
test/run_test_clang.bat
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
@echo off
|
||||||
|
|
||||||
|
if not exist "build" mkdir build
|
||||||
|
pushd build
|
||||||
|
|
||||||
|
clang-cl /Fehmm_test_c.exe ..\HandmadeMath.c ..\hmm_test.c
|
||||||
|
hmm_test_c
|
||||||
|
|
||||||
|
clang-cl /Fehmm_test_c_no_sse.exe /DHANDMADE_MATH_NO_SSE ..\HandmadeMath.c ..\hmm_test.c
|
||||||
|
hmm_test_c_no_sse
|
||||||
|
|
||||||
|
clang-cl /Fehmm_test_cpp.exe ..\HandmadeMath.cpp ..\hmm_test.cpp
|
||||||
|
hmm_test_cpp
|
||||||
|
|
||||||
|
clang-cl /Fehmm_test_cpp_no_sse.exe /DHANDMADE_MATH_NO_SSE ..\HandmadeMath.cpp ..\hmm_test.cpp
|
||||||
|
hmm_test_cpp_no_sse
|
||||||
|
|
||||||
|
popd
|
||||||
@@ -12,16 +12,16 @@ if "%1%"=="travis" (
|
|||||||
if not exist "build" mkdir build
|
if not exist "build" mkdir build
|
||||||
pushd build
|
pushd build
|
||||||
|
|
||||||
cl /Fehmm_test_c.exe ..\HandmadeMath.c ..\hmm_test.c || popd && exit /B
|
cl /Fehmm_test_c.exe ..\HandmadeMath.c ..\hmm_test.c
|
||||||
hmm_test_c
|
hmm_test_c
|
||||||
|
|
||||||
cl /Fehmm_test_c_no_sse.exe /DHANDMADE_MATH_NO_SSE ..\HandmadeMath.c ..\hmm_test.c || popd && exit /B
|
cl /Fehmm_test_c_no_sse.exe /DHANDMADE_MATH_NO_SSE ..\HandmadeMath.c ..\hmm_test.c
|
||||||
hmm_test_c_no_sse
|
hmm_test_c_no_sse
|
||||||
|
|
||||||
cl /Fehmm_test_cpp.exe ..\HandmadeMath.cpp ..\hmm_test.cpp || popd && exit /B
|
cl /Fehmm_test_cpp.exe ..\HandmadeMath.cpp ..\hmm_test.cpp
|
||||||
hmm_test_cpp
|
hmm_test_cpp
|
||||||
|
|
||||||
cl /Fehmm_test_cpp_no_sse.exe /DHANDMADE_MATH_NO_SSE ..\HandmadeMath.cpp ..\hmm_test.cpp || popd && exit /B
|
cl /Fehmm_test_cpp_no_sse.exe /DHANDMADE_MATH_NO_SSE ..\HandmadeMath.cpp ..\hmm_test.cpp
|
||||||
hmm_test_cpp_no_sse
|
hmm_test_cpp_no_sse
|
||||||
|
|
||||||
popd
|
popd
|
||||||
Reference in New Issue
Block a user