mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-14 07:23:26 +00:00
Adds Unreal Engine math implementations
Adds Unreal Engine-specific implementations for camera and projectile prediction calculations. This includes: - Defining constants and data types tailored for Unreal Engine's coordinate system and conventions. - Implementing functions for calculating forward, right, and up vectors, view matrices, and perspective projection matrices. - Providing camera trait for look-at angle calculations and projection matrix generation. - Implements projectile prediction traits and utilities.
This commit is contained in:
27
source/engines/unreal_engine/traits/camera_trait.cpp
Normal file
27
source/engines/unreal_engine/traits/camera_trait.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// Created by Vlad on 8/11/2025.
|
||||
//
|
||||
#include "omath/engines/unreal_engine/traits/camera_trait.hpp"
|
||||
|
||||
namespace omath::unreal_engine
|
||||
{
|
||||
|
||||
ViewAngles CameraTrait::calc_look_at_angle(const Vector3<float>& cam_origin, const Vector3<float>& look_at) noexcept
|
||||
{
|
||||
const auto distance = cam_origin.distance_to(look_at);
|
||||
const auto delta = cam_origin - look_at;
|
||||
|
||||
return {PitchAngle::from_radians(-std::asin(delta.z / distance)),
|
||||
YawAngle::from_radians(std::atan2(delta.x, delta.y)), RollAngle::from_radians(0.f)};
|
||||
}
|
||||
Mat4X4 CameraTrait::calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
|
||||
{
|
||||
return unreal_engine::calc_view_matrix(angles, cam_origin);
|
||||
}
|
||||
Mat4X4 CameraTrait::calc_projection_matrix(const projection::FieldOfView& fov,
|
||||
const projection::ViewPort& view_port, const float near,
|
||||
const float far) noexcept
|
||||
{
|
||||
return calc_perspective_projection_matrix(fov.as_degrees(), view_port.aspect_ratio(), near, far);
|
||||
}
|
||||
} // namespace omath::unity_engine
|
||||
Reference in New Issue
Block a user