mirror of
https://github.com/orange-cpp/omath.git
synced 2026-08-08 14:02:06 +00:00
added stuff
This commit is contained in:
@@ -0,0 +1,23 @@
|
|||||||
|
//
|
||||||
|
// Created by orange on 7/1/2026.
|
||||||
|
//
|
||||||
|
#pragma once
|
||||||
|
#include "omath/linear_algebra/vector3.hpp"
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
|
namespace omath::algorithm
|
||||||
|
{
|
||||||
|
template<class Camera, class FloatingType>
|
||||||
|
requires std::is_floating_point_v<FloatingType>
|
||||||
|
[[nodiscard]]
|
||||||
|
Vector3<float> world_to_radar(const Camera& camera, const Vector3<FloatingType>& position, const FloatingType scale)
|
||||||
|
{
|
||||||
|
const auto origin = static_cast<Vector3<FloatingType>>(camera.get_origin());
|
||||||
|
const auto forward = static_cast<Vector3<FloatingType>>(camera.get_abs_forward());
|
||||||
|
const auto right = static_cast<Vector3<FloatingType>>(camera.get_abs_right());
|
||||||
|
const auto direction = position - origin;
|
||||||
|
|
||||||
|
return {static_cast<float>(direction.dot(right) * scale), static_cast<float>(-direction.dot(forward) * scale),
|
||||||
|
0.f};
|
||||||
|
}
|
||||||
|
} // namespace omath::algorithm
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include <omath/algorithm/radar.hpp>
|
||||||
|
#include <omath/engines/cry_engine/camera.hpp>
|
||||||
|
#include <omath/engines/frostbite_engine/camera.hpp>
|
||||||
|
#include <omath/engines/iw_engine/camera.hpp>
|
||||||
|
#include <omath/engines/opengl_engine/camera.hpp>
|
||||||
|
#include <omath/engines/rage_engine/camera.hpp>
|
||||||
|
#include <omath/engines/source_engine/camera.hpp>
|
||||||
|
#include <omath/engines/unity_engine/camera.hpp>
|
||||||
|
#include <omath/engines/unreal_engine/camera.hpp>
|
||||||
|
|
||||||
|
using namespace omath;
|
||||||
|
|
||||||
|
template<class CameraType, class NumericType>
|
||||||
|
static void verify_world_to_radar_uses_camera_axes()
|
||||||
|
{
|
||||||
|
const Vector3<NumericType> origin{NumericType{10}, NumericType{-20}, NumericType{5}};
|
||||||
|
const NumericType world_distance = NumericType{20};
|
||||||
|
const NumericType scale = NumericType{0.5};
|
||||||
|
const auto radar_distance = static_cast<float>(world_distance * scale);
|
||||||
|
|
||||||
|
CameraType camera{
|
||||||
|
origin, {}, {1280.f, 720.f}, projection::FieldOfView::from_degrees(90.f), NumericType{0.01},
|
||||||
|
NumericType{1000}};
|
||||||
|
|
||||||
|
const auto forward_position = origin + camera.get_abs_forward() * world_distance;
|
||||||
|
const auto forward_radar = algorithm::world_to_radar(camera, forward_position, scale);
|
||||||
|
|
||||||
|
EXPECT_NEAR(forward_radar.x, 0.f, 1e-4f);
|
||||||
|
EXPECT_NEAR(forward_radar.y, -radar_distance, 1e-4f);
|
||||||
|
EXPECT_NEAR(forward_radar.z, 0.f, 1e-6f);
|
||||||
|
|
||||||
|
const auto right_position = origin + camera.get_abs_right() * world_distance;
|
||||||
|
const auto right_radar = algorithm::world_to_radar(camera, right_position, scale);
|
||||||
|
|
||||||
|
EXPECT_NEAR(right_radar.x, radar_distance, 1e-4f);
|
||||||
|
EXPECT_NEAR(right_radar.y, 0.f, 1e-4f);
|
||||||
|
EXPECT_NEAR(right_radar.z, 0.f, 1e-6f);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(WorldToRadarTests, SourceEngineCamera)
|
||||||
|
{
|
||||||
|
verify_world_to_radar_uses_camera_axes<source_engine::Camera, float>();
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(WorldToRadarTests, IWEngineCamera)
|
||||||
|
{
|
||||||
|
verify_world_to_radar_uses_camera_axes<iw_engine::Camera, float>();
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(WorldToRadarTests, FrostbiteEngineCamera)
|
||||||
|
{
|
||||||
|
verify_world_to_radar_uses_camera_axes<frostbite_engine::Camera, float>();
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(WorldToRadarTests, OpenGLEngineCamera)
|
||||||
|
{
|
||||||
|
verify_world_to_radar_uses_camera_axes<opengl_engine::Camera, float>();
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(WorldToRadarTests, UnityEngineCamera)
|
||||||
|
{
|
||||||
|
verify_world_to_radar_uses_camera_axes<unity_engine::Camera, float>();
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(WorldToRadarTests, CryEngineCamera)
|
||||||
|
{
|
||||||
|
verify_world_to_radar_uses_camera_axes<cry_engine::Camera, float>();
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(WorldToRadarTests, RageEngineCamera)
|
||||||
|
{
|
||||||
|
verify_world_to_radar_uses_camera_axes<rage_engine::Camera, float>();
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(WorldToRadarTests, UnrealEngineCamera)
|
||||||
|
{
|
||||||
|
verify_world_to_radar_uses_camera_axes<unreal_engine::Camera, double>();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user