Skip to content

Commit

Permalink
feat: more formatters
Browse files Browse the repository at this point in the history
  • Loading branch information
qudix committed Nov 5, 2024
1 parent 50299fa commit a1c6e92
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 10 deletions.
37 changes: 27 additions & 10 deletions include/RE/N/NiQuaternion.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,14 @@ namespace RE
class NiQuaternion
{
public:
float w{ 1.0f };
float x{ 0.0f };
float y{ 0.0f };
float z{ 0.0f };
NiQuaternion() noexcept = default;

NiQuaternion() {}
NiQuaternion(float a_w, float a_x, float a_y, float a_z) noexcept :
w(a_w), x(a_x), y(a_y), z(a_z) {}

NiQuaternion(float w, float x, float y, float z) :
w(w), x(x), y(y), z(z) {}

NiQuaternion(const NiMatrix3& mat)
NiQuaternion(const NiMatrix3& a_mat) noexcept
{
FromMatrix(mat);
FromMatrix(a_mat);
}

static NiQuaternion Slerp(const NiQuaternion& prev, NiQuaternion next, float t)
Expand Down Expand Up @@ -260,6 +255,28 @@ namespace RE
{
return { -w, -x, -y, -z };
}

// members
float w{ 1.0F }; // 00
float x{ 0.0F }; // 04
float y{ 0.0F }; // 08
float z{ 0.0F }; // 0C
};
static_assert(sizeof(NiQuaternion) == 0x10);
}

template <>
struct std::formatter<RE::NiQuaternion>
{
template <class ParseContext>
constexpr auto parse(ParseContext& a_ctx)
{
return a_ctx.begin();
}

template <class FormatContext>
constexpr auto format(const RE::NiQuaternion& a_quat, FormatContext& a_ctx) const
{
return format_to(a_ctx.out(), "({}, {}, {}, {})", a_quat.w, a_quat.x, a_quat.y, a_quat.z);
}
};
16 changes: 16 additions & 0 deletions include/RE/N/NiRect.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,19 @@ namespace RE
static_assert(sizeof(NiRect<std::int32_t>) == 0x10);
static_assert(sizeof(NiRect<std::uint32_t>) == 0x10);
}

template <class T>
struct std::formatter<RE::NiRect<T>>
{
template <class ParseContext>
constexpr auto parse(ParseContext& a_ctx)
{
return a_ctx.begin();
}

template <class FormatContext>
constexpr auto format(const RE::NiRect<T>& a_rect, FormatContext& a_ctx) const
{
return format_to(a_ctx.out(), "({}, {}, {}, {})", a_rect.left, a_rect.right, a_rect.top, a_rect.bottom);
}
};

0 comments on commit a1c6e92

Please sign in to comment.