From 3db0a3bd325fc1645bed8d69b3922c66411855e4 Mon Sep 17 00:00:00 2001 From: frank Date: Tue, 27 Jun 2023 14:33:14 -0400 Subject: [PATCH] set invert Y to default for Box class, add support for any size GLM vector to JSON library --- src/Box.hpp | 10 +++++----- src/Configuration.hpp | 26 ++++++++++++++++++++------ 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/Box.hpp b/src/Box.hpp index cfd3262..5f6a114 100644 --- a/src/Box.hpp +++ b/src/Box.hpp @@ -35,20 +35,20 @@ class Box : public SDL_FRect private: - bool invert_y_state = false; + bool invert_y_state = true; public: /*! * Construct a Box object by giving a corner coordinate (top left if Y-axis is not inverted, bottom left otherwise) and * size (as width, height). The invert_y argument indicates that the Y-coordinate increases from the bottom of the screen - * to the top rather than the default case where it increases from the top to the bottom. + * to the top (like in OpenGL) rather than from the top to the bottom (like in Pygame). * * @param corner top left coordinate in the x, y axis * @param size size of the box in width and height * @param invert_y if true, y-coordinates increase as they move up on the screen, rather than decrease */ - Box(const glm::vec2& corner = {0, 0}, const glm::vec2& size = {0, 0}, bool invert_y = false); + Box(const glm::vec2& corner = {0.0f, 0.0f}, const glm::vec2& size = {0.0f, 0.0f}, bool invert_y = true); /*! * Construct a Box object lfrom float arguments: x, y, width, height. If invert_y is set, the Y-axis increases from bottom to @@ -62,7 +62,7 @@ public: * @param height size of the y-dimension * @param invert_y if true, y-coordinates increase as they move up on the screen, rather than decrease */ - Box(float x, float y, float width, float height, bool invert_y = false); + Box(float x, float y, float width, float height, bool invert_y = true); /*! * Construct a ::Box object by passing an SDL_Rect struct, which is of the form {x, y, w, h} and limited to int arguments. @@ -70,7 +70,7 @@ public: * @param rect see SDL's rect documentation http://doc.here/sdlwiki/SDL_FRect.html * @param invert_y if true, y-coordinates increase as they move up on the screen, rather than decrease */ - Box(const SDL_Rect& rect, bool invert_y = false); + Box(const SDL_Rect& rect, bool invert_y = true); void invert_y(bool); bool inverted_y() const; diff --git a/src/Configuration.hpp b/src/Configuration.hpp index 630f27a..fd6a847 100644 --- a/src/Configuration.hpp +++ b/src/Configuration.hpp @@ -170,20 +170,34 @@ public: }; -/* Extend GLM so nlohmann::json can read and write glm::vec2 */ +/* Extend GLM so nlohmann::json can read and write glm::vec */ namespace glm { - template - void to_json(nlohmann::json& j, const vec<2, T, defaultp>& v) + template + void to_json(nlohmann::json& j, const vec& v) { - j = nlohmann::json{v.x, v.y}; + if constexpr (dimensions == 2) { + j = nlohmann::json{v.x, v.y}; + } + else if constexpr (dimensions == 3) { + j = nlohmann::json{v.x, v.y, v.z}; + } + else if constexpr (dimensions == 4) { + j = nlohmann::json{v.x, v.y, v.z, v.w}; + } } - template - void from_json(const nlohmann::json& j, vec<2, T, defaultp>& v) + template + void from_json(const nlohmann::json& j, vec& v) { j.at(0).get_to(v.x); j.at(1).get_to(v.y); + if constexpr (dimensions > 2) { + j.at(2).get_to(v.z); + } + if constexpr (dimensions > 3) { + j.at(3).get_to(v.w); + } } }