From 832c2ea5eff9234dbf06fc981511384987658ed3 Mon Sep 17 00:00:00 2001 From: Orange Date: Wed, 19 Mar 2025 20:07:44 +0300 Subject: [PATCH] removed inline functions --- include/omath/engines/iw_engine/Formulas.hpp | 42 ++-------------- .../omath/engines/opengl_engine/Formulas.hpp | 42 +++------------- .../omath/engines/source_engine/Formulas.hpp | 43 ++-------------- source/engines/iw_engine/CMakeLists.txt | 2 +- source/engines/iw_engine/Formulas.cpp | 47 ++++++++++++++++++ source/engines/opengl_engine/CMakeLists.txt | 2 +- source/engines/opengl_engine/Formulas.cpp | 46 +++++++++++++++++ source/engines/source_engine/CMakeLists.txt | 2 +- source/engines/source_engine/Formulas.cpp | 49 +++++++++++++++++++ 9 files changed, 161 insertions(+), 114 deletions(-) create mode 100644 source/engines/iw_engine/Formulas.cpp create mode 100644 source/engines/opengl_engine/Formulas.cpp create mode 100644 source/engines/source_engine/Formulas.cpp diff --git a/include/omath/engines/iw_engine/Formulas.hpp b/include/omath/engines/iw_engine/Formulas.hpp index c98e727..1249c98 100644 --- a/include/omath/engines/iw_engine/Formulas.hpp +++ b/include/omath/engines/iw_engine/Formulas.hpp @@ -8,49 +8,17 @@ namespace omath::iw_engine { [[nodiscard]] - inline Vector3 ForwardVector(const ViewAngles& angles) - { - const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsForward); - - return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)}; - } + Vector3 ForwardVector(const ViewAngles& angles); [[nodiscard]] - inline Vector3 RightVector(const ViewAngles& angles) - { - const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsRight); - - return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)}; - } + Vector3 RightVector(const ViewAngles& angles); [[nodiscard]] - inline Vector3 UpVector(const ViewAngles& angles) - { - const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsUp); + Vector3 UpVector(const ViewAngles& angles); - return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)}; - } - - [[nodiscard]] inline Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3& cam_origin) - { - return MatCameraView(ForwardVector(angles), RightVector(angles), UpVector(angles), cam_origin); - } + [[nodiscard]] Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3& cam_origin); [[nodiscard]] - inline Mat4x4 CalcPerspectiveProjectionMatrix(const float fieldOfView, const float aspectRatio, const float near, - const float far) - { - // NOTE: Need magic number to fix fov calculation, since source inherit Quake proj matrix calculation - constexpr auto kMultiplyFactor = 0.75f; - const float fovHalfTan = std::tan(angles::DegreesToRadians(fieldOfView) / 2.f) * kMultiplyFactor; - - return - { - {1.f / (aspectRatio * fovHalfTan), 0, 0, 0}, - {0, 1.f / fovHalfTan, 0, 0}, - {0, 0, (far + near) / (far - near), -(2.f * far * near) / (far - near)}, - {0, 0, 1, 0}, - }; - } + Mat4x4 CalcPerspectiveProjectionMatrix(float fieldOfView, float aspectRatio, float near, float far); } // namespace omath::source diff --git a/include/omath/engines/opengl_engine/Formulas.hpp b/include/omath/engines/opengl_engine/Formulas.hpp index b63ffdc..e0e9741 100644 --- a/include/omath/engines/opengl_engine/Formulas.hpp +++ b/include/omath/engines/opengl_engine/Formulas.hpp @@ -8,47 +8,17 @@ namespace omath::opengl_engine { [[nodiscard]] - inline Vector3 ForwardVector(const ViewAngles& angles) - { - const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsForward); - - return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)}; - } + Vector3 ForwardVector(const ViewAngles& angles); [[nodiscard]] - inline Vector3 RightVector(const ViewAngles& angles) - { - const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsRight); - - return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)}; - } + Vector3 RightVector(const ViewAngles& angles); [[nodiscard]] - inline Vector3 UpVector(const ViewAngles& angles) - { - const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsUp); + Vector3 UpVector(const ViewAngles& angles); - return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)}; - } - - [[nodiscard]] inline Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3& cam_origin) - { - return MatCameraView(-ForwardVector(angles), RightVector(angles), UpVector(angles), cam_origin); - } + [[nodiscard]] Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3& cam_origin); [[nodiscard]] - inline Mat4x4 CalcPerspectiveProjectionMatrix(const float fieldOfView, const float aspectRatio, const float near, - const float far) - { - const float fovHalfTan = std::tan(angles::DegreesToRadians(fieldOfView) / 2.f); - - return { - {1.f / (aspectRatio * fovHalfTan), 0, 0, 0}, - {0, 1.f / (fovHalfTan), 0, 0}, - {0, 0, -(far + near) / (far - near), -(2.f * far * near) / (far - near)}, - {0, 0, -1, 0}, - - }; - } -} \ No newline at end of file + Mat4x4 CalcPerspectiveProjectionMatrix(float fieldOfView, float aspectRatio, float near, float far); +} // namespace omath::opengl_engine diff --git a/include/omath/engines/source_engine/Formulas.hpp b/include/omath/engines/source_engine/Formulas.hpp index 549d16a..d47d2b6 100644 --- a/include/omath/engines/source_engine/Formulas.hpp +++ b/include/omath/engines/source_engine/Formulas.hpp @@ -7,50 +7,17 @@ namespace omath::source_engine { [[nodiscard]] - inline Vector3 ForwardVector(const ViewAngles& angles) - { - const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsForward); - - return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)}; - } + Vector3 ForwardVector(const ViewAngles& angles); [[nodiscard]] - inline Vector3 RightVector(const ViewAngles& angles) - { - const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsRight); - - return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)}; - } + Vector3 RightVector(const ViewAngles& angles); [[nodiscard]] - inline Vector3 UpVector(const ViewAngles& angles) - { - const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsUp); + Vector3 UpVector(const ViewAngles& angles); - return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)}; - } - - [[nodiscard]] inline Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3& cam_origin) - { - return MatCameraView(ForwardVector(angles), RightVector(angles), UpVector(angles), cam_origin); - } + [[nodiscard]] Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3& cam_origin); [[nodiscard]] - inline Mat4x4 CalcPerspectiveProjectionMatrix(const float fieldOfView, const float aspectRatio, const float near, - const float far) - { - // NOTE: Need magic number to fix fov calculation, since source inherit Quake proj matrix calculation - constexpr auto kMultiplyFactor = 0.75f; - - const float fovHalfTan = std::tan(angles::DegreesToRadians(fieldOfView) / 2.f) * kMultiplyFactor; - - return { - {1.f / (aspectRatio * fovHalfTan), 0, 0, 0}, - {0, 1.f / (fovHalfTan), 0, 0}, - {0, 0, (far + near) / (far - near), -(2.f * far * near) / (far - near)}, - {0, 0, 1, 0}, - - }; - } + Mat4x4 CalcPerspectiveProjectionMatrix(float fieldOfView, float aspectRatio, float near, float far); } // namespace omath::source diff --git a/source/engines/iw_engine/CMakeLists.txt b/source/engines/iw_engine/CMakeLists.txt index 0abf868..0153efa 100644 --- a/source/engines/iw_engine/CMakeLists.txt +++ b/source/engines/iw_engine/CMakeLists.txt @@ -1 +1 @@ -target_sources(omath PRIVATE Camera.cpp) \ No newline at end of file +target_sources(omath PRIVATE Camera.cpp Formulas.cpp) \ No newline at end of file diff --git a/source/engines/iw_engine/Formulas.cpp b/source/engines/iw_engine/Formulas.cpp new file mode 100644 index 0000000..0561b43 --- /dev/null +++ b/source/engines/iw_engine/Formulas.cpp @@ -0,0 +1,47 @@ +// +// Created by Vlad on 3/19/2025. +// +#include "omath/engines/iw_engine/Formulas.hpp" + + +namespace omath::iw_engine +{ + + Vector3 ForwardVector(const ViewAngles& angles) + { + const auto vec = MatRotation(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); + + 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); + + return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)}; + } + Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3& cam_origin) + { + return MatCameraView(ForwardVector(angles), RightVector(angles), UpVector(angles), cam_origin); + } + Mat4x4 CalcPerspectiveProjectionMatrix(const float fieldOfView, const float aspectRatio, const float near, + const float far) + { + // NOTE: Need magic number to fix fov calculation, since source inherit Quake proj matrix calculation + constexpr auto kMultiplyFactor = 0.75f; + const float fovHalfTan = std::tan(angles::DegreesToRadians(fieldOfView) / 2.f) * kMultiplyFactor; + + return { + {1.f / (aspectRatio * fovHalfTan), 0, 0, 0}, + {0, 1.f / fovHalfTan, 0, 0}, + {0, 0, (far + near) / (far - near), -(2.f * far * near) / (far - near)}, + {0, 0, 1, 0}, + }; + } +} // namespace omath::iw_engine diff --git a/source/engines/opengl_engine/CMakeLists.txt b/source/engines/opengl_engine/CMakeLists.txt index 0abf868..0153efa 100644 --- a/source/engines/opengl_engine/CMakeLists.txt +++ b/source/engines/opengl_engine/CMakeLists.txt @@ -1 +1 @@ -target_sources(omath PRIVATE Camera.cpp) \ No newline at end of file +target_sources(omath PRIVATE Camera.cpp Formulas.cpp) \ No newline at end of file diff --git a/source/engines/opengl_engine/Formulas.cpp b/source/engines/opengl_engine/Formulas.cpp new file mode 100644 index 0000000..c2fa698 --- /dev/null +++ b/source/engines/opengl_engine/Formulas.cpp @@ -0,0 +1,46 @@ +// +// Created by Vlad on 3/19/2025. +// +#include "omath/engines/opengl_engine/Formulas.hpp" + + +namespace omath::opengl_engine +{ + + Vector3 ForwardVector(const ViewAngles& angles) + { + const auto vec = MatRotation(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); + + 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); + + return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)}; + } + Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3& cam_origin) + { + return MatCameraView(-ForwardVector(angles), RightVector(angles), + UpVector(angles), cam_origin); + } + Mat4x4 CalcPerspectiveProjectionMatrix(const float fieldOfView, const float aspectRatio, const float near, + const float far) + { + const float fovHalfTan = std::tan(angles::DegreesToRadians(fieldOfView) / 2.f); + + return { + {1.f / (aspectRatio * fovHalfTan), 0, 0, 0}, + {0, 1.f / (fovHalfTan), 0, 0}, + {0, 0, -(far + near) / (far - near), -(2.f * far * near) / (far - near)}, + {0, 0, -1, 0}, + + }; + } +} // namespace omath::opengl_engine diff --git a/source/engines/source_engine/CMakeLists.txt b/source/engines/source_engine/CMakeLists.txt index 0abf868..0153efa 100644 --- a/source/engines/source_engine/CMakeLists.txt +++ b/source/engines/source_engine/CMakeLists.txt @@ -1 +1 @@ -target_sources(omath PRIVATE Camera.cpp) \ No newline at end of file +target_sources(omath PRIVATE Camera.cpp Formulas.cpp) \ No newline at end of file diff --git a/source/engines/source_engine/Formulas.cpp b/source/engines/source_engine/Formulas.cpp new file mode 100644 index 0000000..1bbb90a --- /dev/null +++ b/source/engines/source_engine/Formulas.cpp @@ -0,0 +1,49 @@ +// +// Created by Vlad on 3/19/2025. +// +#include + + +namespace omath::source_engine +{ + Vector3 ForwardVector(const ViewAngles& angles) + { + const auto vec = MatRotation(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); + + 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); + + return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)}; + } + + Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3& cam_origin) + { + return MatCameraView(ForwardVector(angles), RightVector(angles), UpVector(angles), cam_origin); + } + Mat4x4 CalcPerspectiveProjectionMatrix(const float fieldOfView, const float aspectRatio, const float near, + const float far) + { + // NOTE: Need magic number to fix fov calculation, since source inherit Quake proj matrix calculation + constexpr auto kMultiplyFactor = 0.75f; + + const float fovHalfTan = std::tan(angles::DegreesToRadians(fieldOfView) / 2.f) * kMultiplyFactor; + + return { + {1.f / (aspectRatio * fovHalfTan), 0, 0, 0}, + {0, 1.f / (fovHalfTan), 0, 0}, + {0, 0, (far + near) / (far - near), -(2.f * far * near) / (far - near)}, + {0, 0, 1, 0}, + + }; + } +} // namespace omath::source_engine