From 1601f3cbc8a5e65b24074f102317da2df7e142e0 Mon Sep 17 00:00:00 2001 From: Orange Date: Wed, 16 Apr 2025 13:33:08 +0300 Subject: [PATCH] added func added rotation matrix for opengl --- include/omath/angle.hpp | 8 ++++---- include/omath/engines/opengl_engine/formulas.hpp | 2 ++ include/omath/engines/source_engine/formulas.hpp | 6 ++++++ source/engines/opengl_engine/formulas.cpp | 12 +++++++++--- source/engines/source_engine/formulas.cpp | 11 ++++++++--- .../projectile_prediction/proj_pred_engine_avx2.cpp | 2 +- 6 files changed, 30 insertions(+), 11 deletions(-) diff --git a/include/omath/angle.hpp b/include/omath/angle.hpp index 07d5510..11d36d9 100644 --- a/include/omath/angle.hpp +++ b/include/omath/angle.hpp @@ -3,9 +3,9 @@ // #pragma once -#include "omath/angles.hpp" #include #include +#include "omath/angles.hpp" namespace omath @@ -17,7 +17,7 @@ namespace omath }; template - requires std::is_arithmetic_v + requires std::is_arithmetic_v class Angle { Type m_angle; @@ -34,6 +34,7 @@ namespace omath std::unreachable(); } } + public: [[nodiscard]] constexpr static Angle FromDegrees(const Type& degrees) @@ -42,7 +43,6 @@ namespace omath } constexpr Angle() : m_angle(0) { - } [[nodiscard]] constexpr static Angle FromRadians(const Type& degrees) @@ -149,4 +149,4 @@ namespace omath return Angle{-m_angle}; } }; -} +} // namespace omath diff --git a/include/omath/engines/opengl_engine/formulas.hpp b/include/omath/engines/opengl_engine/formulas.hpp index d9dcfe7..7f24ef6 100644 --- a/include/omath/engines/opengl_engine/formulas.hpp +++ b/include/omath/engines/opengl_engine/formulas.hpp @@ -18,6 +18,8 @@ namespace omath::opengl_engine [[nodiscard]] Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3& cam_origin); + [[nodiscard]] + Mat4x4 RotationMatrix(const ViewAngles& angles); [[nodiscard]] Mat4x4 CalcPerspectiveProjectionMatrix(float fieldOfView, float aspectRatio, float near, float far); diff --git a/include/omath/engines/source_engine/formulas.hpp b/include/omath/engines/source_engine/formulas.hpp index fd6415e..817ee14 100644 --- a/include/omath/engines/source_engine/formulas.hpp +++ b/include/omath/engines/source_engine/formulas.hpp @@ -9,6 +9,10 @@ namespace omath::source_engine [[nodiscard]] Vector3 ForwardVector(const ViewAngles& angles); + [[nodiscard]] + Mat4x4 RotationMatrix(const ViewAngles& angles); + + [[nodiscard]] Vector3 RightVector(const ViewAngles& angles); @@ -20,4 +24,6 @@ namespace omath::source_engine [[nodiscard]] Mat4x4 CalcPerspectiveProjectionMatrix(float fieldOfView, float aspectRatio, float near, float far); + + } // namespace omath::source diff --git a/source/engines/opengl_engine/formulas.cpp b/source/engines/opengl_engine/formulas.cpp index 8162bdb..3bd7e47 100644 --- a/source/engines/opengl_engine/formulas.cpp +++ b/source/engines/opengl_engine/formulas.cpp @@ -9,19 +9,19 @@ namespace omath::opengl_engine Vector3 ForwardVector(const ViewAngles& angles) { - const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsForward); + const auto vec = RotationMatrix(angles) * MatColumnFromVector(kAbsForward); return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)}; } Vector3 RightVector(const ViewAngles& angles) { - const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsRight); + const auto vec = RotationMatrix(angles) * MatColumnFromVector(kAbsRight); return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)}; } Vector3 UpVector(const ViewAngles& angles) { - const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsUp); + const auto vec = RotationMatrix(angles) * MatColumnFromVector(kAbsUp); return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)}; } @@ -30,6 +30,12 @@ namespace omath::opengl_engine return MatCameraView(-ForwardVector(angles), RightVector(angles), UpVector(angles), cam_origin); } + Mat4x4 RotationMatrix(const ViewAngles& angles) + { + return MatRotationAxisZ(angles.roll) * + MatRotationAxisY(angles.yaw) * + MatRotationAxisX(angles.pitch); + } Mat4x4 CalcPerspectiveProjectionMatrix(const float fieldOfView, const float aspectRatio, const float near, const float far) { diff --git a/source/engines/source_engine/formulas.cpp b/source/engines/source_engine/formulas.cpp index f037cad..5dcca88 100644 --- a/source/engines/source_engine/formulas.cpp +++ b/source/engines/source_engine/formulas.cpp @@ -8,20 +8,25 @@ namespace omath::source_engine { Vector3 ForwardVector(const ViewAngles& angles) { - const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsForward); + const auto vec = RotationMatrix(angles) * MatColumnFromVector(kAbsForward); return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)}; } + Mat4x4 RotationMatrix(const ViewAngles& angles) + { + return MatRotationAxisZ(angles.yaw) * MatRotationAxisY(angles.pitch) * MatRotationAxisX(angles.roll); + } + Vector3 RightVector(const ViewAngles& angles) { - const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsRight); + const auto vec = RotationMatrix(angles) * MatColumnFromVector(kAbsRight); return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)}; } Vector3 UpVector(const ViewAngles& angles) { - const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsUp); + const auto vec = RotationMatrix(angles) * MatColumnFromVector(kAbsUp); return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)}; } diff --git a/source/projectile_prediction/proj_pred_engine_avx2.cpp b/source/projectile_prediction/proj_pred_engine_avx2.cpp index 632f5b6..48d2b69 100644 --- a/source/projectile_prediction/proj_pred_engine_avx2.cpp +++ b/source/projectile_prediction/proj_pred_engine_avx2.cpp @@ -5,7 +5,7 @@ #include #include - +#include #if defined(OMATH_USE_AVX2) && defined(__i386__) && defined(__x86_64__) #include #include