diff --git a/doc/changelog.dox b/doc/changelog.dox index 306f6df1a..61646e7cb 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -66,7 +66,8 @@ See also: @subsubsection changelog-latest-new-primitives Primitives library - New @ref Primitives::circle3DSolid(), @ref Primitives::circle3DWireframe(), - @ref Primitives::coneSolid() and @ref Primitives::coneWireframe() + @ref Primitives::coneSolid(), @ref Primitives::coneWireframe(), + @ref Primitives::grid3DSolid() and @ref Primitives::grid3DWireframe() primitives @subsection changelog-latest-bugfixes Bug fixes diff --git a/doc/generated/primitives.cpp b/doc/generated/primitives.cpp index 0b1fee72c..a0e191cab 100644 --- a/doc/generated/primitives.cpp +++ b/doc/generated/primitives.cpp @@ -56,6 +56,7 @@ #include #include #include +#include #include #include #include @@ -96,6 +97,7 @@ struct PrimitiveVisualizer: Platform::WindowlessApplication { std::pair coneWireframe(); std::pair cubeWireframe(); std::pair cylinderWireframe(); + std::pair grid3DWireframe(); std::pair line3D(); std::pair planeWireframe(); std::pair uvSphereWireframe(); @@ -108,6 +110,7 @@ struct PrimitiveVisualizer: Platform::WindowlessApplication { std::pair coneSolid(); std::pair cubeSolid(); std::pair cylinderSolid(); + std::pair grid3DSolid(); std::pair icosphereSolid(); std::pair planeSolid(); std::pair uvSphereSolid(); @@ -257,6 +260,7 @@ int PrimitiveVisualizer::exec() { &PrimitiveVisualizer::coneWireframe, &PrimitiveVisualizer::cubeWireframe, &PrimitiveVisualizer::cylinderWireframe, + &PrimitiveVisualizer::grid3DWireframe, &PrimitiveVisualizer::line3D, &PrimitiveVisualizer::planeWireframe, &PrimitiveVisualizer::uvSphereWireframe}) @@ -337,6 +341,7 @@ int PrimitiveVisualizer::exec() { &PrimitiveVisualizer::coneSolid, &PrimitiveVisualizer::cubeSolid, &PrimitiveVisualizer::cylinderSolid, + &PrimitiveVisualizer::grid3DSolid, &PrimitiveVisualizer::icosphereSolid, &PrimitiveVisualizer::planeSolid, &PrimitiveVisualizer::uvSphereSolid}) @@ -421,6 +426,10 @@ std::pair PrimitiveVisualizer::cylinderWireframe return {Primitives::cylinderWireframe(1, 32, 1.0f), "cylinderwireframe.png"}; } +std::pair PrimitiveVisualizer::grid3DWireframe() { + return {Primitives::grid3DWireframe({5, 3}), "grid3dwireframe.png"}; +} + std::pair PrimitiveVisualizer::line3D() { auto line = Primitives::line3D(); MeshTools::transformPointsInPlace(Matrix4::translation(Vector3::xAxis(-1.0f))*Matrix4::scaling(Vector3::xScale(2.0f)), line.positions(0)); @@ -465,6 +474,10 @@ std::pair PrimitiveVisualizer::cylinderSolid() { return {Primitives::cylinderSolid(1, 12, 1.0f, Primitives::CylinderFlag::CapEnds), "cylindersolid.png"}; } +std::pair PrimitiveVisualizer::grid3DSolid() { + return {Primitives::grid3DSolid({5, 3}), "grid3dsolid.png"}; +} + std::pair PrimitiveVisualizer::icosphereSolid() { return {Primitives::icosphereSolid(1), "icospheresolid.png"}; } diff --git a/doc/primitives-grid3dsolid.png b/doc/primitives-grid3dsolid.png new file mode 100644 index 000000000..510c58f58 Binary files /dev/null and b/doc/primitives-grid3dsolid.png differ diff --git a/doc/primitives-grid3dwireframe.png b/doc/primitives-grid3dwireframe.png new file mode 100644 index 000000000..e8657cf9a Binary files /dev/null and b/doc/primitives-grid3dwireframe.png differ diff --git a/src/Magnum/Primitives/CMakeLists.txt b/src/Magnum/Primitives/CMakeLists.txt index 7ab1d453f..bc72d40d6 100644 --- a/src/Magnum/Primitives/CMakeLists.txt +++ b/src/Magnum/Primitives/CMakeLists.txt @@ -31,6 +31,7 @@ set(MagnumPrimitives_SRCS Cone.cpp Cube.cpp Cylinder.cpp + Grid.cpp Icosphere.cpp Line.cpp Plane.cpp @@ -48,6 +49,7 @@ set(MagnumPrimitives_HEADERS Cone.h Cube.h Cylinder.h + Grid.h Icosphere.h Line.h Plane.h diff --git a/src/Magnum/Primitives/Grid.cpp b/src/Magnum/Primitives/Grid.cpp new file mode 100644 index 000000000..5b59f9af7 --- /dev/null +++ b/src/Magnum/Primitives/Grid.cpp @@ -0,0 +1,108 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 + Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include "Grid.h" + +#include "Magnum/Mesh.h" +#include "Magnum/Math/Color.h" +#include "Magnum/Trade/MeshData3D.h" + +namespace Magnum { namespace Primitives { + +Trade::MeshData3D grid3DSolid(const Vector2i& subdivisions, const GridFlags flags) { + const Vector2i vertexCount = subdivisions + Vector2i{2}; + const Vector2i faceCount = subdivisions + Vector2i{1}; + + std::vector positions; + positions.reserve(vertexCount.product()); + for(Int y = 0; y != vertexCount.y(); ++y) + for(Int x = 0; x != vertexCount.x(); ++x) + positions.emplace_back((Vector2(x, y)/Vector2(faceCount))*2.0f - Vector2{1.0f}, 0.0f); + + std::vector indices; + indices.reserve(faceCount.product()*6); + for(Int y = 0; y != faceCount.y(); ++y) { + for(Int x = 0; x != faceCount.x(); ++x) { + /* 2--1 5 + | / /| + |/ / | + 0 3--4 */ + indices.insert(indices.end(), { + UnsignedInt(y*vertexCount.x() + x), + UnsignedInt((y + 1)*vertexCount.x() + x + 1), + UnsignedInt((y + 1)*vertexCount.x() + x + 0), + UnsignedInt(y*vertexCount.x() + x), + UnsignedInt(y*vertexCount.x() + x + 1), + UnsignedInt((y + 1)*vertexCount.x() + x + 1)}); + } + } + + std::vector> normals; + if(flags & GridFlag::GenerateNormals) + normals.emplace_back(positions.size(), Vector3::zAxis(1.0f)); + + std::vector> textureCoordinates; + if(flags & GridFlag::GenerateTextureCoords) { + textureCoordinates.emplace_back(); + textureCoordinates[0].reserve(positions.size()); + for(std::size_t i = 0; i != positions.size(); ++i) + textureCoordinates[0].emplace_back(positions[i].xy()*0.5f + Vector2{0.5f}); + } + + return Trade::MeshData3D{MeshPrimitive::Triangles, std::move(indices), {std::move(positions)}, std::move(normals), std::move(textureCoordinates), {}, nullptr}; +} + +Trade::MeshData3D grid3DWireframe(const Vector2i& subdivisions) { + const Vector2i vertexCount = subdivisions + Vector2i{2}; + const Vector2i faceCount = subdivisions + Vector2i{1}; + + std::vector positions; + positions.reserve(vertexCount.product()); + for(Int y = 0; y != vertexCount.y(); ++y) + for(Int x = 0; x != vertexCount.x(); ++x) + positions.emplace_back((Vector2(x, y)/Vector2(faceCount))*2.0f - Vector2{1.0f}, 0.0f); + + std::vector indices; + indices.reserve(vertexCount.y()*(vertexCount.x() - 1)*2 + + vertexCount.x()*(vertexCount.y() - 1)*2); + for(Int y = 0; y != vertexCount.y(); ++y) { + for(Int x = 0; x != vertexCount.x(); ++x) { + /* 3 7 + | | ... + 2 6 + 0--1 4--5 ... */ + if(x != vertexCount.x() - 1) indices.insert(indices.end(), { + UnsignedInt(y*vertexCount.x() + x), + UnsignedInt(y*vertexCount.x() + x + 1)}); + if(y != vertexCount.y() - 1) indices.insert(indices.end(), { + UnsignedInt(y*vertexCount.x() + x), + UnsignedInt((y + 1)*vertexCount.x() + x)}); + } + } + + return Trade::MeshData3D{MeshPrimitive::Lines, std::move(indices), {std::move(positions)}, {}, {}, {}, nullptr}; +} + +}} diff --git a/src/Magnum/Primitives/Grid.h b/src/Magnum/Primitives/Grid.h new file mode 100644 index 000000000..c049df981 --- /dev/null +++ b/src/Magnum/Primitives/Grid.h @@ -0,0 +1,101 @@ +#ifndef Magnum_Primitives_Grid_h +#define Magnum_Primitives_Grid_h +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 + Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +/** @file + * @brief Function @ref Magnum::Primitives::grid3DSolid(), @ref Magnum::Primitives::grid3DWireframe() + */ + +#include + +#include "Magnum/Magnum.h" +#include "Magnum/Math/Math.h" +#include "Magnum/Primitives/visibility.h" +#include "Magnum/Trade/Trade.h" + +namespace Magnum { namespace Primitives { + +/** +@brief Grid flag + +@see @ref GridFlags, @ref grid3DSolid() +*/ +enum class GridFlag: UnsignedByte { + /** Generate texture coordinates with origin in bottom left corner. */ + GenerateTextureCoords = 1 << 0, + + /** + * Generate normals inn positive Z direction. Disable if you'd be + * generating your own normals anyway (for example based on a heightmap). + */ + GenerateNormals = 1 << 1 +}; + +/** +@brief Grid flags + +@see @ref grid3DSolid() +*/ +typedef Containers::EnumSet GridFlags; + +CORRADE_ENUMSET_OPERATORS(GridFlags) + +/** +@brief 3D solid grid + +2x2 grid. Indexed @ref MeshPrimitive::Triangles with optional normals and +texture coordinates. + +@image html primitives-grid3dsolid.png + +The @p subdivisions parameter describes how many times the plane gets cut in +each direction. Specifying @cpp {0, 0} @ce will make the result an (indexed) +equivalent to @ref planeSolid(); @cpp {5, 3} @ce will make the grid have 6 +cells horizontally and 4 vertically. In particular, this is different from the +`subdivisions` parameter in @ref icosphereSolid(). +@see @ref grid3DWireframe() +*/ +MAGNUM_PRIMITIVES_EXPORT Trade::MeshData3D grid3DSolid(const Vector2i& subdivisions, GridFlags flags = GridFlag::GenerateNormals); + +/** +@brief 3D wireframe grid + +2x2 grid. Indexed @ref MeshPrimitive::Lines. + +@image html primitives-grid3dwireframe.png + +The @p subdivisions parameter describes how many times the plane gets cut in +each direction. Specifying @cpp {0, 0} @ce will make the result an (indexed) +equivalent to @ref planeWireframe(); @cpp {5, 3} @ce will make the grid have 6 +cells horizontally and 4 vertically. In particular, this is different from the +`subdivisions` parameter in @ref icosphereSolid(). +@see @ref grid3DSolid() +*/ +MAGNUM_PRIMITIVES_EXPORT Trade::MeshData3D grid3DWireframe(const Vector2i& subdivisions); + +}} + +#endif diff --git a/src/Magnum/Primitives/Icosphere.h b/src/Magnum/Primitives/Icosphere.h index 8559446e2..ecd2d613e 100644 --- a/src/Magnum/Primitives/Icosphere.h +++ b/src/Magnum/Primitives/Icosphere.h @@ -47,6 +47,12 @@ normals. @image html primitives-icospheresolid.png +The @p subdivisions parameter describes how many times is each icosphere +triangle subdivided, recursively. Specifying @cpp 0 @ce will result in an +icosphere with 20 faces, saying @cpp 1 @ce will result in an icosphere with 80 +faces (each triangle subdivided into four smaller), saying @cpp 2 @ce will +result in 320 faces and so on. In particular, this is different from the +`subdivisions` parameter in @ref grid3DSolid() or @ref grid3DWireframe(). @see @ref uvSphereSolid(), @ref uvSphereWireframe() */ MAGNUM_PRIMITIVES_EXPORT Trade::MeshData3D icosphereSolid(UnsignedInt subdivisions); diff --git a/src/Magnum/Primitives/Test/CMakeLists.txt b/src/Magnum/Primitives/Test/CMakeLists.txt index 28eb3a469..d0ff68730 100644 --- a/src/Magnum/Primitives/Test/CMakeLists.txt +++ b/src/Magnum/Primitives/Test/CMakeLists.txt @@ -30,6 +30,7 @@ corrade_add_test(PrimitivesCrosshairTest CrosshairTest.cpp LIBRARIES MagnumPrimi corrade_add_test(PrimitivesCubeTest CubeTest.cpp LIBRARIES MagnumPrimitives) corrade_add_test(PrimitivesConeTest ConeTest.cpp LIBRARIES MagnumPrimitives) corrade_add_test(PrimitivesCylinderTest CylinderTest.cpp LIBRARIES MagnumPrimitives) +corrade_add_test(PrimitivesGridTest GridTest.cpp LIBRARIES MagnumPrimitives) corrade_add_test(PrimitivesIcosphereTest IcosphereTest.cpp LIBRARIES MagnumPrimitives) corrade_add_test(PrimitivesLineTest LineTest.cpp LIBRARIES MagnumPrimitives) corrade_add_test(PrimitivesPlaneTest PlaneTest.cpp LIBRARIES MagnumPrimitives) diff --git a/src/Magnum/Primitives/Test/GridTest.cpp b/src/Magnum/Primitives/Test/GridTest.cpp new file mode 100644 index 000000000..851aeb317 --- /dev/null +++ b/src/Magnum/Primitives/Test/GridTest.cpp @@ -0,0 +1,377 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 + Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include +#include + +#include "Magnum/Math/Vector3.h" +#include "Magnum/Primitives/Grid.h" +#include "Magnum/Trade/MeshData3D.h" + +namespace Magnum { namespace Primitives { namespace Test { + +struct GridTest: TestSuite::Tester { + explicit GridTest(); + + void solid3DWithoutAnything(); + void solid3DWithNormalsAndTextureCoords(); + void wireframe3D(); +}; + +GridTest::GridTest() { + addTests({&GridTest::solid3DWithoutAnything, + &GridTest::solid3DWithNormalsAndTextureCoords, + &GridTest::wireframe3D}); +} + +void GridTest::solid3DWithoutAnything() { + Trade::MeshData3D grid = grid3DSolid({5, 3}, {}); + + CORRADE_COMPARE_AS(grid.positions(0), (std::vector{ + {-1.0f, -1.0f, 0.0f}, + {-0.666667f, -1.0f, 0.0f}, + {-0.333333f, -1.0f, 0.0f}, + {0.0f, -1.0f, 0.0f}, + {0.333333f, -1.0f, 0.0f}, + {0.666667f, -1.0f, 0.0f}, + {1.0f, -1.0f, 0.0f}, + + {-1.0f, -0.5f, 0.0f}, + {-0.666667f, -0.5f, 0.0f}, + {-0.333333f, -0.5f, 0.0f}, + {0.0f, -0.5f, 0.0f}, + {0.333333f, -0.5f, 0.0f}, + {0.666667f, -0.5f, 0.0f}, + {1.0f, -0.5f, 0.0f}, + + {-1.0f, 0.0f, 0.0f}, + {-0.666667f, 0.0f, 0.0f}, + {-0.333333f, 0.0f, 0.0f}, + {0.0f, 0.0f, 0.0f}, + {0.333333f, 0.0f, 0.0f}, + {0.666667f, 0.0f, 0.0f}, + {1.0f, 0.0f, 0.0f}, + + {-1.0f, 0.5f, 0.0f}, + {-0.666667f, 0.5f, 0.0f}, + {-0.333333f, 0.5f, 0.0f}, + {0.0f, 0.5f, 0.0f}, + {0.333333f, 0.5f, 0.0f}, + {0.666667f, 0.5f, 0.0f}, + {1.0f, 0.5f, 0.0f}, + + {-1.0f, 1.0f, 0.0f}, + {-0.666667f, 1.0f, 0.0f}, + {-0.333333f, 1.0f, 0.0f}, + {0.0f, 1.0f, 0.0f}, + {0.333333f, 1.0f, 0.0f}, + {0.666667f, 1.0f, 0.0f}, + {1.0f, 1.0f, 0.0f} + }), TestSuite::Compare::Container); + + CORRADE_COMPARE(grid.normalArrayCount(), 0); + CORRADE_COMPARE(grid.textureCoords2DArrayCount(), 0); + + CORRADE_COMPARE_AS(grid.indices(), (std::vector{ + 0, 8, 7, 0, 1, 8, + 1, 9, 8, 1, 2, 9, + 2, 10, 9, 2, 3, 10, + 3, 11, 10, 3, 4, 11, + 4, 12, 11, 4, 5, 12, + 5, 13, 12, 5, 6, 13, + + 7, 15, 14, 7, 8, 15, + 8, 16, 15, 8, 9, 16, + 9, 17, 16, 9, 10, 17, + 10, 18, 17, 10, 11, 18, + 11, 19, 18, 11, 12, 19, + 12, 20, 19, 12, 13, 20, + + 14, 22, 21, 14, 15, 22, + 15, 23, 22, 15, 16, 23, + 16, 24, 23, 16, 17, 24, + 17, 25, 24, 17, 18, 25, + 18, 26, 25, 18, 19, 26, + 19, 27, 26, 19, 20, 27, + + 21, 29, 28, 21, 22, 29, + 22, 30, 29, 22, 23, 30, + 23, 31, 30, 23, 24, 31, + 24, 32, 31, 24, 25, 32, + 25, 33, 32, 25, 26, 33, + 26, 34, 33, 26, 27, 34 + }), TestSuite::Compare::Container); +} + +void GridTest::solid3DWithNormalsAndTextureCoords() { + Trade::MeshData3D grid = grid3DSolid({5, 3}, GridFlag::GenerateNormals|GridFlag::GenerateTextureCoords); + + CORRADE_COMPARE_AS(grid.positions(0), (std::vector{ + {-1.0f, -1.0f, 0.0f}, + {-0.666667f, -1.0f, 0.0f}, + {-0.333333f, -1.0f, 0.0f}, + {0.0f, -1.0f, 0.0f}, + {0.333333f, -1.0f, 0.0f}, + {0.666667f, -1.0f, 0.0f}, + {1.0f, -1.0f, 0.0f}, + + {-1.0f, -0.5f, 0.0f}, + {-0.666667f, -0.5f, 0.0f}, + {-0.333333f, -0.5f, 0.0f}, + {0.0f, -0.5f, 0.0f}, + {0.333333f, -0.5f, 0.0f}, + {0.666667f, -0.5f, 0.0f}, + {1.0f, -0.5f, 0.0f}, + + {-1.0f, 0.0f, 0.0f}, + {-0.666667f, 0.0f, 0.0f}, + {-0.333333f, 0.0f, 0.0f}, + {0.0f, 0.0f, 0.0f}, + {0.333333f, 0.0f, 0.0f}, + {0.666667f, 0.0f, 0.0f}, + {1.0f, 0.0f, 0.0f}, + + {-1.0f, 0.5f, 0.0f}, + {-0.666667f, 0.5f, 0.0f}, + {-0.333333f, 0.5f, 0.0f}, + {0.0f, 0.5f, 0.0f}, + {0.333333f, 0.5f, 0.0f}, + {0.666667f, 0.5f, 0.0f}, + {1.0f, 0.5f, 0.0f}, + + {-1.0f, 1.0f, 0.0f}, + {-0.666667f, 1.0f, 0.0f}, + {-0.333333f, 1.0f, 0.0f}, + {0.0f, 1.0f, 0.0f}, + {0.333333f, 1.0f, 0.0f}, + {0.666667f, 1.0f, 0.0f}, + {1.0f, 1.0f, 0.0f} + }), TestSuite::Compare::Container); + + CORRADE_COMPARE_AS(grid.normals(0), (std::vector{ + {0.0f, 0.0f, 1.0f}, + {0.0f, 0.0f, 1.0f}, + {0.0f, 0.0f, 1.0f}, + {0.0f, 0.0f, 1.0f}, + {0.0f, 0.0f, 1.0f}, + {0.0f, 0.0f, 1.0f}, + {0.0f, 0.0f, 1.0f}, + + {0.0f, 0.0f, 1.0f}, + {0.0f, 0.0f, 1.0f}, + {0.0f, 0.0f, 1.0f}, + {0.0f, 0.0f, 1.0f}, + {0.0f, 0.0f, 1.0f}, + {0.0f, 0.0f, 1.0f}, + {0.0f, 0.0f, 1.0f}, + + {0.0f, 0.0f, 1.0f}, + {0.0f, 0.0f, 1.0f}, + {0.0f, 0.0f, 1.0f}, + {0.0f, 0.0f, 1.0f}, + {0.0f, 0.0f, 1.0f}, + {0.0f, 0.0f, 1.0f}, + {0.0f, 0.0f, 1.0f}, + + {0.0f, 0.0f, 1.0f}, + {0.0f, 0.0f, 1.0f}, + {0.0f, 0.0f, 1.0f}, + {0.0f, 0.0f, 1.0f}, + {0.0f, 0.0f, 1.0f}, + {0.0f, 0.0f, 1.0f}, + {0.0f, 0.0f, 1.0f}, + + {0.0f, 0.0f, 1.0f}, + {0.0f, 0.0f, 1.0f}, + {0.0f, 0.0f, 1.0f}, + {0.0f, 0.0f, 1.0f}, + {0.0f, 0.0f, 1.0f}, + {0.0f, 0.0f, 1.0f}, + {0.0f, 0.0f, 1.0f}, + }), TestSuite::Compare::Container); + + CORRADE_COMPARE_AS(grid.textureCoords2D(0), (std::vector{ + {0.0f, 0.0f}, + {0.166667f, 0.0f}, + {0.333333f, 0.0f}, + {0.5f, 0.0f}, + {0.666667f, 0.0f}, + {0.833333f, 0.0f}, + {1.0f, 0.0f}, + + {0.0f, 0.25f}, + {0.166667f, 0.25f}, + {0.333333f, 0.25f}, + {0.5f, 0.25f}, + {0.666667f, 0.25f}, + {0.833333f, 0.25f}, + {1.0f, 0.25f}, + + {0.0f, 0.5f}, + {0.166667f, 0.5f}, + {0.333333f, 0.5f}, + {0.5f, 0.5f}, + {0.666667f, 0.5f}, + {0.833333f, 0.5f}, + {1.0f, 0.5f}, + + {0.0f, 0.75f}, + {0.166667f, 0.75f}, + {0.333333f, 0.75f}, + {0.5f, 0.75f}, + {0.666667f, 0.75f}, + {0.833333f, 0.75f}, + {1.0f, 0.75f}, + + {0.0f, 1.0f}, + {0.166667f, 1.0f}, + {0.333333f, 1.0f}, + {0.5f, 1.0f}, + {0.666667f, 1.0f}, + {0.833333f, 1.0f}, + {1.0f, 1.0f} + }), TestSuite::Compare::Container); + + CORRADE_COMPARE_AS(grid.indices(), (std::vector{ + 0, 8, 7, 0, 1, 8, + 1, 9, 8, 1, 2, 9, + 2, 10, 9, 2, 3, 10, + 3, 11, 10, 3, 4, 11, + 4, 12, 11, 4, 5, 12, + 5, 13, 12, 5, 6, 13, + + 7, 15, 14, 7, 8, 15, + 8, 16, 15, 8, 9, 16, + 9, 17, 16, 9, 10, 17, + 10, 18, 17, 10, 11, 18, + 11, 19, 18, 11, 12, 19, + 12, 20, 19, 12, 13, 20, + + 14, 22, 21, 14, 15, 22, + 15, 23, 22, 15, 16, 23, + 16, 24, 23, 16, 17, 24, + 17, 25, 24, 17, 18, 25, + 18, 26, 25, 18, 19, 26, + 19, 27, 26, 19, 20, 27, + + 21, 29, 28, 21, 22, 29, + 22, 30, 29, 22, 23, 30, + 23, 31, 30, 23, 24, 31, + 24, 32, 31, 24, 25, 32, + 25, 33, 32, 25, 26, 33, + 26, 34, 33, 26, 27, 34 + }), TestSuite::Compare::Container); +} + +void GridTest::wireframe3D() { + Trade::MeshData3D grid = grid3DWireframe({5, 3}); + + CORRADE_COMPARE_AS(grid.positions(0), (std::vector{ + {-1.0f, -1.0f, 0.0f}, + {-0.666667f, -1.0f, 0.0f}, + {-0.333333f, -1.0f, 0.0f}, + {0.0f, -1.0f, 0.0f}, + {0.333333f, -1.0f, 0.0f}, + {0.666667f, -1.0f, 0.0f}, + {1.0f, -1.0f, 0.0f}, + + {-1.0f, -0.5f, 0.0f}, + {-0.666667f, -0.5f, 0.0f}, + {-0.333333f, -0.5f, 0.0f}, + {0.0f, -0.5f, 0.0f}, + {0.333333f, -0.5f, 0.0f}, + {0.666667f, -0.5f, 0.0f}, + {1.0f, -0.5f, 0.0f}, + + {-1.0f, 0.0f, 0.0f}, + {-0.666667f, 0.0f, 0.0f}, + {-0.333333f, 0.0f, 0.0f}, + {0.0f, 0.0f, 0.0f}, + {0.333333f, 0.0f, 0.0f}, + {0.666667f, 0.0f, 0.0f}, + {1.0f, 0.0f, 0.0f}, + + {-1.0f, 0.5f, 0.0f}, + {-0.666667f, 0.5f, 0.0f}, + {-0.333333f, 0.5f, 0.0f}, + {0.0f, 0.5f, 0.0f}, + {0.333333f, 0.5f, 0.0f}, + {0.666667f, 0.5f, 0.0f}, + {1.0f, 0.5f, 0.0f}, + + {-1.0f, 1.0f, 0.0f}, + {-0.666667f, 1.0f, 0.0f}, + {-0.333333f, 1.0f, 0.0f}, + {0.0f, 1.0f, 0.0f}, + {0.333333f, 1.0f, 0.0f}, + {0.666667f, 1.0f, 0.0f}, + {1.0f, 1.0f, 0.0f} + }), TestSuite::Compare::Container); + + CORRADE_COMPARE_AS(grid.indices(), (std::vector{ + 0, 1, 0, 7, + 1, 2, 1, 8, + 2, 3, 2, 9, + 3, 4, 3, 10, + 4, 5, 4, 11, + 5, 6, 5, 12, + 6, 13, + + 7, 8, 7, 14, + 8, 9, 8, 15, + 9, 10, 9, 16, + 10, 11, 10, 17, + 11, 12, 11, 18, + 12, 13, 12, 19, + 13, 20, + + 14, 15, 14, 21, + 15, 16, 15, 22, + 16, 17, 16, 23, + 17, 18, 17, 24, + 18, 19, 18, 25, + 19, 20, 19, 26, + 20, 27, + + 21, 22, 21, 28, + 22, 23, 22, 29, + 23, 24, 23, 30, + 24, 25, 24, 31, + 25, 26, 25, 32, + 26, 27, 26, 33, + 27, 34, + + 28, 29, + 29, 30, + 30, 31, + 31, 32, + 32, 33, + 33, 34 + }), TestSuite::Compare::Container); +} + +}}} + +CORRADE_TEST_MAIN(Magnum::Primitives::Test::GridTest)