mirror of
https://github.com/HandmadeMath/HandmadeMath.git
synced 2025-10-18 06:31:48 +00:00
WIP: Properly initialize all elements of LookAt matrix (#84)
* Properly initialize all elements of LookAt matrix * Update version and readme * Add a test for LookAt good enough
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
HandmadeMath.h v1.5.0
|
HandmadeMath.h v1.5.1
|
||||||
|
|
||||||
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.
|
||||||
@@ -166,6 +166,8 @@
|
|||||||
(*) Changed internal structure for better performance and inlining.
|
(*) Changed internal structure for better performance and inlining.
|
||||||
(*) As a result, HANDMADE_MATH_NO_INLINE has been removed and no
|
(*) As a result, HANDMADE_MATH_NO_INLINE has been removed and no
|
||||||
longer has any effect.
|
longer has any effect.
|
||||||
|
1.5.1
|
||||||
|
(*) Fixed a bug with uninitialized elements in HMM_LookAt.
|
||||||
|
|
||||||
|
|
||||||
LICENSE
|
LICENSE
|
||||||
@@ -2339,14 +2341,17 @@ hmm_mat4 HMM_LookAt(hmm_vec3 Eye, hmm_vec3 Center, hmm_vec3 Up)
|
|||||||
Result.Elements[0][0] = S.X;
|
Result.Elements[0][0] = S.X;
|
||||||
Result.Elements[0][1] = U.X;
|
Result.Elements[0][1] = U.X;
|
||||||
Result.Elements[0][2] = -F.X;
|
Result.Elements[0][2] = -F.X;
|
||||||
|
Result.Elements[0][3] = 0.0f;
|
||||||
|
|
||||||
Result.Elements[1][0] = S.Y;
|
Result.Elements[1][0] = S.Y;
|
||||||
Result.Elements[1][1] = U.Y;
|
Result.Elements[1][1] = U.Y;
|
||||||
Result.Elements[1][2] = -F.Y;
|
Result.Elements[1][2] = -F.Y;
|
||||||
|
Result.Elements[1][3] = 0.0f;
|
||||||
|
|
||||||
Result.Elements[2][0] = S.Z;
|
Result.Elements[2][0] = S.Z;
|
||||||
Result.Elements[2][1] = U.Z;
|
Result.Elements[2][1] = U.Z;
|
||||||
Result.Elements[2][2] = -F.Z;
|
Result.Elements[2][2] = -F.Z;
|
||||||
|
Result.Elements[2][3] = 0.0f;
|
||||||
|
|
||||||
Result.Elements[3][0] = -HMM_DotVec3(S, Eye);
|
Result.Elements[3][0] = -HMM_DotVec3(S, Eye);
|
||||||
Result.Elements[3][1] = -HMM_DotVec3(U, Eye);
|
Result.Elements[3][1] = -HMM_DotVec3(U, Eye);
|
||||||
|
@@ -10,6 +10,7 @@ To get started, go download [the latest release](https://github.com/HandmadeMath
|
|||||||
|
|
||||||
Version | Changes |
|
Version | Changes |
|
||||||
----------------|----------------|
|
----------------|----------------|
|
||||||
|
**1.5.1** | Fixed a bug with uninitialized elements in HMM_LookAt.
|
||||||
**1.5.0** | Changed internal structure for better performance and inlining. As a result, `HANDMADE_MATH_NO_INLINE` has been removed and no longer has any effect.
|
**1.5.0** | Changed internal structure for better performance and inlining. As a result, `HANDMADE_MATH_NO_INLINE` has been removed and no longer has any effect.
|
||||||
**1.4.0** | Fixed bug when using C mode. SSE'd all vec4 operations. Removed zeroing for better performance.
|
**1.4.0** | Fixed bug when using C mode. SSE'd all vec4 operations. Removed zeroing for better performance.
|
||||||
**1.3.0** | Removed need to `#define HANDMADE_MATH_CPP_MODE`. C++ definitions are now included automatically in C++ environments.
|
**1.3.0** | Removed need to `#define HANDMADE_MATH_CPP_MODE`. C++ definitions are now included automatically in C++ environments.
|
||||||
|
@@ -51,3 +51,27 @@ TEST(Transformations, Scale)
|
|||||||
EXPECT_FLOAT_EQ(scaled.Z, 1.5f);
|
EXPECT_FLOAT_EQ(scaled.Z, 1.5f);
|
||||||
EXPECT_FLOAT_EQ(scaled.W, 1.0f);
|
EXPECT_FLOAT_EQ(scaled.W, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(Transformations, LookAt)
|
||||||
|
{
|
||||||
|
const float abs_error = 0.0001f;
|
||||||
|
|
||||||
|
hmm_mat4 result = HMM_LookAt(HMM_Vec3(1.0f, 0.0f, 0.0f), HMM_Vec3(0.0f, 2.0f, 1.0f), HMM_Vec3(2.0f, 1.0f, 1.0f));
|
||||||
|
|
||||||
|
EXPECT_NEAR(result.Elements[0][0], 0.169031f, abs_error);
|
||||||
|
EXPECT_NEAR(result.Elements[0][1], 0.897085f, abs_error);
|
||||||
|
EXPECT_NEAR(result.Elements[0][2], 0.408248f, abs_error);
|
||||||
|
EXPECT_FLOAT_EQ(result.Elements[0][3], 0.0f);
|
||||||
|
EXPECT_NEAR(result.Elements[1][0], 0.507093f, abs_error);
|
||||||
|
EXPECT_NEAR(result.Elements[1][1], 0.276026f, abs_error);
|
||||||
|
EXPECT_NEAR(result.Elements[1][2], -0.816497f, abs_error);
|
||||||
|
EXPECT_FLOAT_EQ(result.Elements[1][3], 0.0f);
|
||||||
|
EXPECT_NEAR(result.Elements[2][0], -0.845154f, abs_error);
|
||||||
|
EXPECT_NEAR(result.Elements[2][1], 0.345033f, abs_error);
|
||||||
|
EXPECT_NEAR(result.Elements[2][2], -0.408248f, abs_error);
|
||||||
|
EXPECT_FLOAT_EQ(result.Elements[2][3], 0.0f);
|
||||||
|
EXPECT_NEAR(result.Elements[3][0], -0.169031f, abs_error);
|
||||||
|
EXPECT_NEAR(result.Elements[3][1], -0.897085f, abs_error);
|
||||||
|
EXPECT_NEAR(result.Elements[3][2], -0.408248f, abs_error);
|
||||||
|
EXPECT_FLOAT_EQ(result.Elements[3][3], 1.0f);
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user