Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 2 additions & 11 deletions include/omath/engines/iw_engine/camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,9 @@
#pragma once
#include "omath/engines/iw_engine/constants.hpp"
#include "omath/projection/camera.hpp"
#include "traits/camera_trait.hpp"

namespace omath::iw_engine
{
class Camera final : public projection::Camera<Mat4X4, ViewAngles>
{
public:
Camera(const Vector3<float>& position, const ViewAngles& view_angles, const projection::ViewPort& view_port,
const Angle<float, 0.f, 180.f, AngleFlags::Clamped>& fov, float near, float far);
void look_at(const Vector3<float>& target) override;

protected:
[[nodiscard]] Mat4X4 calc_view_matrix() const noexcept override;
[[nodiscard]] Mat4X4 calc_projection_matrix() const noexcept override;
};
using Camera = projection::Camera<Mat4X4, ViewAngles, CameraTrait>;
} // namespace omath::iw_engine
24 changes: 24 additions & 0 deletions include/omath/engines/iw_engine/traits/camera_trait.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// Created by Vlad on 8/10/2025.
//

#pragma once
#include "omath/engines/iw_engine/constants.hpp"
#include "omath/projection/camera.hpp"

namespace omath::iw_engine
{
class CameraTrait final
{
public:
[[nodiscard]]
static ViewAngles calc_look_at_angle(const Vector3<float>& cam_origin, const Vector3<float>& look_at) noexcept;

[[nodiscard]]
static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept;
[[nodiscard]]
static Mat4X4 calc_projection_matrix(const projection::FieldOfView& fov, const projection::ViewPort& view_port,
float near, float far) noexcept;
};

} // namespace omath::iw_engine
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,26 @@
#include "omath/projectile_prediction/target.hpp"
#include <optional>

namespace omath::projectile_prediction::traits
namespace omath::iw_engine
{
class IwEngineTrait final
class PredEngineTrait final
{
public:
constexpr static Vector3<float> predict_projectile_position(const Projectile& projectile, const float pitch,
const float yaw, const float time,
const float gravity) noexcept
constexpr static Vector3<float> predict_projectile_position(const projectile_prediction::Projectile& projectile,
const float pitch, const float yaw,
const float time, const float gravity) noexcept
{
auto current_pos = projectile.m_origin
+ iw_engine::forward_vector({iw_engine::PitchAngle::from_degrees(-pitch),
iw_engine::YawAngle::from_degrees(yaw),
iw_engine::RollAngle::from_degrees(0)})
+ forward_vector({PitchAngle::from_degrees(-pitch), YawAngle::from_degrees(yaw),
RollAngle::from_degrees(0)})
* projectile.m_launch_speed * time;
current_pos.z -= (gravity * projectile.m_gravity_scale) * (time * time) * 0.5f;

return current_pos;
}
[[nodiscard]]
static constexpr Vector3<float> predict_target_position(const Target& target, const float time,
const float gravity) noexcept
static constexpr Vector3<float> predict_target_position(const projectile_prediction::Target& target,
const float time, const float gravity) noexcept
{
auto predicted = target.m_origin + target.m_velocity * time;

Expand All @@ -50,7 +49,7 @@ namespace omath::projectile_prediction::traits
}

[[nodiscard]]
static Vector3<float> calc_viewpoint_from_angles(const Projectile& projectile,
static Vector3<float> calc_viewpoint_from_angles(const projectile_prediction::Projectile& projectile,
Vector3<float> predicted_target_position,
const std::optional<float> projectile_pitch) noexcept
{
Expand All @@ -77,4 +76,4 @@ namespace omath::projectile_prediction::traits
return angles::radians_to_degrees(std::atan2(delta.y, delta.x));
};
};
} // namespace omath::projectile_prediction::traits
} // namespace omath::iw_engine
11 changes: 2 additions & 9 deletions include/omath/engines/opengl_engine/camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,9 @@
#pragma once
#include "omath/engines/opengl_engine/constants.hpp"
#include "omath/projection/camera.hpp"
#include "traits/camera_trait.hpp"

namespace omath::opengl_engine
{
class Camera final : public projection::Camera<Mat4X4, ViewAngles>
{
public:
Camera(const Vector3<float>& position, const ViewAngles& view_angles, const projection::ViewPort& view_port,
const Angle<float, 0.f, 180.f, AngleFlags::Clamped>& fov, float near, float far);
void look_at(const Vector3<float>& target) override;
[[nodiscard]] Mat4X4 calc_view_matrix() const noexcept override;
[[nodiscard]] Mat4X4 calc_projection_matrix() const noexcept override;
};
using Camera = projection::Camera<Mat4X4, ViewAngles, CameraTrait>;
} // namespace omath::opengl_engine
24 changes: 24 additions & 0 deletions include/omath/engines/opengl_engine/traits/camera_trait.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// Created by Vlad on 8/10/2025.
//

#pragma once
#include "omath/engines/opengl_engine/constants.hpp"
#include "omath/projection/camera.hpp"

namespace omath::opengl_engine
{
class CameraTrait final
{
public:
[[nodiscard]]
static ViewAngles calc_look_at_angle(const Vector3<float>& cam_origin, const Vector3<float>& look_at) noexcept;

[[nodiscard]]
static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept;
[[nodiscard]]
static Mat4X4 calc_projection_matrix(const projection::FieldOfView& fov, const projection::ViewPort& view_port,
float near, float far) noexcept;
};

} // namespace omath::opengl_engine
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,26 @@
#include "omath/projectile_prediction/target.hpp"
#include <optional>

namespace omath::projectile_prediction::traits
namespace omath::opengl_engine
{
class OpenGlEngineTrait final
class PredEngineTrait final
{
public:
constexpr static Vector3<float> predict_projectile_position(const Projectile& projectile, const float pitch,
const float yaw, const float time,
const float gravity) noexcept
constexpr static Vector3<float> predict_projectile_position(const projectile_prediction::Projectile& projectile,
const float pitch, const float yaw,
const float time, const float gravity) noexcept
{
auto current_pos = projectile.m_origin
+ opengl_engine::forward_vector({opengl_engine::PitchAngle::from_degrees(-pitch),
opengl_engine::YawAngle::from_degrees(yaw),
opengl_engine::RollAngle::from_degrees(0)})
+ forward_vector({PitchAngle::from_degrees(-pitch), YawAngle::from_degrees(yaw),
RollAngle::from_degrees(0)})
* projectile.m_launch_speed * time;
current_pos.y -= (gravity * projectile.m_gravity_scale) * (time * time) * 0.5f;

return current_pos;
}
[[nodiscard]]
static constexpr Vector3<float> predict_target_position(const Target& target, const float time,
const float gravity) noexcept
static constexpr Vector3<float> predict_target_position(const projectile_prediction::Target& target,
const float time, const float gravity) noexcept
{
auto predicted = target.m_origin + target.m_velocity * time;

Expand All @@ -49,7 +48,7 @@ namespace omath::projectile_prediction::traits
}

[[nodiscard]]
static Vector3<float> calc_viewpoint_from_angles(const Projectile& projectile,
static Vector3<float> calc_viewpoint_from_angles(const projectile_prediction::Projectile& projectile,
Vector3<float> predicted_target_position,
const std::optional<float> projectile_pitch) noexcept
{
Expand All @@ -76,4 +75,4 @@ namespace omath::projectile_prediction::traits
return angles::radians_to_degrees(std::atan2(delta.z, delta.x));
};
};
} // namespace omath::projectile_prediction::traits
} // namespace omath::opengl_engine
14 changes: 2 additions & 12 deletions include/omath/engines/source_engine/camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,8 @@
#pragma once
#include "omath/engines/source_engine/constants.hpp"
#include "omath/projection/camera.hpp"

#include "traits/camera_trait.hpp"
namespace omath::source_engine
{
class Camera final : public projection::Camera<Mat4X4, ViewAngles>
{
public:
Camera(const Vector3<float>& position, const ViewAngles& view_angles, const projection::ViewPort& view_port,
const Angle<float, 0.f, 180.f, AngleFlags::Clamped>& fov, float near, float far);
void look_at(const Vector3<float>& target) override;

protected:
[[nodiscard]] Mat4X4 calc_view_matrix() const noexcept override;
[[nodiscard]] Mat4X4 calc_projection_matrix() const noexcept override;
};
using Camera = projection::Camera<Mat4X4, ViewAngles, CameraTrait>;
} // namespace omath::source_engine
24 changes: 24 additions & 0 deletions include/omath/engines/source_engine/traits/camera_trait.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// Created by Vlad on 8/10/2025.
//

#pragma once
#include "omath/engines/source_engine/constants.hpp"
#include "omath/projection/camera.hpp"

namespace omath::source_engine
{
class CameraTrait final
{
public:
[[nodiscard]]
static ViewAngles calc_look_at_angle(const Vector3<float>& cam_origin, const Vector3<float>& look_at) noexcept;

[[nodiscard]]
static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept;
[[nodiscard]]
static Mat4X4 calc_projection_matrix(const projection::FieldOfView& fov, const projection::ViewPort& view_port,
float near, float far) noexcept;
};

} // namespace omath::source_engine
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,26 @@
#include "omath/projectile_prediction/target.hpp"
#include <optional>

namespace omath::projectile_prediction::traits
namespace omath::source_engine
{
class SourceEngineTrait final
class PredEngineTrait final
{
public:
constexpr static Vector3<float> predict_projectile_position(const Projectile& projectile, const float pitch,
const float yaw, const float time,
const float gravity) noexcept
constexpr static Vector3<float> predict_projectile_position(const projectile_prediction::Projectile& projectile,
const float pitch, const float yaw,
const float time, const float gravity) noexcept
{
auto current_pos = projectile.m_origin
+ source_engine::forward_vector({source_engine::PitchAngle::from_degrees(-pitch),
source_engine::YawAngle::from_degrees(yaw),
source_engine::RollAngle::from_degrees(0)})
+ forward_vector({PitchAngle::from_degrees(-pitch), YawAngle::from_degrees(yaw),
RollAngle::from_degrees(0)})
* projectile.m_launch_speed * time;
current_pos.z -= (gravity * projectile.m_gravity_scale) * (time * time) * 0.5f;

return current_pos;
}
[[nodiscard]]
static constexpr Vector3<float> predict_target_position(const Target& target, const float time,
const float gravity) noexcept
static constexpr Vector3<float> predict_target_position(const projectile_prediction::Target& target,
const float time, const float gravity) noexcept
{
auto predicted = target.m_origin + target.m_velocity * time;

Expand All @@ -50,7 +49,7 @@ namespace omath::projectile_prediction::traits
}

[[nodiscard]]
static Vector3<float> calc_viewpoint_from_angles(const Projectile& projectile,
static Vector3<float> calc_viewpoint_from_angles(const projectile_prediction::Projectile& projectile,
Vector3<float> predicted_target_position,
const std::optional<float> projectile_pitch) noexcept
{
Expand All @@ -77,4 +76,4 @@ namespace omath::projectile_prediction::traits
return angles::radians_to_degrees(std::atan2(delta.y, delta.x));
};
};
} // namespace omath::projectile_prediction::traits
} // namespace omath::source_engine
13 changes: 2 additions & 11 deletions include/omath/engines/unity_engine/camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,9 @@
#pragma once
#include "omath/engines/unity_engine/constants.hpp"
#include "omath/projection/camera.hpp"
#include "traits/camera_trait.hpp"

namespace omath::unity_engine
{
class Camera final : public projection::Camera<Mat4X4, ViewAngles>
{
public:
Camera(const Vector3<float>& position, const ViewAngles& view_angles, const projection::ViewPort& view_port,
const Angle<float, 0.f, 180.f, AngleFlags::Clamped>& fov, float near, float far);
void look_at(const Vector3<float>& target) override;

protected:
[[nodiscard]] Mat4X4 calc_view_matrix() const noexcept override;
[[nodiscard]] Mat4X4 calc_projection_matrix() const noexcept override;
};
using Camera = projection::Camera<Mat4X4, ViewAngles, CameraTrait>;
} // namespace omath::unity_engine
24 changes: 24 additions & 0 deletions include/omath/engines/unity_engine/traits/camera_trait.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// Created by Vlad on 8/10/2025.
//

#pragma once
#include "omath/engines/unity_engine/formulas.hpp"
#include "omath/projection/camera.hpp"

namespace omath::unity_engine
{
class CameraTrait final
{
public:
[[nodiscard]]
static ViewAngles calc_look_at_angle(const Vector3<float>& cam_origin, const Vector3<float>& look_at) noexcept;

[[nodiscard]]
static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept;
[[nodiscard]]
static Mat4X4 calc_projection_matrix(const projection::FieldOfView& fov, const projection::ViewPort& view_port,
float near, float far) noexcept;
};

} // namespace omath::unity_engine
Loading
Loading