added unit test

This commit is contained in:
2024-08-27 10:56:56 +03:00
parent db57dfd5f9
commit 13188615ed
5 changed files with 39 additions and 11 deletions

View File

@@ -15,6 +15,7 @@ namespace omath::projection
class Camera
{
public:
Camera(const Vector3& position, const Vector3& viewAngles, const Vector3& viewPort, float fov, float near, float far);
void SetViewAngles(const Vector3& viewAngles);
[[nodiscard]] const Vector3& GetViewAngles() const;

View File

@@ -238,10 +238,12 @@ namespace omath
const auto cosRoll = std::cos(angles::DegreesToRadians(roll));
const auto sinRoll = std::sin(angles::DegreesToRadians(roll));
return {-sinRoll*sinPitch*cosYaw + -cosRoll*-sinYaw,
-sinRoll*sinPitch*sinYaw + -cosRoll*cosYaw,
-sinRoll*cosPitch};
// Right vector calculation
return {
cosYaw * cosRoll - sinYaw * sinPitch * sinRoll, // X component
sinRoll * cosPitch, // Y component
sinYaw * cosRoll + cosYaw * sinPitch * sinRoll // Z component
};
}
Vector3 Vector3::UpVector(float pitch, float yaw, float roll)
@@ -255,12 +257,11 @@ namespace omath
const auto cosRoll = std::cos(angles::DegreesToRadians(roll));
const auto sinRoll = std::sin(angles::DegreesToRadians(roll));
return
{
cosRoll*sinPitch*cosYaw+-sinRoll*-sinYaw,
cosRoll*sinPitch*cosYaw+-sinRoll*-sinYaw,
cosRoll*cosPitch,
// Up vector calculation
return {
-sinRoll * cosYaw + cosRoll * sinPitch * sinYaw, // X component
cosRoll * cosPitch, // Y component
-sinRoll * sinYaw - cosRoll * sinPitch * cosYaw // Z component
};
}

View File

@@ -7,6 +7,17 @@
namespace omath::projection
{
Camera::Camera(const Vector3 &position, const Vector3 &viewAngles, const Vector3 &viewPort, const float fov, const float near,
const float far)
{
m_origin = position;
m_viewAngles = viewAngles;
m_viewPort = viewPort;
m_fieldOfView = fov;
m_nearPlaneDistance = near;
m_farPlaneDistance = far;
}
Matrix Camera::GetViewMatrix() const
{
return GetOrientationMatrix() * GetTranslationMatrix();

View File

@@ -5,7 +5,7 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
file(GLOB TEST_SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
include(GoogleTest)
add_executable(unit-tests UnitTestPrediction.cpp UnitTestMatrix.cpp UnitTestAstar.cpp)
add_executable(unit-tests UnitTestPrediction.cpp UnitTestMatrix.cpp UnitTestAstar.cpp UnitTestProjection.cpp)
target_link_libraries(unit-tests PRIVATE gtest gtest_main omath)

View File

@@ -0,0 +1,15 @@
//
// Created by Vlad on 27.08.2024.
//
#include <gtest/gtest.h>
#include <omath/matrix.h>
#include <print>
#include <omath/projection/Camera.h>
TEST(UnitTestProjection, IsPointOnScreen)
{
const omath::projection::Camera camera({}, {90, 0.f, 0.f} , {1920.f, 1080.f, 0.f}, 120, 10, 100);
const auto proj = camera.WorldToScreen({0,0,15});
EXPECT_TRUE(proj.has_value());
}