mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 07:03:25 +00:00
Adds functionality to convert screen coordinates to world space, including handling for cases where the inverse view projection matrix is singular or when the world position is out of screen bounds. Also exposes Camera class to unit tests.
22 lines
851 B
C++
22 lines
851 B
C++
//
|
|
// Created by Vlad on 27.08.2024.
|
|
//
|
|
#include <complex>
|
|
#include <gtest/gtest.h>
|
|
#include <omath/engines/source_engine/camera.hpp>
|
|
#include <omath/projection/camera.hpp>
|
|
#include <print>
|
|
|
|
TEST(UnitTestProjection, Projection)
|
|
{
|
|
constexpr auto fov = omath::Angle<float, 0.f, 180.f, omath::AngleFlags::Clamped>::from_degrees(90.f);
|
|
const auto cam = omath::source_engine::Camera({0, 0, 0}, omath::source_engine::ViewAngles{}, {1920.f, 1080.f}, fov,
|
|
0.01f, 1000.f);
|
|
|
|
const auto projected = cam.world_to_screen({1000, 0, 50.f});
|
|
const auto result = cam.screen_to_world(projected.value());
|
|
const auto result2 = cam.world_to_screen(result.value());
|
|
EXPECT_NEAR(projected->x, 960.f, 0.001f);
|
|
EXPECT_NEAR(projected->y, 504.f, 0.001f);
|
|
EXPECT_NEAR(projected->z, 1.f, 0.001f);
|
|
} |