8000 Global improvement by orange-cpp · Pull Request #15 · orange-cpp/omath · GitHub
[go: up one dir, main page]

Skip to content

Global improvement #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added more unit tests
  • Loading branch information
orange-cpp committed Nov 30, 2024
commit a33ee638b9715d606594ebbce93402a223bfac06
35 changes: 31 additions & 4 deletions include/omath/Angles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,39 @@

namespace omath::angles
{
[[nodiscard]] constexpr float RadiansToDegrees(const float radiands)
template<class type>
requires std::is_floating_point_v<type>
[[nodiscard]] constexpr float RadiansToDegrees(const type& radians)
{
return radiands * (180.f / std::numbers::pi_v<float>);
return radians * (type(180) / std::numbers::pi_v<type>);
}
[[nodiscard]] constexpr float DegreesToRadians(const float degrees)

template<class type>
requires std::is_floating_point_v<type>
[[nodiscard]] constexpr float DegreesToRadians(const type& degrees)
{
return degrees * (std::numbers::pi_v<type> / type(180));
}

template<class type>
requires std::is_floating_point_v<type>
[[nodiscard]] type HorizontalFovToVertical(const type& horFov, const type& aspect)
{
return degrees * (std::numbers::pi_v<float> / 180.f);
const auto fovRad = DegreesToRadians(horFov);

const auto vertFov = type(2) * std::atan(std::tan(fovRad / type(2)) / aspect);

return RadiansToDegrees(vertFov);
}

template<class type>
requires std::is_floating_point_v<type>
[[nodiscard]] type VerticalFovToHorizontal(const type& vertFov, const type& aspect)
{
const auto fovRad = DegreesToRadians(vertFov);

const auto horFov = type(2) * std::atan(std::tan(fovRad / type(2)) * aspect);

return RadiansToDegrees(horFov);
}
}
1 change: 1 addition & 0 deletions include/omath/collision/LineTracer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace omath::collision
public:
LineTracer() = delete;


[[nodiscard]]
static bool CanTraceLine(const Ray& ray, const Triangle3d& triangle);

Expand Down
8 changes: 4 additions & 4 deletions include/omath/engines/opengl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ namespace omath::opengl
{
return
{
{right.x, up.x, -forward.x, 0},
{right.y, up.y, -forward.y, 0},
{right.z, up.z, -forward.z, 0},
{-cam_origin.x, -cam_origin.y, -cam_origin.z, 1},
{right.x, up.x, -forward.x, 0},
{right.y, up.y, -forward.y, 0},
{right.z, up.z, -forward.z, 0},
{-cam_origin.x, -cam_origin.y, -cam_origin.z, 1},
};
}

Expand Down
6 changes: 6 additions & 0 deletions include/omath/pathfinding/NavigationMesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@

namespace omath::pathfinding
{

enum Error
{

};

class NavigationMesh final
{
public:
Expand Down
2 changes: 2 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ add_executable(unit-tests
general/UnitTestColor.cpp
general/UnitTestVector4.cpp
general/UnitTestLineTrace.cpp
general/UnitTestAngles.cpp

engines/UnitTestOpenGL.cpp
engines/UnitTestUnityEngine.cpp
engines/UnitTestSourceEngine.cpp

)

target_link_libraries(unit-tests PRIVATE gtest gtest_main omath glm)
Expand Down
4 changes: 2 additions & 2 deletions tests/engines/UnitTestOpenGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include <gtest/gtest.h>
#include <omath/Matrix.hpp>
#include <print>
#include <omath/engines/opengl.hpp>
#include <omath/engines/source.hpp>
#include <omath/engines/OpenGL.hpp>
#include <omath/engines/Source.hpp>
#include <glm/glm.hpp>

#include "glm/ext/matrix_clip_space.hpp"
Expand Down
38 changes: 38 additions & 0 deletions tests/general/UnitTestAngles.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// Created by Orange on 11/30/2024.
//
#include <gtest/gtest.h>
#include <omath/Angles.hpp>


TEST(UnitTestAngles, RadiansToDeg)
{
constexpr float rad = 67;

EXPECT_NEAR(omath::angles::RadiansToDegrees(rad), 3838.82f, 0.01f);
}

TEST(UnitTestAngles, DegreesToRadians)
{
constexpr float degree = 90;

EXPECT_NEAR(omath::angles::DegreesToRadians(degree), 1.5708f, 0.01f);
}

TEST(UnitTestAngles, HorizontalFovToVerical)
{
constexpr float hFov = 90;
constexpr float aspectRation = 16.0f / 9.0f;
const auto verticalFov = omath::angles::HorizontalFovToVertical(hFov, aspectRation);

EXPECT_NEAR(verticalFov, 58.71f, 0.01f);
}

TEST(UnitTestAngles, VerticalToHorizontal)
{
constexpr float vFov = 58.71;
constexpr float aspectRation = 16.0f / 9.0f;
const auto horizontalFov = omath::angles::VerticalFovToHorizontal(vFov, aspectRation);

EXPECT_NEAR(horizontalFov, 89.99f, 0.01f);
}
0