Browse Source

Primitives: added grid3DSolid() and grid3DWireframe().

pull/205/head
Vladimír Vondruš 8 years ago
parent
commit
8c74f4b2db
  1. 3
      doc/changelog.dox
  2. 13
      doc/generated/primitives.cpp
  3. BIN
      doc/primitives-grid3dsolid.png
  4. BIN
      doc/primitives-grid3dwireframe.png
  5. 2
      src/Magnum/Primitives/CMakeLists.txt
  6. 108
      src/Magnum/Primitives/Grid.cpp
  7. 101
      src/Magnum/Primitives/Grid.h
  8. 6
      src/Magnum/Primitives/Icosphere.h
  9. 1
      src/Magnum/Primitives/Test/CMakeLists.txt
  10. 377
      src/Magnum/Primitives/Test/GridTest.cpp

3
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

13
doc/generated/primitives.cpp

@ -56,6 +56,7 @@
#include <Magnum/Primitives/Cone.h>
#include <Magnum/Primitives/Cube.h>
#include <Magnum/Primitives/Cylinder.h>
#include <Magnum/Primitives/Grid.h>
#include <Magnum/Primitives/Icosphere.h>
#include <Magnum/Primitives/Line.h>
#include <Magnum/Primitives/Plane.h>
@ -96,6 +97,7 @@ struct PrimitiveVisualizer: Platform::WindowlessApplication {
std::pair<Trade::MeshData3D, std::string> coneWireframe();
std::pair<Trade::MeshData3D, std::string> cubeWireframe();
std::pair<Trade::MeshData3D, std::string> cylinderWireframe();
std::pair<Trade::MeshData3D, std::string> grid3DWireframe();
std::pair<Trade::MeshData3D, std::string> line3D();
std::pair<Trade::MeshData3D, std::string> planeWireframe();
std::pair<Trade::MeshData3D, std::string> uvSphereWireframe();
@ -108,6 +110,7 @@ struct PrimitiveVisualizer: Platform::WindowlessApplication {
std::pair<Trade::MeshData3D, std::string> coneSolid();
std::pair<Trade::MeshData3D, std::string> cubeSolid();
std::pair<Trade::MeshData3D, std::string> cylinderSolid();
std::pair<Trade::MeshData3D, std::string> grid3DSolid();
std::pair<Trade::MeshData3D, std::string> icosphereSolid();
std::pair<Trade::MeshData3D, std::string> planeSolid();
std::pair<Trade::MeshData3D, std::string> 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<Trade::MeshData3D, std::string> PrimitiveVisualizer::cylinderWireframe
return {Primitives::cylinderWireframe(1, 32, 1.0f), "cylinderwireframe.png"};
}
std::pair<Trade::MeshData3D, std::string> PrimitiveVisualizer::grid3DWireframe() {
return {Primitives::grid3DWireframe({5, 3}), "grid3dwireframe.png"};
}
std::pair<Trade::MeshData3D, std::string> 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<Trade::MeshData3D, std::string> PrimitiveVisualizer::cylinderSolid() {
return {Primitives::cylinderSolid(1, 12, 1.0f, Primitives::CylinderFlag::CapEnds), "cylindersolid.png"};
}
std::pair<Trade::MeshData3D, std::string> PrimitiveVisualizer::grid3DSolid() {
return {Primitives::grid3DSolid({5, 3}), "grid3dsolid.png"};
}
std::pair<Trade::MeshData3D, std::string> PrimitiveVisualizer::icosphereSolid() {
return {Primitives::icosphereSolid(1), "icospheresolid.png"};
}

BIN
doc/primitives-grid3dsolid.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

BIN
doc/primitives-grid3dwireframe.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

2
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

108
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š <mosra@centrum.cz>
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<Vector3> 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<UnsignedInt> 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<std::vector<Vector3>> normals;
if(flags & GridFlag::GenerateNormals)
normals.emplace_back(positions.size(), Vector3::zAxis(1.0f));
std::vector<std::vector<Vector2>> 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<Vector3> 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<UnsignedInt> 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};
}
}}

101
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š <mosra@centrum.cz>
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 <Corrade/Containers/EnumSet.h>
#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<GridFlag> 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

6
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);

1
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)

377
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š <mosra@centrum.cz>
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 <Corrade/TestSuite/Tester.h>
#include <Corrade/TestSuite/Compare/Container.h>
#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<Vector3>{
{-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<UnsignedInt>{
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<Vector3>{
{-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<Vector3>{
{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<Vector2>{
{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<UnsignedInt>{
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<Vector3>{
{-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<UnsignedInt>{
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)
Loading…
Cancel
Save