mirror of
https://github.com/HandmadeMath/HandmadeMath.git
synced 2025-12-28 07:34:32 +00:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@@ -361,6 +361,7 @@ HMMDEF float HMM_LengthSquared(hmm_vec3 A);
|
||||
HMMDEF float HMM_Length(hmm_vec3 A);
|
||||
HMMDEF float HMM_Power(float Base, int Exponent);
|
||||
HMMDEF float HMM_PowerF(float Base, float Exponent);
|
||||
HMMDEF float HMM_Lerp(float A, float Time, float B);
|
||||
HMMDEF float HMM_Clamp(float Min, float Value, float Max);
|
||||
|
||||
HMMDEF hmm_vec3 HMM_Normalize(hmm_vec3 A);
|
||||
@@ -409,6 +410,8 @@ HMMDEF hmm_mat4 HMM_MultiplyMat4f(hmm_mat4 Matrix, float Scalar);
|
||||
HMMDEF hmm_vec4 HMM_MultiplyMat4ByVec4(hmm_mat4 Matrix, hmm_vec4 Vector);
|
||||
HMMDEF hmm_mat4 HMM_DivideMat4f(hmm_mat4 Matrix, float Scalar);
|
||||
|
||||
HMMDEF hmm_mat4 HMM_Transpose(hmm_mat4 Matrix);
|
||||
|
||||
HMMDEF hmm_mat4 HMM_Orthographic(float Left, float Right, float Bottom, float Top, float Near, float Far);
|
||||
HMMDEF hmm_mat4 HMM_Perspective(float FOV, float AspectRatio, float Near, float Far);
|
||||
HMMDEF hmm_mat4 HMM_Translate(hmm_vec3 Translation);
|
||||
@@ -423,7 +426,6 @@ HMMDEF hmm_mat4 HMM_LookAt(hmm_vec3 Eye, hmm_vec3 Center, hmm_vec3 Up);
|
||||
|
||||
#ifdef HANDMADE_MATH_CPP_MODE
|
||||
|
||||
|
||||
HMMDEF float HMM_Dot(hmm_vec2 VecOne, hmm_vec2 VecTwo);
|
||||
HMMDEF float HMM_Dot(hmm_vec3 VecOne, hmm_vec3 VecTwo);
|
||||
HMMDEF float HMM_Dot(hmm_vec4 VecOne, hmm_vec4 VecTwo);
|
||||
@@ -612,7 +614,6 @@ HMM_ToRadians(float Degrees)
|
||||
return (Result);
|
||||
}
|
||||
|
||||
|
||||
HINLINE float
|
||||
HMM_DotVec2(hmm_vec2 VecOne, hmm_vec2 VecTwo)
|
||||
{
|
||||
@@ -631,7 +632,6 @@ HMM_DotVec3(hmm_vec3 VecOne, hmm_vec3 VecTwo)
|
||||
return (Result);
|
||||
}
|
||||
|
||||
|
||||
HINLINE float
|
||||
HMM_DotVec4(hmm_vec4 VecOne, hmm_vec4 VecTwo)
|
||||
{
|
||||
@@ -641,7 +641,6 @@ HMM_DotVec4(hmm_vec4 VecOne, hmm_vec4 VecTwo)
|
||||
return (Result);
|
||||
}
|
||||
|
||||
|
||||
HINLINE float
|
||||
HMM_LengthSquared(hmm_vec3 A)
|
||||
{
|
||||
@@ -717,7 +716,6 @@ HMM_Clamp(float Min, float Value, float Max)
|
||||
return (Result);
|
||||
}
|
||||
|
||||
|
||||
HINLINE hmm_vec3
|
||||
HMM_Normalize(hmm_vec3 A)
|
||||
{
|
||||
@@ -1181,6 +1179,24 @@ HMM_DivideMat4f(hmm_mat4 Matrix, float Scalar)
|
||||
return (Result);
|
||||
}
|
||||
|
||||
hmm_mat4
|
||||
HMM_Transpose(hmm_mat4 Matrix)
|
||||
{
|
||||
hmm_mat4 Result = HMM_Mat4();
|
||||
|
||||
int Columns;
|
||||
for(Columns = 0; Columns < 4; ++Columns)
|
||||
{
|
||||
int Rows;
|
||||
for(Rows = 0; Rows < 4; ++Rows)
|
||||
{
|
||||
Result.Elements[Rows][Columns] = Matrix.Elements[Columns][Rows];
|
||||
}
|
||||
}
|
||||
|
||||
return (Result);
|
||||
}
|
||||
|
||||
hmm_mat4
|
||||
HMM_Orthographic(float Left, float Right, float Bottom, float Top, float Near, float Far)
|
||||
{
|
||||
|
||||
@@ -64,6 +64,12 @@ TEST(ScalarMath, PowerF)
|
||||
EXPECT_FLOAT_EQ(HMM_PowerF(-2.0f, 4.1), -17.148376f);
|
||||
EXPECT_FLOAT_EQ(HMM_PowerF(2.0f, -2.5), 0.176777f);
|
||||
EXPECT_FLOAT_EQ(HMM_PowerF(-2.0f, -2.5), -0.176777f);
|
||||
|
||||
TEST(ScalarMath, Lerp)
|
||||
{
|
||||
EXPECT_FLOAT_EQ(HMM_Lerp(-2.0f, 0.0f, 2.0f), -2.0f);
|
||||
EXPECT_FLOAT_EQ(HMM_Lerp(-2.0f, 0.5f, 2.0f), 0.0f);
|
||||
EXPECT_FLOAT_EQ(HMM_Lerp(-2.0f, 1.0f, 2.0f), 2.0f);
|
||||
}
|
||||
|
||||
TEST(ScalarMath, Clamp)
|
||||
@@ -215,6 +221,41 @@ TEST(VectorOps, DotVec4)
|
||||
EXPECT_FLOAT_EQ(HMM_Dot(v1, v2), 70.0f);
|
||||
}
|
||||
|
||||
TEST(MatrixOps, Transpose)
|
||||
{
|
||||
hmm_mat4 m4 = HMM_Mat4(); // will have 1 - 16
|
||||
|
||||
// Fill the matrix
|
||||
int Counter = 1;
|
||||
for (int Column = 0; Column < 4; ++Column)
|
||||
{
|
||||
for (int Row = 0; Row < 4; ++Row)
|
||||
{
|
||||
m4.Elements[Column][Row] = Counter;
|
||||
++Counter;
|
||||
}
|
||||
}
|
||||
|
||||
// Test the matrix
|
||||
hmm_mat4 result = HMM_Transpose(m4);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], 1.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], 5.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][2], 9.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][3], 13.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][0], 2.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][1], 6.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][2], 10.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][3], 14.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][0], 3.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][1], 7.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][2], 11.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][3], 15.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[3][0], 4.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[3][1], 8.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[3][2], 12.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[3][3], 16.0f);
|
||||
}
|
||||
|
||||
TEST(Addition, Vec2)
|
||||
{
|
||||
hmm_vec2 v2_1 = HMM_Vec2(1.0f, 2.0f);
|
||||
|
||||
Reference in New Issue
Block a user