Add Pose support for yml

This commit is contained in:
Georg Hagen
2024-10-21 17:54:48 +02:00
parent 3b3eb3d86f
commit 0bde92291d
3 changed files with 38 additions and 4 deletions

View File

@@ -8,6 +8,7 @@
#include "Math/Math.hpp"
#include "Math/AABB.hpp"
#include "Math/Pose.hpp"
#include <ryml.hpp>
#include <ryml_std.hpp>
#include <c4/format.hpp>
@@ -50,10 +51,13 @@ namespace c4
m[1][3], m[2][3], m[3][3]);
}
template<class T>
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<class T>
size_t to_chars(ryml::substr buf, const OpenVulkano::Math::Pose<T>& 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<class T>
bool from_chars(ryml::csubstr buf, OpenVulkano::Math::Vector2<T>* v)
{
@@ -114,10 +118,16 @@ namespace c4
return ret != ryml::yml::npos;
}
template<class T>
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<class T>
bool from_chars(ryml::csubstr buf, OpenVulkano::Math::Pose<T>* 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;
}
}

View File

@@ -8,6 +8,7 @@
#include "Base/UUID.hpp"
#include "Math/AABB.hpp"
#include "Math/Pose.hpp"
#include <yaml-cpp/yaml.h>
#include <fmt/format.h>
#include <c4/format.hpp>
@@ -51,4 +52,23 @@ namespace YAML
return false;
}
};
template<>
struct convert<OpenVulkano::Math::PoseF>
{
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;
}
};
}

View File

@@ -51,12 +51,16 @@ namespace OpenVulkano::Math
[[nodiscard]] const Quaternion<T>& GetOrientation() const { return m_orientation; }
[[nodiscard]] Quaternion<T>& GetOrientation() { return m_orientation; }
void SetOrientation(const Math::Quaternion<T>& orientation) { m_orientation = orientation; }
void SetOrientation(const Math::Vector3_SIMD<T>& eulerAngle) { m_orientation = Math::Utils::qua(eulerAngle); }
[[nodiscard]] const Vector3_SIMD<T>& GetPosition() const { return m_position; }
[[nodiscard]] Vector3_SIMD<T>& GetPosition() { return m_position; }
void SetPosition(const Math::Vector3_SIMD<T>& pos) { m_position = pos; }
[[nodiscard]] Pose<T> Interpolate(const Pose<T>& otherPose, T mixFactor) const