mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 07:03:25 +00:00
removed inline functions
This commit is contained in:
@@ -8,49 +8,17 @@
|
|||||||
namespace omath::iw_engine
|
namespace omath::iw_engine
|
||||||
{
|
{
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
inline Vector3<float> ForwardVector(const ViewAngles& angles)
|
Vector3<float> ForwardVector(const ViewAngles& angles);
|
||||||
{
|
|
||||||
const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsForward);
|
|
||||||
|
|
||||||
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
inline Vector3<float> RightVector(const ViewAngles& angles)
|
Vector3<float> RightVector(const ViewAngles& angles);
|
||||||
{
|
|
||||||
const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsRight);
|
|
||||||
|
|
||||||
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
inline Vector3<float> UpVector(const ViewAngles& angles)
|
Vector3<float> UpVector(const ViewAngles& angles);
|
||||||
{
|
|
||||||
const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsUp);
|
|
||||||
|
|
||||||
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
|
[[nodiscard]] Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3<float>& cam_origin);
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] inline Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3<float>& cam_origin)
|
|
||||||
{
|
|
||||||
return MatCameraView(ForwardVector(angles), RightVector(angles), UpVector(angles), cam_origin);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
inline Mat4x4 CalcPerspectiveProjectionMatrix(const float fieldOfView, const float aspectRatio, const float near,
|
Mat4x4 CalcPerspectiveProjectionMatrix(float fieldOfView, float aspectRatio, float near, float far);
|
||||||
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
|
} // namespace omath::source
|
||||||
|
|||||||
@@ -8,47 +8,17 @@
|
|||||||
namespace omath::opengl_engine
|
namespace omath::opengl_engine
|
||||||
{
|
{
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
inline Vector3<float> ForwardVector(const ViewAngles& angles)
|
Vector3<float> ForwardVector(const ViewAngles& angles);
|
||||||
{
|
|
||||||
const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsForward);
|
|
||||||
|
|
||||||
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
inline Vector3<float> RightVector(const ViewAngles& angles)
|
Vector3<float> RightVector(const ViewAngles& angles);
|
||||||
{
|
|
||||||
const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsRight);
|
|
||||||
|
|
||||||
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
inline Vector3<float> UpVector(const ViewAngles& angles)
|
Vector3<float> UpVector(const ViewAngles& angles);
|
||||||
{
|
|
||||||
const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsUp);
|
|
||||||
|
|
||||||
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
|
[[nodiscard]] Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3<float>& cam_origin);
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] inline Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3<float>& cam_origin)
|
|
||||||
{
|
|
||||||
return MatCameraView<float, MatStoreType::COLUMN_MAJOR>(-ForwardVector(angles), RightVector(angles), UpVector(angles), cam_origin);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
inline Mat4x4 CalcPerspectiveProjectionMatrix(const float fieldOfView, const float aspectRatio, const float near,
|
Mat4x4 CalcPerspectiveProjectionMatrix(float fieldOfView, float aspectRatio, float near, float far);
|
||||||
const float far)
|
} // namespace omath::opengl_engine
|
||||||
{
|
|
||||||
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},
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -7,50 +7,17 @@
|
|||||||
namespace omath::source_engine
|
namespace omath::source_engine
|
||||||
{
|
{
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
inline Vector3<float> ForwardVector(const ViewAngles& angles)
|
Vector3<float> ForwardVector(const ViewAngles& angles);
|
||||||
{
|
|
||||||
const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsForward);
|
|
||||||
|
|
||||||
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
inline Vector3<float> RightVector(const ViewAngles& angles)
|
Vector3<float> RightVector(const ViewAngles& angles);
|
||||||
{
|
|
||||||
const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsRight);
|
|
||||||
|
|
||||||
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
inline Vector3<float> UpVector(const ViewAngles& angles)
|
Vector3<float> UpVector(const ViewAngles& angles);
|
||||||
{
|
|
||||||
const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsUp);
|
|
||||||
|
|
||||||
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
|
[[nodiscard]] Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3<float>& cam_origin);
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] inline Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3<float>& cam_origin)
|
|
||||||
{
|
|
||||||
return MatCameraView(ForwardVector(angles), RightVector(angles), UpVector(angles), cam_origin);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
inline Mat4x4 CalcPerspectiveProjectionMatrix(const float fieldOfView, const float aspectRatio, const float near,
|
Mat4x4 CalcPerspectiveProjectionMatrix(float fieldOfView, float aspectRatio, float near, float far);
|
||||||
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
|
} // namespace omath::source
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
target_sources(omath PRIVATE Camera.cpp)
|
target_sources(omath PRIVATE Camera.cpp Formulas.cpp)
|
||||||
47
source/engines/iw_engine/Formulas.cpp
Normal file
47
source/engines/iw_engine/Formulas.cpp
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
//
|
||||||
|
// Created by Vlad on 3/19/2025.
|
||||||
|
//
|
||||||
|
#include "omath/engines/iw_engine/Formulas.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
namespace omath::iw_engine
|
||||||
|
{
|
||||||
|
|
||||||
|
Vector3<float> 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<float> 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<float> 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<float>& 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
|
||||||
@@ -1 +1 @@
|
|||||||
target_sources(omath PRIVATE Camera.cpp)
|
target_sources(omath PRIVATE Camera.cpp Formulas.cpp)
|
||||||
46
source/engines/opengl_engine/Formulas.cpp
Normal file
46
source/engines/opengl_engine/Formulas.cpp
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
//
|
||||||
|
// Created by Vlad on 3/19/2025.
|
||||||
|
//
|
||||||
|
#include "omath/engines/opengl_engine/Formulas.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
namespace omath::opengl_engine
|
||||||
|
{
|
||||||
|
|
||||||
|
Vector3<float> 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<float> 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<float> 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<float>& cam_origin)
|
||||||
|
{
|
||||||
|
return MatCameraView<float, MatStoreType::COLUMN_MAJOR>(-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
|
||||||
@@ -1 +1 @@
|
|||||||
target_sources(omath PRIVATE Camera.cpp)
|
target_sources(omath PRIVATE Camera.cpp Formulas.cpp)
|
||||||
49
source/engines/source_engine/Formulas.cpp
Normal file
49
source/engines/source_engine/Formulas.cpp
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
//
|
||||||
|
// Created by Vlad on 3/19/2025.
|
||||||
|
//
|
||||||
|
#include <omath/engines/source_engine/Formulas.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
namespace omath::source_engine
|
||||||
|
{
|
||||||
|
Vector3<float> 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<float> 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<float> 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<float>& 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
|
||||||
Reference in New Issue
Block a user