mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 07:03:25 +00:00
added func
added rotation matrix for opengl
This commit is contained in:
@@ -3,9 +3,9 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "omath/angles.hpp"
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include "omath/angles.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace omath
|
namespace omath
|
||||||
@@ -17,7 +17,7 @@ namespace omath
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<class Type = float, Type min = Type(0), Type max = Type(360), AngleFlags flags = AngleFlags::Normalized>
|
template<class Type = float, Type min = Type(0), Type max = Type(360), AngleFlags flags = AngleFlags::Normalized>
|
||||||
requires std::is_arithmetic_v<Type>
|
requires std::is_arithmetic_v<Type>
|
||||||
class Angle
|
class Angle
|
||||||
{
|
{
|
||||||
Type m_angle;
|
Type m_angle;
|
||||||
@@ -34,6 +34,7 @@ namespace omath
|
|||||||
std::unreachable();
|
std::unreachable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr static Angle FromDegrees(const Type& degrees)
|
constexpr static Angle FromDegrees(const Type& degrees)
|
||||||
@@ -42,7 +43,6 @@ namespace omath
|
|||||||
}
|
}
|
||||||
constexpr Angle() : m_angle(0)
|
constexpr Angle() : m_angle(0)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr static Angle FromRadians(const Type& degrees)
|
constexpr static Angle FromRadians(const Type& degrees)
|
||||||
@@ -149,4 +149,4 @@ namespace omath
|
|||||||
return Angle{-m_angle};
|
return Angle{-m_angle};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
} // namespace omath
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ namespace omath::opengl_engine
|
|||||||
|
|
||||||
[[nodiscard]] Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3<float>& cam_origin);
|
[[nodiscard]] Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3<float>& cam_origin);
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
Mat4x4 RotationMatrix(const ViewAngles& angles);
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Mat4x4 CalcPerspectiveProjectionMatrix(float fieldOfView, float aspectRatio, float near, float far);
|
Mat4x4 CalcPerspectiveProjectionMatrix(float fieldOfView, float aspectRatio, float near, float far);
|
||||||
|
|||||||
@@ -9,6 +9,10 @@ namespace omath::source_engine
|
|||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Vector3<float> ForwardVector(const ViewAngles& angles);
|
Vector3<float> ForwardVector(const ViewAngles& angles);
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
Mat4x4 RotationMatrix(const ViewAngles& angles);
|
||||||
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Vector3<float> RightVector(const ViewAngles& angles);
|
Vector3<float> RightVector(const ViewAngles& angles);
|
||||||
|
|
||||||
@@ -20,4 +24,6 @@ namespace omath::source_engine
|
|||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Mat4x4 CalcPerspectiveProjectionMatrix(float fieldOfView, float aspectRatio, float near, float far);
|
Mat4x4 CalcPerspectiveProjectionMatrix(float fieldOfView, float aspectRatio, float near, float far);
|
||||||
|
|
||||||
|
|
||||||
} // namespace omath::source
|
} // namespace omath::source
|
||||||
|
|||||||
@@ -9,19 +9,19 @@ namespace omath::opengl_engine
|
|||||||
|
|
||||||
Vector3<float> ForwardVector(const ViewAngles& angles)
|
Vector3<float> ForwardVector(const ViewAngles& angles)
|
||||||
{
|
{
|
||||||
const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsForward);
|
const auto vec = RotationMatrix(angles) * MatColumnFromVector<float, MatStoreType::COLUMN_MAJOR>(kAbsForward);
|
||||||
|
|
||||||
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
|
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
|
||||||
}
|
}
|
||||||
Vector3<float> RightVector(const ViewAngles& angles)
|
Vector3<float> RightVector(const ViewAngles& angles)
|
||||||
{
|
{
|
||||||
const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsRight);
|
const auto vec = RotationMatrix(angles) * MatColumnFromVector<float, MatStoreType::COLUMN_MAJOR>(kAbsRight);
|
||||||
|
|
||||||
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
|
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
|
||||||
}
|
}
|
||||||
Vector3<float> UpVector(const ViewAngles& angles)
|
Vector3<float> UpVector(const ViewAngles& angles)
|
||||||
{
|
{
|
||||||
const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsUp);
|
const auto vec = RotationMatrix(angles) * MatColumnFromVector<float, MatStoreType::COLUMN_MAJOR>(kAbsUp);
|
||||||
|
|
||||||
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
|
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
|
||||||
}
|
}
|
||||||
@@ -30,6 +30,12 @@ namespace omath::opengl_engine
|
|||||||
return MatCameraView<float, MatStoreType::COLUMN_MAJOR>(-ForwardVector(angles), RightVector(angles),
|
return MatCameraView<float, MatStoreType::COLUMN_MAJOR>(-ForwardVector(angles), RightVector(angles),
|
||||||
UpVector(angles), cam_origin);
|
UpVector(angles), cam_origin);
|
||||||
}
|
}
|
||||||
|
Mat4x4 RotationMatrix(const ViewAngles& angles)
|
||||||
|
{
|
||||||
|
return MatRotationAxisZ<float, MatStoreType::COLUMN_MAJOR>(angles.roll) *
|
||||||
|
MatRotationAxisY<float, MatStoreType::COLUMN_MAJOR>(angles.yaw) *
|
||||||
|
MatRotationAxisX<float, MatStoreType::COLUMN_MAJOR>(angles.pitch);
|
||||||
|
}
|
||||||
Mat4x4 CalcPerspectiveProjectionMatrix(const float fieldOfView, const float aspectRatio, const float near,
|
Mat4x4 CalcPerspectiveProjectionMatrix(const float fieldOfView, const float aspectRatio, const float near,
|
||||||
const float far)
|
const float far)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,20 +8,25 @@ namespace omath::source_engine
|
|||||||
{
|
{
|
||||||
Vector3<float> ForwardVector(const ViewAngles& angles)
|
Vector3<float> 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)};
|
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<float> RightVector(const ViewAngles& angles)
|
Vector3<float> 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)};
|
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
|
||||||
}
|
}
|
||||||
Vector3<float> UpVector(const ViewAngles& angles)
|
Vector3<float> 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)};
|
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#include <source_location>
|
#include <source_location>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
|
#include <format>
|
||||||
#if defined(OMATH_USE_AVX2) && defined(__i386__) && defined(__x86_64__)
|
#if defined(OMATH_USE_AVX2) && defined(__i386__) && defined(__x86_64__)
|
||||||
#include <immintrin.h>
|
#include <immintrin.h>
|
||||||
#include <format>
|
#include <format>
|
||||||
|
|||||||
Reference in New Issue
Block a user