/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ #pragma once #define GLM_FORECE_DEPTH_ZERO_TO_ONE // TODO handle this better #include #include #include #include #include #include #include #include #include #include #include namespace OpenVulkano::Math { namespace Utils { using namespace glm; template>> constexpr T Radians(T degree) { constexpr T CONVERSION = std::numbers::pi_v / 180.0; return degree * CONVERSION; } template constexpr T Square(T val) { return val * val; } // Ensures that a given angle is between 0 and 2 pi template>> constexpr T NormalizeAngleRad(T angle) { constexpr T PIX2 = 2 * std::numbers::pi; while (angle < 0) { angle += PIX2; } while (angle >= PIX2) { angle -= PIX2; } return angle; } template constexpr void SortPair(T& e1, T& e2) { if (e1 > e2) std::swap(e1, e2); } template T maxVal(const glm::tvec3& vec) { return std::max(vec.x, std::max(vec.y, vec.z)); } template T maxVal(const glm::tvec4& vec) { return std::max(std::max(vec.x, vec.y), std::max(vec.z, vec.w)); } template T minVal(const glm::tvec3& vec) { return std::min(vec.x, std::min(vec.y, vec.z)); } template T minVal(const glm::tvec4& vec) { return std::min(std::min(vec.x, vec.y), std::min(vec.z, vec.w)); } } template using Matrix2_SIMD = glm::tmat2x2; template using Matrix3_SIMD = glm::tmat3x3; template using Matrix4_SIMD = glm::tmat4x4; template using Matrix2 = glm::tmat2x2; template using Matrix3 = glm::tmat3x3; template using Matrix4 = Matrix4_SIMD; //template using Matrix4 = glm::tmat4x4; typedef Matrix2 Matrix2f; typedef Matrix2 Matrix2d; typedef Matrix2 Matrix2i; typedef Matrix2 Matrix2l; typedef Matrix3 Matrix3f; typedef Matrix3 Matrix3d; typedef Matrix3 Matrix3i; typedef Matrix3 Matrix3l; typedef Matrix4 Matrix4f; typedef Matrix4 Matrix4d; typedef Matrix4 Matrix4i; typedef Matrix4 Matrix4l; typedef Matrix2_SIMD Matrix2f_SIMD; typedef Matrix2_SIMD Matrix2d_SIMD; typedef Matrix2_SIMD Matrix2i_SIMD; typedef Matrix2_SIMD Matrix2l_SIMD; typedef Matrix3_SIMD Matrix3f_SIMD; typedef Matrix3_SIMD Matrix3d_SIMD; typedef Matrix3_SIMD Matrix3i_SIMD; typedef Matrix3_SIMD Matrix3l_SIMD; typedef Matrix4_SIMD Matrix4f_SIMD; typedef Matrix4_SIMD Matrix4d_SIMD; typedef Matrix4_SIMD Matrix4i_SIMD; typedef Matrix4_SIMD Matrix4l_SIMD; template using Vector2_SIMD = glm::tvec2; template using Vector3_SIMD = glm::tvec3; template using Vector4_SIMD = glm::tvec4; template using Vector2 = glm::tvec2; template using Vector3 = glm::tvec3; template using Vector4 = Vector4_SIMD; //template using Vector4 = glm::tvec4; typedef Vector2 Vector2f; typedef Vector2 Vector2d; typedef Vector2 Vector2c; typedef Vector2 Vector2s; typedef Vector2 Vector2i; typedef Vector2 Vector2l; typedef Vector2 Vector2uc; typedef Vector2 Vector2us; typedef Vector2 Vector2ui; typedef Vector2 Vector2ul; typedef Vector3 Vector3f; typedef Vector3 Vector3d; typedef Vector3 Vector3c; typedef Vector3 Vector3s; typedef Vector3 Vector3i; typedef Vector3 Vector3l; typedef Vector3 Vector3uc; typedef Vector3 Vector3us; typedef Vector3 Vector3ui; typedef Vector3 Vector3ul; typedef Vector4 Vector4f; typedef Vector4 Vector4d; typedef Vector4 Vector4c; typedef Vector4 Vector4s; typedef Vector4 Vector4i; typedef Vector4 Vector4l; typedef Vector4 Vector4uc; typedef Vector4 Vector4us; typedef Vector4 Vector4ui; typedef Vector4 Vector4ul; typedef Vector2_SIMD Vector2f_SIMD; typedef Vector2_SIMD Vector2d_SIMD; typedef Vector2_SIMD Vector2c_SIMD; typedef Vector2_SIMD Vector2s_SIMD; typedef Vector2_SIMD Vector2i_SIMD; typedef Vector2_SIMD Vector2l_SIMD; typedef Vector2_SIMD Vector2uc_SIMD; typedef Vector2_SIMD Vector2us_SIMD; typedef Vector2_SIMD Vector2ui_SIMD; typedef Vector2_SIMD Vector2ul_SIMD; typedef Vector3_SIMD Vector3f_SIMD; typedef Vector3_SIMD Vector3d_SIMD; typedef Vector3_SIMD Vector3c_SIMD; typedef Vector3_SIMD Vector3s_SIMD; typedef Vector3_SIMD Vector3i_SIMD; typedef Vector3_SIMD Vector3l_SIMD; typedef Vector3_SIMD Vector3uc_SIMD; typedef Vector3_SIMD Vector3us_SIMD; typedef Vector3_SIMD Vector3ui_SIMD; typedef Vector3_SIMD Vector3ul_SIMD; typedef Vector4_SIMD Vector4f_SIMD; typedef Vector4_SIMD Vector4d_SIMD; typedef Vector4_SIMD Vector4c_SIMD; typedef Vector4_SIMD Vector4s_SIMD; typedef Vector4_SIMD Vector4i_SIMD; typedef Vector4_SIMD Vector4l_SIMD; typedef Vector4_SIMD Vector4uc_SIMD; typedef Vector4_SIMD Vector4us_SIMD; typedef Vector4_SIMD Vector4ui_SIMD; typedef Vector4_SIMD Vector4ul_SIMD; template using Quaternion = glm::tquat; typedef Quaternion QuaternionF; typedef Quaternion QuaternionD; typedef Quaternion QuaternionI; } template>> glm::vec operator / (const float lhs, const glm::vec& rhs) { return lhs / glm::vec(rhs); } template>> glm::vec operator * (const float lhs, const glm::vec& rhs) { return lhs * glm::vec(rhs); } template>> glm::vec operator * (const glm::vec& lhs, const T rhs) { return lhs * static_cast(rhs); }