mirror of
https://github.com/HandmadeMath/HandmadeMath.git
synced 2026-07-16 12:41:16 +00:00
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
HandmadeMath.h v0.5.2
|
HandmadeMath.h v0.6
|
||||||
|
|
||||||
This is a single header file with a bunch of useful functions for
|
This is a single header file with a bunch of useful functions for
|
||||||
basic game math operations.
|
basic game math operations.
|
||||||
@@ -122,7 +122,15 @@
|
|||||||
0.5.2
|
0.5.2
|
||||||
(*) Fixed SSE code in HMM_SqrtF
|
(*) Fixed SSE code in HMM_SqrtF
|
||||||
(*) Fixed SSE code in HMM_RSqrtF
|
(*) Fixed SSE code in HMM_RSqrtF
|
||||||
|
0.6
|
||||||
|
(*) Added Unit testing
|
||||||
|
(*) Made HMM_Power faster
|
||||||
|
(*) Fixed possible efficiency problem with HMM_Normalize
|
||||||
|
(*) RENAMED HMM_LengthSquareRoot to HMM_LengthSquared
|
||||||
|
(*) RENAMED HMM_RSqrtF to HMM_RSquareRootF
|
||||||
|
(*) RENAMED HMM_SqrtF to HMM_SquareRootF
|
||||||
|
(*) REMOVED Inner function (user should use Dot now)
|
||||||
|
(*) REMOVED HMM_FastInverseSquareRoot function declaration
|
||||||
|
|
||||||
LICENSE
|
LICENSE
|
||||||
|
|
||||||
@@ -147,10 +155,6 @@
|
|||||||
Insofaras (@insofaras)
|
Insofaras (@insofaras)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// NOTE(zak): I think this is the include for SSE 2 on
|
|
||||||
// MacOS, Windows, and Linux if im wrong just open up
|
|
||||||
// a issue and tell me, or submit a pull request
|
|
||||||
// with the fix.
|
|
||||||
#include <xmmintrin.h>
|
#include <xmmintrin.h>
|
||||||
|
|
||||||
#ifndef HANDMADE_MATH_H
|
#ifndef HANDMADE_MATH_H
|
||||||
@@ -334,12 +338,11 @@ typedef hmm_mat4 hmm_m4;
|
|||||||
HMMDEF float HMM_SinF(float Angle);
|
HMMDEF float HMM_SinF(float Angle);
|
||||||
HMMDEF float HMM_TanF(float Angle);
|
HMMDEF float HMM_TanF(float Angle);
|
||||||
HMMDEF float HMM_CosF(float Angle);
|
HMMDEF float HMM_CosF(float Angle);
|
||||||
HMMDEF float HMM_SqrtF(float Angle);
|
|
||||||
|
|
||||||
HMMDEF float HMM_ToRadians(float Degrees);
|
HMMDEF float HMM_ToRadians(float Degrees);
|
||||||
HMMDEF float HMM_Inner(hmm_vec3 A, hmm_vec3 B);
|
HMMDEF float HMM_SquareRootF(float Float);
|
||||||
HMMDEF float HMM_SquareRoot(float Float);
|
HMMDEF float HMM_RSquareRootF(float Float);
|
||||||
HMMDEF float HMM_LengthSquareRoot(hmm_vec3 A);
|
HMMDEF float HMM_LengthSquared(hmm_vec3 A);
|
||||||
HMMDEF float HMM_FastInverseSquareRoot(float Number);
|
HMMDEF float HMM_FastInverseSquareRoot(float Number);
|
||||||
HMMDEF float HMM_Length(hmm_vec3 A);
|
HMMDEF float HMM_Length(hmm_vec3 A);
|
||||||
HMMDEF float HMM_Power(float Base, int Exponent);
|
HMMDEF float HMM_Power(float Base, int Exponent);
|
||||||
@@ -528,7 +531,7 @@ HMM_TanF(float Radians)
|
|||||||
}
|
}
|
||||||
|
|
||||||
HINLINE float
|
HINLINE float
|
||||||
HMM_SqrtF(float Value)
|
HMM_SquareRootF(float Value)
|
||||||
{
|
{
|
||||||
float Result = 0;
|
float Result = 0;
|
||||||
|
|
||||||
@@ -544,7 +547,7 @@ HMM_SqrtF(float Value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
HINLINE float
|
HINLINE float
|
||||||
HMM_RSqrtF(float Value)
|
HMM_RSquareRootF(float Value)
|
||||||
{
|
{
|
||||||
float Result = 0;
|
float Result = 0;
|
||||||
|
|
||||||
@@ -569,20 +572,20 @@ HMM_ToRadians(float Degrees)
|
|||||||
}
|
}
|
||||||
|
|
||||||
HINLINE float
|
HINLINE float
|
||||||
HMM_Inner(hmm_vec3 A, hmm_vec3 B)
|
HMM_Dot(hmm_vec3 VecOne, hmm_vec3 VecTwo)
|
||||||
{
|
{
|
||||||
float Result = 0;
|
float Result = 0;
|
||||||
|
|
||||||
Result = A.X * B.X + A.Y * B.Y + A.Z * B.Z;
|
Result = (VecOne.X * VecTwo.X) + (VecOne.Y * VecTwo.Y) + (VecOne.Z * VecTwo.Z);
|
||||||
return (Result);
|
return (Result);
|
||||||
}
|
}
|
||||||
|
|
||||||
HINLINE float
|
HINLINE float
|
||||||
HMM_LengthSquareRoot(hmm_vec3 A)
|
HMM_LengthSquared(hmm_vec3 A)
|
||||||
{
|
{
|
||||||
float Result = 0;
|
float Result = 0;
|
||||||
|
|
||||||
Result = HMM_Inner(A, A);
|
Result = HMM_Dot(A, A);
|
||||||
return (Result);
|
return (Result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -591,7 +594,7 @@ HMM_Length(hmm_vec3 A)
|
|||||||
{
|
{
|
||||||
float Result = 0;
|
float Result = 0;
|
||||||
|
|
||||||
Result = HMM_SqrtF(HMM_LengthSquareRoot(A));
|
Result = HMM_SquareRootF(HMM_LengthSquared(A));
|
||||||
return (Result);
|
return (Result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -646,9 +649,11 @@ HMM_Normalize(hmm_vec3 A)
|
|||||||
{
|
{
|
||||||
hmm_vec3 Result = {0};
|
hmm_vec3 Result = {0};
|
||||||
|
|
||||||
Result.X = A.X * (1.0f / HMM_Length(A));
|
float VectorLength = HMM_Length(A);
|
||||||
Result.Y = A.Y * (1.0f / HMM_Length(A));
|
|
||||||
Result.Z = A.Z * (1.0f / HMM_Length(A));
|
Result.X = A.X * (1.0f / VectorLength);
|
||||||
|
Result.Y = A.Y * (1.0f / VectorLength);
|
||||||
|
Result.Z = A.Z * (1.0f / VectorLength);
|
||||||
|
|
||||||
return (Result);
|
return (Result);
|
||||||
}
|
}
|
||||||
@@ -665,15 +670,6 @@ HMM_Cross(hmm_vec3 VecOne, hmm_vec3 VecTwo)
|
|||||||
return (Result);
|
return (Result);
|
||||||
}
|
}
|
||||||
|
|
||||||
HINLINE float
|
|
||||||
HMM_Dot(hmm_vec3 VecOne, hmm_vec3 VecTwo)
|
|
||||||
{
|
|
||||||
float Result = 0;
|
|
||||||
|
|
||||||
Result = (VecOne.X * VecTwo.X) + (VecOne.Y * VecTwo.Y) + (VecOne.Z * VecTwo.Z);
|
|
||||||
return (Result);
|
|
||||||
}
|
|
||||||
|
|
||||||
HINLINE hmm_vec2
|
HINLINE hmm_vec2
|
||||||
HMM_Vec2(float X, float Y)
|
HMM_Vec2(float X, float Y)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user