diff --git a/dev/CMakeLists.txt b/dev/CMakeLists.txt index 4895ce0..61704c9 100644 --- a/dev/CMakeLists.txt +++ b/dev/CMakeLists.txt @@ -45,7 +45,8 @@ else() endif() add_custom_target(CopyHeader - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/olcPixelGameEngine3.h ${REPO_ROOT_DIR}/olcPixelGameEngine3.h + BYPRODUCTS ${REPO_ROOT_DIR}/olcPixelGameEngine3.h + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_BINARY_DIR}/olcPixelGameEngine3.h ${REPO_ROOT_DIR}/olcPixelGameEngine3.h DEPENDS olcPixelGameEngine3.h ) diff --git a/dev/src/vector2d.h b/dev/src/vector2d.h index 5b6a88b..90d71cc 100644 --- a/dev/src/vector2d.h +++ b/dev/src/vector2d.h @@ -195,6 +195,26 @@ namespace olc { return { static_cast(this->x), static_cast(this->y) }; } + + template + auto& get() & { + return std::get(xy); + } + + template + const auto& get() const & { + return std::get(xy); + } + + template + auto&& get() && { + return std::get(xy); + } + + template + const auto& get() const && { + return std::get(xy); + } }; // Multiplication operator overloads between vectors and scalars, and vectors and vectors @@ -356,6 +376,16 @@ namespace olc typedef v_2d vf2d; typedef v_2d vd2d; } + +namespace std { + template + struct tuple_size> : std::integral_constant {}; + + + template + struct tuple_element> : tuple_element> {}; +} + #define PGE_VECTOR2D_DECLARED 1 #endif //! END DECLARATION \ No newline at end of file diff --git a/dev/src/vector4d.h b/dev/src/vector4d.h index 3661b50..618d69e 100644 --- a/dev/src/vector4d.h +++ b/dev/src/vector4d.h @@ -183,6 +183,26 @@ namespace olc { return { static_cast(this->x), static_cast(this->y), static_cast(this->z), static_cast(this->w) }; } + + template + auto& get() & { + return std::get(xyzw); + } + + template + const auto& get() const & { + return std::get(xyzw); + } + + template + auto&& get() && { + return std::get(xyzw); + } + + template + const auto& get() const && { + return std::get(xyzw); + } }; // Multiplication operator overloads between vectors and scalars, and vectors and vectors @@ -343,6 +363,16 @@ namespace olc typedef v_4d vf4d; typedef v_4d vd4d; } + +namespace std { + template + struct tuple_size> : std::integral_constant {}; + + + template + struct tuple_element> : tuple_element> {}; +} + #define PGE_VECTOR4D_DECLARED 1 #endif //! END DECLARATION \ No newline at end of file diff --git a/examples/olcPGE3_3DCube.cpp b/examples/olcPGE3_3DCube.cpp index 1839d6d..ce127eb 100644 --- a/examples/olcPGE3_3DCube.cpp +++ b/examples/olcPGE3_3DCube.cpp @@ -1,7 +1,7 @@ /* olc::PixelGameEngine3 Example - olc::SanityCube!!! - Draws teh infamous olc::SanityCube using the hardware 3D rendering capabilities. + Draws the infamous olc::SanityCube using the hardware 3D rendering capabilities. Licenced under the OLC-3 License */ @@ -12,6 +12,8 @@ #define OLC_PGE3_APPLICATION #include "../olcPixelGameEngine3.h" +#include + // Example application demonstrating basic 3D rendering. This class // overrides the olc::PixelGameEngine base class by implementing // the OnUserCreate() and OnUserUpdate() functions @@ -123,7 +125,11 @@ class Example_3DCube : public olc::PixelGameEngine draw.Line({ 0,0,0 }, { 0, 1, 0 }, olc::Colour::GREEN); draw.Line({ 0,0,0 }, { 0, 0, 1 }, olc::Colour::BLUE); - draw.StringProp({ 4, 4 }, "+X: Right\n-X: Left\n+Y: Up\n-Y: Down\n+Z: Q\n-Z: A\nSPIN: Space", olc::Colour::BLACK); + // Decompose the quaternion to demonstrate the structured binding support + const auto [x, y, z, w] = vViewTranslate; + draw.String({ 4, 4 }, std::format("X:{: 4.1f} Y:{: 4.1f} Z:{: 4.1f} W:{: 4.1f}", x, y, z, w), olc::Colour::BLACK); + draw.StringProp({ 4, 14 }, "+X: Right\n-X: Left\n+Y: Up\n-Y: Down\n+Z: Q\n-Z: A\nSPIN: Space", olc::Colour::BLACK); + // Successful frame return true; diff --git a/examples/olcPGE3_WorldTransform.cpp b/examples/olcPGE3_WorldTransform.cpp index 699b6bc..bdf4748 100644 --- a/examples/olcPGE3_WorldTransform.cpp +++ b/examples/olcPGE3_WorldTransform.cpp @@ -132,6 +132,12 @@ class Example_WorldTransform: public olc::PixelGameEngine // Get Mouse in "transformed world" space olc::vf2d vMouseWorld = draw.ScreenToWorld(vMouseScreen); + // Unpack the mouse coordinate to x and y just for fun and to serve as a compilation test for unpacking v_2d objects + const auto& [x1, y1] = vMouseWorld; + auto& [x2, y2] = vMouseWorld; + auto [x3, y3] = vMouseWorld; + auto&& [x4, y4] = vMouseWorld; + // Draw Status draw.WorldReset(); draw.StringProp({ 8, 300 }, "Offset: Arrow Keys, Scale: Shift & Arrow Keys, Rotate: Q/A, SPACE: Reset"); diff --git a/olcPixelGameEngine3.h b/olcPixelGameEngine3.h index 2b919d7..e92f859 100644 --- a/olcPixelGameEngine3.h +++ b/olcPixelGameEngine3.h @@ -849,6 +849,26 @@ namespace olc { return { static_cast(this->x), static_cast(this->y) }; } + + template + auto& get() & { + return std::get(xy); + } + + template + const auto& get() const & { + return std::get(xy); + } + + template + auto&& get() && { + return std::get(xy); + } + + template + const auto& get() const && { + return std::get(xy); + } }; // Multiplication operator overloads between vectors and scalars, and vectors and vectors @@ -1010,6 +1030,16 @@ namespace olc typedef v_2d vf2d; typedef v_2d vd2d; } + +namespace std { + template + struct tuple_size> : std::integral_constant {}; + + + template + struct tuple_element> : tuple_element> {}; +} + #define PGE_VECTOR2D_DECLARED 1 #endif @@ -1182,6 +1212,26 @@ namespace olc { return { static_cast(this->x), static_cast(this->y), static_cast(this->z), static_cast(this->w) }; } + + template + auto& get() & { + return std::get(xyzw); + } + + template + const auto& get() const & { + return std::get(xyzw); + } + + template + auto&& get() && { + return std::get(xyzw); + } + + template + const auto& get() const && { + return std::get(xyzw); + } }; // Multiplication operator overloads between vectors and scalars, and vectors and vectors @@ -1342,6 +1392,16 @@ namespace olc typedef v_4d vf4d; typedef v_4d vd4d; } + +namespace std { + template + struct tuple_size> : std::integral_constant {}; + + + template + struct tuple_element> : tuple_element> {}; +} + #define PGE_VECTOR4D_DECLARED 1 #endif