Add CoordinateSystem enum
This commit is contained in:
65
openVulkanoCpp/Math/CoordinateSystem.hpp
Normal file
65
openVulkanoCpp/Math/CoordinateSystem.hpp
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
#include "Math.hpp"
|
||||
#include <optional>
|
||||
#include <magic_enum/magic_enum.hpp>
|
||||
|
||||
namespace OpenVulkano::Math
|
||||
{
|
||||
class CoordinateSystem final
|
||||
{
|
||||
public:
|
||||
enum System: uint8_t
|
||||
{
|
||||
RIGHT_HANDED_Y_UP = 0,
|
||||
RIGHT_HANDED_Z_UP,
|
||||
LEFT_HANDED_Y_UP,
|
||||
LEFT_HANDED_Z_UP
|
||||
};
|
||||
|
||||
enum class Handedness: uint8_t { Right = 0, Left };
|
||||
|
||||
enum class UpAxis: uint8_t { Y, Z };
|
||||
|
||||
constexpr CoordinateSystem(System system = RIGHT_HANDED_Y_UP): m_system(system) {}
|
||||
|
||||
constexpr CoordinateSystem(Handedness handedness, UpAxis up): m_system(static_cast<System>(static_cast<uint8_t>(handedness) << 1 | static_cast<uint8_t>(up))) {}
|
||||
|
||||
[[nodiscard]] constexpr std::string_view GetName() const
|
||||
{
|
||||
return magic_enum::enum_name(m_system);
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr static std::optional<CoordinateSystem> GetFromName(std::string_view name)
|
||||
{
|
||||
auto result = magic_enum::enum_cast<System>(name);
|
||||
if (result.has_value()) return CoordinateSystem(result.value());
|
||||
return {};
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr Handedness GetHandedness() const { return static_cast<Handedness>(m_system >> 1); }
|
||||
|
||||
[[nodiscard]] constexpr UpAxis GetUpAxis() const { return static_cast<UpAxis>(m_system & 1); }
|
||||
|
||||
[[nodiscard]] constexpr operator System() const { return m_system; }
|
||||
|
||||
[[nodiscard]] constexpr operator Handedness() const { return GetHandedness(); }
|
||||
|
||||
[[nodiscard]] constexpr operator UpAxis() const { return GetUpAxis(); }
|
||||
|
||||
[[nodiscard]] constexpr auto operator <=>(const CoordinateSystem& other) const { return m_system <=> other.m_system; }
|
||||
[[nodiscard]] constexpr auto operator <=>(const System& other) const { return m_system <=> other; }
|
||||
|
||||
[[nodiscard]] constexpr bool operator ==(const CoordinateSystem& other) const { return m_system == other.m_system; }
|
||||
[[nodiscard]] constexpr bool operator ==(const System& other) const { return m_system == other; }
|
||||
|
||||
private:
|
||||
System m_system;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user