From 0bde92291d619262b4f33be58f5843da472b14c0 Mon Sep 17 00:00:00 2001 From: Georg Hagen Date: Mon, 21 Oct 2024 17:54:48 +0200 Subject: [PATCH] Add Pose support for yml --- openVulkanoCpp/Extensions/RymlConverters.hpp | 18 +++++++++++++---- .../Extensions/YamlCppConverters.hpp | 20 +++++++++++++++++++ openVulkanoCpp/Math/Pose.hpp | 4 ++++ 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/openVulkanoCpp/Extensions/RymlConverters.hpp b/openVulkanoCpp/Extensions/RymlConverters.hpp index 63ac35c..a22848e 100644 --- a/openVulkanoCpp/Extensions/RymlConverters.hpp +++ b/openVulkanoCpp/Extensions/RymlConverters.hpp @@ -8,6 +8,7 @@ #include "Math/Math.hpp" #include "Math/AABB.hpp" +#include "Math/Pose.hpp" #include #include #include @@ -50,10 +51,13 @@ namespace c4 m[1][3], m[2][3], m[3][3]); } - template - size_t to_chars(ryml::substr buf, const OpenVulkano::Math::AABB& bbox) + inline size_t to_chars(ryml::substr buf, const OpenVulkano::Math::AABB& bbox) { return ryml::format(buf, "({},{},{}),({},{},{})", bbox.min.x, bbox.min.y, bbox.min.z, bbox.max.x, bbox.max.y, bbox.max.z); } + template + size_t to_chars(ryml::substr buf, const OpenVulkano::Math::Pose& pose) + { return ryml::format(buf, "({},{},{}),({},{},{},{})", pose.m_position.x, pose.m_position.y, pose.m_position.z, pose.m_orientation.x, pose.m_orientation.y, pose.m_orientation.z, pose.m_orientation.w); } + template bool from_chars(ryml::csubstr buf, OpenVulkano::Math::Vector2* v) { @@ -114,10 +118,16 @@ namespace c4 return ret != ryml::yml::npos; } - template - bool from_chars(ryml::csubstr buf, OpenVulkano::Math::AABB* bbox) + inline bool from_chars(ryml::csubstr buf, OpenVulkano::Math::AABB* bbox) { size_t ret = ryml::unformat(buf, "({},{},{}),({},{},{})", bbox->min.x, bbox->min.y, bbox->min.z, bbox->max.x, bbox->max.y, bbox->max.z); return ret != ryml::yml::npos; } + + template + bool from_chars(ryml::csubstr buf, OpenVulkano::Math::Pose* pose) + { + size_t ret = ryml::unformat(buf, "({},{},{}),({},{},{},{})", pose->m_position.x, pose->m_position.y, pose->m_position.z, pose->m_orientation.x, pose->m_orientation.y, pose->m_orientation.z, pose->m_orientation.w); + return ret != ryml::yml::npos; + } } \ No newline at end of file diff --git a/openVulkanoCpp/Extensions/YamlCppConverters.hpp b/openVulkanoCpp/Extensions/YamlCppConverters.hpp index 5bb5b2e..ce9e52b 100644 --- a/openVulkanoCpp/Extensions/YamlCppConverters.hpp +++ b/openVulkanoCpp/Extensions/YamlCppConverters.hpp @@ -8,6 +8,7 @@ #include "Base/UUID.hpp" #include "Math/AABB.hpp" +#include "Math/Pose.hpp" #include #include #include @@ -51,4 +52,23 @@ namespace YAML return false; } }; + + template<> + struct convert + { + static Node encode(const OpenVulkano::Math::PoseF& pose) + { + return Node(fmt::format("({},{},{}),({},{},{},{})", pose.GetPosition().x, pose.GetPosition().y, pose.GetPosition().z, pose.GetOrientation().x, pose.GetOrientation().y, pose.GetOrientation().z, pose.GetOrientation().w)); + } + + static bool decode(const Node& node, OpenVulkano::Math::PoseF& pose) + { + if (node.IsScalar()) + { + size_t ret = c4::unformat(c4::to_csubstr(node.Scalar().c_str()), "({},{},{}),({},{},{},{})", pose.GetPosition().x, pose.GetPosition().y, pose.GetPosition().z, pose.GetOrientation().x, pose.GetOrientation().y, pose.GetOrientation().z, pose.GetOrientation().w); + return ret != c4::csubstr::npos; + } + return false; + } + }; } diff --git a/openVulkanoCpp/Math/Pose.hpp b/openVulkanoCpp/Math/Pose.hpp index 6b1ae35..907b4bf 100644 --- a/openVulkanoCpp/Math/Pose.hpp +++ b/openVulkanoCpp/Math/Pose.hpp @@ -51,12 +51,16 @@ namespace OpenVulkano::Math [[nodiscard]] const Quaternion& GetOrientation() const { return m_orientation; } + [[nodiscard]] Quaternion& GetOrientation() { return m_orientation; } + void SetOrientation(const Math::Quaternion& orientation) { m_orientation = orientation; } void SetOrientation(const Math::Vector3_SIMD& eulerAngle) { m_orientation = Math::Utils::qua(eulerAngle); } [[nodiscard]] const Vector3_SIMD& GetPosition() const { return m_position; } + [[nodiscard]] Vector3_SIMD& GetPosition() { return m_position; } + void SetPosition(const Math::Vector3_SIMD& pos) { m_position = pos; } [[nodiscard]] Pose Interpolate(const Pose& otherPose, T mixFactor) const