diff --git a/source/Vector3.cpp b/source/Vector3.cpp index 7644794..5abdd04 100644 --- a/source/Vector3.cpp +++ b/source/Vector3.cpp @@ -202,10 +202,9 @@ namespace omath const float distance = DistTo(other); const auto delta = other - *this; - // Make x negative since -89 is top and 89 is bottom return { - -angles::RadiansToDegrees(asinf(delta.z / distance)), + angles::RadiansToDegrees(asinf(delta.z / distance)), angles::RadiansToDegrees(atan2f(delta.y, delta.x)), 0.f }; @@ -251,7 +250,7 @@ namespace omath Vector3 Vector3::Normalized() const { - float length = this->Length(); + const float length = this->Length(); if (length != 0) { return *this / length; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 43c591f..a73124c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -5,7 +5,7 @@ project(unit-tests) file(GLOB TEST_SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) include(GoogleTest) -add_executable(unit-tests UnitTestColor.cpp UnitTestMatrix.cpp) +add_executable(unit-tests UnitTestPrediction.cpp UnitTestMatrix.cpp) target_link_libraries(unit-tests PRIVATE gtest gtest_main omath) diff --git a/tests/UnitTestColor.cpp b/tests/UnitTestColor.cpp deleted file mode 100644 index 5ced212..0000000 --- a/tests/UnitTestColor.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include - -TEST(x,x) -{ - omath::prediction::Target target{.m_origin = {100, 0, 60}, .m_velocity = {0, 0, 0}, .m_isAirborne = false}; - omath::prediction::Projectile proj = {.m_origin = {3,2,1}, .m_launchSpeed = 5000, .m_gravityScale= 0.4}; - auto vel = omath::prediction::Engine(400, 1.f / 1000.f, 50, 5.f).MaybeCalculateAimPoint(proj, target); - - auto pitch = proj.m_origin.ViewAngleTo(vel.value()).x; - - printf("pitch: %f", pitch); -} \ No newline at end of file diff --git a/tests/UnitTestPrediction.cpp b/tests/UnitTestPrediction.cpp new file mode 100644 index 0000000..d3ce5c2 --- /dev/null +++ b/tests/UnitTestPrediction.cpp @@ -0,0 +1,14 @@ +#include +#include + +TEST(UnitTestPrediction, PredictionTest) +{ + const omath::prediction::Target target{.m_origin = {100, 0, 90}, .m_velocity = {0, 0, 0}, .m_isAirborne = false}; + const omath::prediction::Projectile proj = {.m_origin = {3,2,1}, .m_launchSpeed = 5000, .m_gravityScale= 0.4}; + const auto viewPoint = omath::prediction::Engine(400, 1.f / 1000.f, 50, 5.f).MaybeCalculateAimPoint(proj, target); + + const auto [pitch, yaw, _] = proj.m_origin.ViewAngleTo(viewPoint.value()); + + EXPECT_NEAR(42.547142, pitch, 0.0001f); + EXPECT_NEAR(-1.181189, yaw, 0.0001f); +} \ No newline at end of file