mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-14 07:23:26 +00:00
Merge pull request #32 from orange-cpp/u/orange-cpp/examples
U/orange cpp/examples
This commit is contained in:
@@ -10,9 +10,10 @@ option(OMATH_THREAT_WARNING_AS_ERROR "Set highest level of warnings and force co
|
|||||||
option(OMATH_BUILD_AS_SHARED_LIBRARY "Build Omath as .so or .dll" OFF)
|
option(OMATH_BUILD_AS_SHARED_LIBRARY "Build Omath as .so or .dll" OFF)
|
||||||
option(OMATH_USE_AVX2 "Omath will use AVX2 to boost performance" ON)
|
option(OMATH_USE_AVX2 "Omath will use AVX2 to boost performance" ON)
|
||||||
option(OMATH_IMGUI_INTEGRATION "Omath will define method to convert omath types to imgui types" OFF)
|
option(OMATH_IMGUI_INTEGRATION "Omath will define method to convert omath types to imgui types" OFF)
|
||||||
|
option(OMATH_BUILD_EXAMPLES "Build example projects with you can learn & play" OFF)
|
||||||
|
|
||||||
if (OMATH_BUILD_AS_SHARED_LIBRARY)
|
if (OMATH_BUILD_AS_SHARED_LIBRARY)
|
||||||
add_library(omath SHARED source/Vector3.cpp)
|
add_library(omath SHARED source/Matrix.cpp)
|
||||||
else()
|
else()
|
||||||
add_library(omath STATIC source/Matrix.cpp)
|
add_library(omath STATIC source/Matrix.cpp)
|
||||||
endif()
|
endif()
|
||||||
@@ -49,6 +50,10 @@ if(OMATH_BUILD_TESTS)
|
|||||||
add_subdirectory(tests)
|
add_subdirectory(tests)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if (OMATH_BUILD_EXAMPLES)
|
||||||
|
add_subdirectory(examples)
|
||||||
|
endif()
|
||||||
|
|
||||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND OMATH_THREAT_WARNING_AS_ERROR)
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND OMATH_THREAT_WARNING_AS_ERROR)
|
||||||
target_compile_options(omath PRIVATE /W4 /WX)
|
target_compile_options(omath PRIVATE /W4 /WX)
|
||||||
elseif(OMATH_THREAT_WARNING_AS_ERROR)
|
elseif(OMATH_THREAT_WARNING_AS_ERROR)
|
||||||
|
|||||||
@@ -12,14 +12,14 @@
|
|||||||
Oranges's Math Library (omath) is a comprehensive, open-source library aimed at providing efficient, reliable, and versatile mathematical functions and algorithms. Developed primarily in C++, this library is designed to cater to a wide range of mathematical operations essential in scientific computing, engineering, and academic research.
|
Oranges's Math Library (omath) is a comprehensive, open-source library aimed at providing efficient, reliable, and versatile mathematical functions and algorithms. Developed primarily in C++, this library is designed to cater to a wide range of mathematical operations essential in scientific computing, engineering, and academic research.
|
||||||
|
|
||||||
## 👁🗨 Features
|
## 👁🗨 Features
|
||||||
- **Efficiency**: Optimized for performance, ensuring quick computations.
|
- **Efficiency**: Optimized for performance, ensuring quick computations using AVX2.
|
||||||
- **Versatility**: Includes a wide array of mathematical functions and algorithms.
|
- **Versatility**: Includes a wide array of mathematical functions and algorithms.
|
||||||
- **Ease of Use**: Simplified interface for convenient integration into various projects.
|
- **Ease of Use**: Simplified interface for convenient integration into various projects.
|
||||||
- **Projectile Prediction**: Projectile prediction engine with O(N) algo complexity, that can power you projectile aim-bot.
|
- **Projectile Prediction**: Projectile prediction engine with O(N) algo complexity, that can power you projectile aim-bot.
|
||||||
- **3D Projection**: No need to find view-projection matrix anymore you can make your own projection pipeline.
|
- **3D Projection**: No need to find view-projection matrix anymore you can make your own projection pipeline.
|
||||||
- **Collision Detection**: Production ready code to handle collision detection by using simple interfaces.
|
- **Collision Detection**: Production ready code to handle collision detection by using simple interfaces.
|
||||||
- **No Additional Dependencies**: No additional dependencies need to use OMath except unit test execution
|
- **No Additional Dependencies**: No additional dependencies need to use OMath except unit test execution
|
||||||
|
- **Ready for meta-programming**: Omath use templates for common types like Vectors, Matrixes etc, to handle all types!
|
||||||
## ⏬ Getting Started
|
## ⏬ Getting Started
|
||||||
### Prerequisites
|
### Prerequisites
|
||||||
- C++ Compiler
|
- C++ Compiler
|
||||||
|
|||||||
4
examples/CMakeLists.txt
Normal file
4
examples/CMakeLists.txt
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
project(examples)
|
||||||
|
|
||||||
|
add_executable(ExampleProjectionMatrixBuilder ExampleProjMatBuilder.cpp)
|
||||||
|
target_link_libraries(ExampleProjectionMatrixBuilder PRIVATE omath::omath)
|
||||||
40
examples/ExampleProjMatBuilder.cpp
Normal file
40
examples/ExampleProjMatBuilder.cpp
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
//
|
||||||
|
// Created by Vlad on 3/19/2025.
|
||||||
|
//
|
||||||
|
#include <iostream>
|
||||||
|
#include <omath/engines/opengl_engine/Camera.hpp>
|
||||||
|
#include <omath/engines/opengl_engine/Formulas.hpp>
|
||||||
|
#include <omath/projection/Camera.hpp>
|
||||||
|
#include <print>
|
||||||
|
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
std::println("OMATH Projection Matrix Builder");
|
||||||
|
|
||||||
|
float fov = 0;
|
||||||
|
float near = 0;
|
||||||
|
float far = 0;
|
||||||
|
float viewPortWidth = 0;
|
||||||
|
float viewPortHeight = 0;
|
||||||
|
|
||||||
|
std::print("Enter camera fov: ");
|
||||||
|
std::cin >> fov;
|
||||||
|
|
||||||
|
std::print("Enter camera z near: ");
|
||||||
|
std::cin >> near;
|
||||||
|
|
||||||
|
std::print("Enter camera z far: ");
|
||||||
|
std::cin >> far;
|
||||||
|
|
||||||
|
std::print("Enter camera screen width: ");
|
||||||
|
std::cin >> viewPortWidth;
|
||||||
|
|
||||||
|
std::print("Enter camera screen height: ");
|
||||||
|
std::cin >> viewPortHeight;
|
||||||
|
|
||||||
|
const auto mat =
|
||||||
|
omath::opengl_engine::CalcPerspectiveProjectionMatrix(fov, viewPortWidth / viewPortHeight, near, far);
|
||||||
|
|
||||||
|
std::print("{}", mat.ToString());
|
||||||
|
};
|
||||||
@@ -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