Browse Source

Primitives: make Cone and Cylinder tests more maintainable.

I got some bugs there, need to fix them.
pull/388/head
Vladimír Vondruš 7 years ago
parent
commit
8c902bec4d
  1. 290
      src/Magnum/Primitives/Test/ConeTest.cpp
  2. 371
      src/Magnum/Primitives/Test/CylinderTest.cpp

290
src/Magnum/Primitives/Test/ConeTest.cpp

@ -36,12 +36,16 @@ struct ConeTest: TestSuite::Tester {
explicit ConeTest();
void solidWithoutAnything();
void solidWithCaps();
void solidWithTextureCoords();
void solidWithTextureCoordsAndCaps();
void wireframe();
};
ConeTest::ConeTest() {
addTests({&ConeTest::solidWithoutAnything,
&ConeTest::solidWithCaps,
&ConeTest::solidWithTextureCoords,
&ConeTest::solidWithTextureCoordsAndCaps,
&ConeTest::wireframe});
}
@ -50,114 +54,235 @@ void ConeTest::solidWithoutAnything() {
Trade::MeshData3D cone = coneSolid(2, 3, 1.0f);
CORRADE_COMPARE_AS(cone.positions(0), (std::vector<Vector3>{
{0.0f, -1.0f, 1.0f},
{0.866025f, -1.0f, -0.5f},
{-0.866025f, -1.0f, -0.5f},
{0.0f, -1.0f, 1.0f}, /* 0 */
{0.866025f, -1.0f, -0.5f}, /* 1 */
{-0.866025f, -1.0f, -0.5f}, /* 2 */
{0.0f, 0.0f, 0.5f},
{0.433013f, 0.0f, -0.25f},
{-0.433013f, 0.0f, -0.25f},
{0.0f, 0.0f, 0.5f}, /* 3 */
{0.433013f, 0.0f, -0.25f}, /* 4 */
{-0.433013f, 0.0f, -0.25f}, /* 5 */
{0.0f, 1.0f, 0.0f},
{0.0f, 1.0f, 0.0f},
{0.0f, 1.0f, 0.0f}
{0.0f, 1.0f, 0.0f}, /* 6 */
{0.0f, 1.0f, 0.0f}, /* 7 */
{0.0f, 1.0f, 0.0f} /* 8 */
}), TestSuite::Compare::Container);
CORRADE_COMPARE_AS(cone.normals(0), (std::vector<Vector3>{
{0.0f, 0.447214f, 0.894427f},
{0.774597f, 0.447214f, -0.447214f},
{-0.774597f, 0.447214f, -0.447214f},
{0.0f, 0.447214f, 0.894427f}, /* 0 */
{0.774597f, 0.447214f, -0.447214f}, /* 1 */
{-0.774597f, 0.447214f, -0.447214f}, /* 2 */
{0.0f, 0.447214f, 0.894427f},
{0.774597f, 0.447214f, -0.447214f},
{-0.774597f, 0.447214f, -0.447214f},
{0.0f, 0.447214f, 0.894427f}, /* 3 */
{0.774597f, 0.447214f, -0.447214f}, /* 4 */
{-0.774597f, 0.447214f, -0.447214f}, /* 5 */
{0.0f, 0.447214f, 0.894427f},
{0.774597f, 0.447214f, -0.447214f},
{-0.774597f, 0.447214f, -0.447214f}
{0.0f, 0.447214f, 0.894427f}, /* 6 */
{0.774597f, 0.447214f, -0.447214f}, /* 7 */
{-0.774597f, 0.447214f, -0.447214f} /* 8 */
}), TestSuite::Compare::Container);
CORRADE_VERIFY(!cone.hasTextureCoords2D());
CORRADE_COMPARE_AS(cone.indices(), (std::vector<UnsignedInt>{
0, 1, 4, 0, 4, 3, 1, 2, 5, 1, 5, 4, 2, 0, 3, 2, 3, 5,
3, 4, 7, 3, 7, 6, 4, 5, 8, 4, 8, 7, 5, 3, 6, 5, 6, 8
}), TestSuite::Compare::Container);
}
void ConeTest::solidWithTextureCoordsAndCaps() {
Trade::MeshData3D cone = coneSolid(2, 3, 1.0f, ConeFlag::GenerateTextureCoords|ConeFlag::CapEnd);
void ConeTest::solidWithCaps() {
Trade::MeshData3D cone = coneSolid(2, 3, 1.0f, ConeFlag::CapEnd);
/* Bottom ring duplicated because it has different normals, first vertex of
each ring duplicated because it has different texture coordinates */
CORRADE_COMPARE_AS(cone.positions(0), (std::vector<Vector3>{
{0.0f, -1.0f, 0.0f},
{0.0f, -1.0f, 0.0f}, /* 0 */
{0.0f, -1.0f, 1.0f},
{0.866025f, -1.0f, -0.5f},
{-0.866025f, -1.0f, -0.5f},
{0.0f, -1.0f, 1.0f},
{0.0f, -1.0f, 1.0f}, /* 1 */
{0.866025f, -1.0f, -0.5f}, /* 2 */
{-0.866025f, -1.0f, -0.5f}, /* 3 */
{0.0f, -1.0f, 1.0f},
{0.866025f, -1.0f, -0.5f},
{-0.866025f, -1.0f, -0.5f},
{0.0f, -1.0f, 1.0f},
{0.0f, -1.0f, 1.0f}, /* 4 */
{0.866025f, -1.0f, -0.5f}, /* 5 */
{-0.866025f, -1.0f, -0.5f}, /* 6 */
{0.0f, 0.0f, 0.5f},
{0.433013f, 0.0f, -0.25f},
{-0.433013f, 0.0f, -0.25f},
{0.0f, 0.0f, 0.5f},
{0.0f, 0.0f, 0.5f}, /* 7 */
{0.433013f, 0.0f, -0.25f}, /* 8 */
{-0.433013f, 0.0f, -0.25f}, /* 9 */
{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}, /* 10 */
{0.0f, 1.0f, 0.0f}, /* 11 */
{0.0f, 1.0f, 0.0f}, /* 12 */
}), TestSuite::Compare::Container);
CORRADE_COMPARE_AS(cone.normals(0), (std::vector<Vector3>{
{0.0f, -1.0f, 0.0f},
{0.0f, -1.0f, 0.0f}, /* 0 */
{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}, /* 1 */
{0.0f, -1.0f, 0.0f}, /* 2 */
{0.0f, -1.0f, 0.0f}, /* 3 */
{0.0f, 0.447214f, 0.894427f},
{0.774597f, 0.447214f, -0.447214f},
{-0.774597f, 0.447214f, -0.447214f},
{0.0f, 0.447214f, 0.894427f},
{0.0f, 0.447214f, 0.894427f}, /* 4 */
{0.774597f, 0.447214f, -0.447214f}, /* 5 */
{-0.774597f, 0.447214f, -0.447214f}, /* 6 */
{0.0f, 0.447214f, 0.894427f},
{0.774597f, 0.447214f, -0.447214f},
{-0.774597f, 0.447214f, -0.447214f},
{0.0f, 0.447214f, 0.894427f},
{0.0f, 0.447214f, 0.894427f}, /* 7 */
{0.774597f, 0.447214f, -0.447214f}, /* 8 */
{-0.774597f, 0.447214f, -0.447214f}, /* 9 */
{0.0f, 0.447214f, 0.894427f}, /* 10 */
{0.774597f, 0.447214f, -0.447214f}, /* 11 */
{-0.774597f, 0.447214f, -0.447214f}, /* 12 */
}), TestSuite::Compare::Container);
CORRADE_VERIFY(!cone.hasTextureCoords2D());
/* Faces of the caps and sides do not share any vertices due to different
normals */
CORRADE_COMPARE_AS(cone.indices(), (std::vector<UnsignedInt>{
0, 2, 1, 0, 3, 2, 0, 1, 3,
4, 5, 8, 4, 8, 7, 5, 6, 9, 5, 9, 8, 6, 4, 7, 6, 7, 9,
7, 8, 11, 7, 11, 10, 8, 9, 12, 8, 12, 11, 9, 7, 10, 9, 10, 12
}), TestSuite::Compare::Container);
}
void ConeTest::solidWithTextureCoords() {
Trade::MeshData3D cone = coneSolid(2, 3, 1.0f, ConeFlag::GenerateTextureCoords);
/* Bottom ring duplicated because it has different normals, first vertex of
each ring duplicated because it has different texture coordinates */
CORRADE_COMPARE_AS(cone.positions(0), (std::vector<Vector3>{
{0.0f, -1.0f, 1.0f}, /* 0 */
{0.866025f, -1.0f, -0.5f}, /* 1 */
{-0.866025f, -1.0f, -0.5f}, /* 2 */
{0.0f, -1.0f, 1.0f}, /* 3 */
{0.0f, 0.0f, 0.5f}, /* 4 */
{0.433013f, 0.0f, -0.25f}, /* 5 */
{-0.433013f, 0.0f, -0.25f}, /* 6 */
{0.0f, 0.0f, 0.5f}, /* 7 */
{0.0f, 1.0f, 0.0f}, /* 8 */
{0.0f, 1.0f, 0.0f}, /* 9 */
{0.0f, 1.0f, 0.0f}, /* 10 */
{0.0f, 1.0f, 0.0f} /* 11 */
}), TestSuite::Compare::Container);
{0.0f, 0.447214f, 0.894427f},
{0.774597f, 0.447214f, -0.447214f},
{-0.774597f, 0.447214f, -0.447214f},
{0.0f, 0.447214f, 0.894427f}
CORRADE_COMPARE_AS(cone.normals(0), (std::vector<Vector3>{
{0.0f, 0.447214f, 0.894427f}, /* 0 */
{0.774597f, 0.447214f, -0.447214f}, /* 1 */
{-0.774597f, 0.447214f, -0.447214f}, /* 2 */
{0.0f, 0.447214f, 0.894427f}, /* 3 */
{0.0f, 0.447214f, 0.894427f}, /* 4 */
{0.774597f, 0.447214f, -0.447214f}, /* 5 */
{-0.774597f, 0.447214f, -0.447214f}, /* 6 */
{0.0f, 0.447214f, 0.894427f}, /* 7 */
{0.0f, 0.447214f, 0.894427f}, /* 8 */
{0.774597f, 0.447214f, -0.447214f}, /* 9 */
{-0.774597f, 0.447214f, -0.447214f}, /* 10 */
{0.0f, 0.447214f, 0.894427f} /* 11 */
}), TestSuite::Compare::Container);
CORRADE_COMPARE_AS(cone.textureCoords2D(0), (std::vector<Vector2>{
{0.5f, 0.0f},
{0.0f, 0.0f}, /* 0 */
{0.333333f, 0.0f}, /* 1 */
{0.666667f, 0.0f}, /* 2 */
{1.0f, 0.0f}, /* 3 */
{0.0f, 0.5f}, /* 4 */
{0.333333f, 0.5f}, /* 5 */
{0.666667f, 0.5f}, /* 6 */
{1.0f, 0.5f}, /* 7 */
{0.0f, 1.0f}, /* 8 */
{0.333333f, 1.0f}, /* 9 */
{0.666667f, 1.0f}, /* 10 */
{1.0f, 1.0f}, /* 11 */
}), TestSuite::Compare::Container);
{0.0f, 0.333333f},
{0.333333f, 0.333333f},
{0.666667f, 0.333333f},
{1.0f, 0.333333f},
/* Each ring has an extra vertex for texture coords */
CORRADE_COMPARE_AS(cone.indices(), (std::vector<UnsignedInt>{
0, 1, 5, 0, 5, 4, 1, 2, 6, 1, 6, 5, 2, 3, 7, 2, 7, 6,
4, 5, 9, 4, 9, 8, 5, 6, 10, 5, 10, 9, 6, 7, 11, 6, 11, 10
}), TestSuite::Compare::Container);
}
{0.0f, 0.333333f},
{0.333333f, 0.333333f},
{0.666667f, 0.333333f},
{1.0f, 0.333333f},
void ConeTest::solidWithTextureCoordsAndCaps() {
Trade::MeshData3D cone = coneSolid(2, 3, 1.0f, ConeFlag::GenerateTextureCoords|ConeFlag::CapEnd);
{0.0f, 0.666667f},
{0.333333f, 0.666667f},
{0.666667f, 0.666667f},
{1.0f, 0.666667f},
/* Bottom ring duplicated because it has different normals, first vertex of
each ring duplicated because it has different texture coordinates */
CORRADE_COMPARE_AS(cone.positions(0), (std::vector<Vector3>{
{0.0f, -1.0f, 0.0f}, /* 0 */
{0.0f, -1.0f, 1.0f}, /* 1 */
{0.866025f, -1.0f, -0.5f}, /* 2 */
{-0.866025f, -1.0f, -0.5f}, /* 3 */
{0.0f, -1.0f, 1.0f}, /* 4 */
{0.0f, -1.0f, 1.0f}, /* 5 */
{0.866025f, -1.0f, -0.5f}, /* 6 */
{-0.866025f, -1.0f, -0.5f}, /* 7 */
{0.0f, -1.0f, 1.0f}, /* 8 */
{0.0f, 0.0f, 0.5f}, /* 9 */
{0.433013f, 0.0f, -0.25f}, /* 10 */
{-0.433013f, 0.0f, -0.25f}, /* 11 */
{0.0f, 0.0f, 0.5f}, /* 12 */
{0.0f, 1.0f, 0.0f}, /* 13 */
{0.0f, 1.0f, 0.0f}, /* 14 */
{0.0f, 1.0f, 0.0f}, /* 15 */
{0.0f, 1.0f, 0.0f} /* 16 */
}), TestSuite::Compare::Container);
CORRADE_COMPARE_AS(cone.normals(0), (std::vector<Vector3>{
{0.0f, -1.0f, 0.0f}, /* 0 */
{0.0f, -1.0f, 0.0f}, /* 1 */
{0.0f, -1.0f, 0.0f}, /* 2 */
{0.0f, -1.0f, 0.0f}, /* 3 */
{0.0f, -1.0f, 0.0f}, /* 4 */
{0.0f, 0.447214f, 0.894427f}, /* 5 */
{0.774597f, 0.447214f, -0.447214f}, /* 6 */
{-0.774597f, 0.447214f, -0.447214f}, /* 7 */
{0.0f, 0.447214f, 0.894427f}, /* 8 */
{0.0f, 0.447214f, 0.894427f}, /* 9 */
{0.774597f, 0.447214f, -0.447214f}, /* 10 */
{-0.774597f, 0.447214f, -0.447214f}, /* 11 */
{0.0f, 0.447214f, 0.894427f}, /* 12 */
{0.0f, 0.447214f, 0.894427f}, /* 13 */
{0.774597f, 0.447214f, -0.447214f}, /* 14 */
{-0.774597f, 0.447214f, -0.447214f}, /* 15 */
{0.0f, 0.447214f, 0.894427f} /* 16 */
}), TestSuite::Compare::Container);
{0.0f, 1.0f},
{0.333333f, 1.0f},
{0.666667f, 1.0f},
{1.0f, 1.0f},
CORRADE_COMPARE_AS(cone.textureCoords2D(0), (std::vector<Vector2>{
{0.5f, 0.0f}, /* 0 */
{0.0f, 0.333333f}, /* 1 */
{0.333333f, 0.333333f}, /* 2 */
{0.666667f, 0.333333f}, /* 3 */
{1.0f, 0.333333f}, /* 4 */
{0.0f, 0.333333f}, /* 5 */
{0.333333f, 0.333333f}, /* 6 */
{0.666667f, 0.333333f}, /* 7 */
{1.0f, 0.333333f}, /* 8 */
{0.0f, 0.666667f}, /* 9 */
{0.333333f, 0.666667f}, /* 10 */
{0.666667f, 0.666667f}, /* 11 */
{1.0f, 0.666667f}, /* 12 */
{0.0f, 1.0f}, /* 13 */
{0.333333f, 1.0f}, /* 14 */
{0.666667f, 1.0f}, /* 15 */
{1.0f, 1.0f}, /* 16 */
}), TestSuite::Compare::Container);
/* Faces of the caps and sides do not share any vertices due to different
@ -173,19 +298,20 @@ void ConeTest::wireframe() {
Trade::MeshData3D cone = coneWireframe(8, 1.5f);
CORRADE_COMPARE_AS(cone.positions(0), (std::vector<Vector3>{
{0.0f, -1.5f, 1.0f},
{1.0f, -1.5f, 0.0f},
{0.0f, -1.5f, -1.0f},
{-1.0f, -1.5f, 0.0f},
{0.707107f, -1.5f, 0.707107f},
{0.707107f, -1.5f, -0.707107f},
{-0.707107f, -1.5f, -0.707107f},
{-0.707107f, -1.5f, 0.707107f},
{0.0f, 1.5f, 0.0f}
{0.0f, -1.5f, 1.0f}, /* 0 */
{1.0f, -1.5f, 0.0f}, /* 1 */
{0.0f, -1.5f, -1.0f}, /* 2 */
{-1.0f, -1.5f, 0.0f}, /* 3 */
{0.707107f, -1.5f, 0.707107f}, /* 4 */
{0.707107f, -1.5f, -0.707107f}, /* 5 */
{-0.707107f, -1.5f, -0.707107f}, /* 6 */
{-0.707107f, -1.5f, 0.707107f}, /* 7 */
{0.0f, 1.5f, 0.0f} /* 8 */
}), TestSuite::Compare::Container);
CORRADE_COMPARE(cone.normalArrayCount(), 0);
CORRADE_VERIFY(!cone.hasNormals());
CORRADE_VERIFY(!cone.hasTextureCoords2D());
CORRADE_COMPARE_AS(cone.indices(), (std::vector<UnsignedInt>{
0, 4, 1, 5, 2, 6, 3, 7,

371
src/Magnum/Primitives/Test/CylinderTest.cpp

@ -36,12 +36,16 @@ struct CylinderTest: TestSuite::Tester {
explicit CylinderTest();
void solidWithoutAnything();
void solidWithCaps();
void solidWithTextureCoords();
void solidWithTextureCoordsAndCaps();
void wireframe();
};
CylinderTest::CylinderTest() {
addTests({&CylinderTest::solidWithoutAnything,
&CylinderTest::solidWithCaps,
&CylinderTest::solidWithTextureCoords,
&CylinderTest::solidWithTextureCoordsAndCaps,
&CylinderTest::wireframe});
}
@ -50,135 +54,269 @@ void CylinderTest::solidWithoutAnything() {
Trade::MeshData3D cylinder = cylinderSolid(2, 3, 1.5f);
CORRADE_COMPARE_AS(cylinder.positions(0), (std::vector<Vector3>{
{0.0f, -1.5f, 1.0f},
{0.866025f, -1.5f, -0.5f},
{-0.866025f, -1.5f, -0.5f},
{0.0f, -1.5f, 1.0f}, /* 0 */
{0.866025f, -1.5f, -0.5f}, /* 1 */
{-0.866025f, -1.5f, -0.5f}, /* 2 */
{0.0f, 0.0f, 1.0f},
{0.866025f, 0.0f, -0.5f},
{-0.866025f, 0.0f, -0.5f},
{0.0f, 0.0f, 1.0f}, /* 3 */
{0.866025f, 0.0f, -0.5f}, /* 4 */
{-0.866025f, 0.0f, -0.5f}, /* 5 */
{0.0f, 1.5f, 1.0f},
{0.866025f, 1.5f, -0.5f},
{-0.866025f, 1.5f, -0.5f}
{0.0f, 1.5f, 1.0f}, /* 6 */
{0.866025f, 1.5f, -0.5f}, /* 7 */
{-0.866025f, 1.5f, -0.5f} /* 8 */
}), TestSuite::Compare::Container);
CORRADE_COMPARE_AS(cylinder.normals(0), (std::vector<Vector3>{
{0.0f, 0.0f, 1.0f},
{0.866025f, 0.0f, -0.5f},
{-0.866025f, 0.0f, -0.5f},
{0.0f, 0.0f, 1.0f}, /* 0 */
{0.866025f, 0.0f, -0.5f}, /* 1 */
{-0.866025f, 0.0f, -0.5f}, /* 2 */
{0.0f, 0.0f, 1.0f},
{0.866025f, 0.0f, -0.5f},
{-0.866025f, 0.0f, -0.5f},
{0.0f, 0.0f, 1.0f}, /* 3 */
{0.866025f, 0.0f, -0.5f}, /* 4 */
{-0.866025f, 0.0f, -0.5f}, /* 5 */
{0.0f, 0.0f, 1.0f},
{0.866025f, 0.0f, -0.5f},
{-0.866025f, 0.0f, -0.5f}
{0.0f, 0.0f, 1.0f}, /* 6 */
{0.866025f, 0.0f, -0.5f}, /* 7 */
{-0.866025f, 0.0f, -0.5f} /* 8 */
}), TestSuite::Compare::Container);
CORRADE_VERIFY(!cylinder.hasTextureCoords2D());
CORRADE_COMPARE_AS(cylinder.indices(), (std::vector<UnsignedInt>{
0, 1, 4, 0, 4, 3, 1, 2, 5, 1, 5, 4, 2, 0, 3, 2, 3, 5,
3, 4, 7, 3, 7, 6, 4, 5, 8, 4, 8, 7, 5, 3, 6, 5, 6, 8
}), TestSuite::Compare::Container);
}
void CylinderTest::solidWithTextureCoordsAndCaps() {
Trade::MeshData3D cylinder = cylinderSolid(2, 3, 1.5f, CylinderFlag::GenerateTextureCoords|CylinderFlag::CapEnds);
void CylinderTest::solidWithCaps() {
Trade::MeshData3D cylinder = cylinderSolid(2, 3, 1.5f, CylinderFlag::CapEnds);
/* Bottom ring duplicated because it has different normals, first vertex of
each ring duplicated because it has different texture coordinates */
CORRADE_COMPARE_AS(cylinder.positions(0), (std::vector<Vector3>{
{0.0f, -1.5f, 0.0f},
{0.0f, -1.5f, 0.0f}, /* 0 */
{0.0f, -1.5f, 1.0f},
{0.866025f, -1.5f, -0.5f},
{-0.866025f, -1.5f, -0.5f},
{0.0f, -1.5f, 1.0f},
{0.0f, -1.5f, 1.0f}, /* 1 */
{0.866025f, -1.5f, -0.5f}, /* 2 */
{-0.866025f, -1.5f, -0.5f}, /* 3 */
{0.0f, -1.5f, 1.0f},
{0.866025f, -1.5f, -0.5f},
{-0.866025f, -1.5f, -0.5f},
{0.0f, -1.5f, 1.0f},
{0.0f, -1.5f, 1.0f}, /* 4 */
{0.866025f, -1.5f, -0.5f}, /* 5 */
{-0.866025f, -1.5f, -0.5f}, /* 6 */
{0.0f, 0.0f, 1.0f},
{0.866025f, 0.0f, -0.5f},
{-0.866025f, 0.0f, -0.5f},
{0.0f, 0.0f, 1.0f},
{0.0f, 0.0f, 1.0f}, /* 7 */
{0.866025f, 0.0f, -0.5f}, /* 8 */
{-0.866025f, 0.0f, -0.5f}, /* 9 */
{0.0f, 1.5f, 1.0f},
{0.866025f, 1.5f, -0.5f},
{-0.866025f, 1.5f, -0.5f},
{0.0f, 1.5f, 1.0f},
{0.0f, 1.5f, 1.0f}, /* 10 */
{0.866025f, 1.5f, -0.5f}, /* 11 */
{-0.866025f, 1.5f, -0.5f}, /* 12 */
{0.0f, 1.5f, 1.0f},
{0.866025f, 1.5f, -0.5f},
{-0.866025f, 1.5f, -0.5f},
{0.0f, 1.5f, 1.0f},
{0.0f, 1.5f, 1.0f}, /* 13 */
{0.866025f, 1.5f, -0.5f}, /* 14 */
{-0.866025f, 1.5f, -0.5f}, /* 15 */
{0.0f, 1.5f, 0.0f}
{0.0f, 1.5f, 0.0f} /* 16 */
}), TestSuite::Compare::Container);
CORRADE_COMPARE_AS(cylinder.normals(0), (std::vector<Vector3>{
{0.0f, -1.0f, 0.0f},
{0.0f, -1.0f, 0.0f}, /* 0 */
{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}, /* 1 */
{0.0f, -1.0f, 0.0f}, /* 2 */
{0.0f, -1.0f, 0.0f}, /* 3 */
{0.0f, 0.0f, 1.0f},
{0.866025f, 0.0f, -0.5f},
{-0.866025f, 0.0f, -0.5f},
{0.0f, 0.0f, 1.0f},
{0.0f, 0.0f, 1.0f}, /* 4 */
{0.866025f, 0.0f, -0.5f}, /* 5 */
{-0.866025f, 0.0f, -0.5f}, /* 6 */
{0.0f, 0.0f, 1.0f},
{0.866025f, 0.0f, -0.5f},
{-0.866025f, 0.0f, -0.5f},
{0.0f, 0.0f, 1.0f},
{0.0f, 0.0f, 1.0f}, /* 7 */
{0.866025f, 0.0f, -0.5f}, /* 8 */
{-0.866025f, 0.0f, -0.5f}, /* 9 */
{0.0f, 0.0f, 1.0f},
{0.866025f, 0.0f, -0.5f},
{-0.866025f, 0.0f, -0.5f},
{0.0f, 0.0f, 1.0f},
{0.0f, 0.0f, 1.0f}, /* 10 */
{0.866025f, 0.0f, -0.5f}, /* 11 */
{-0.866025f, 0.0f, -0.5f}, /* 12 */
{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}, /* 13 */
{0.0f, 1.0f, 0.0f}, /* 14 */
{0.0f, 1.0f, 0.0f}, /* 15 */
{0.0f, 1.0f, 0.0f},
{0.0f, 1.0f, 0.0f}, /* 16 */
}), TestSuite::Compare::Container);
CORRADE_COMPARE_AS(cylinder.textureCoords2D(0), (std::vector<Vector2>{
{0.5f, 0.0f},
CORRADE_VERIFY(!cylinder.hasTextureCoords2D());
{0.0f, 0.2f},
{0.333333f, 0.2f},
{0.666667f, 0.2f},
{1.0f, 0.2f},
/* Faces of the caps and sides do not share any vertices due to different
normals */
CORRADE_COMPARE_AS(cylinder.indices(), (std::vector<UnsignedInt>{
0, 2, 1, 0, 3, 2, 0, 1, 3,
4, 5, 8, 4, 8, 7, 5, 6, 9, 5, 9, 8, 6, 4, 7, 6, 7, 9,
7, 8, 11, 7, 11, 10, 8, 9, 12, 8, 12, 11, 9, 7, 10, 9, 10, 12,
13, 14, 16, 14, 15, 16, 15, 13, 16
}), TestSuite::Compare::Container);
}
{0.0f, 0.2f},
{0.333333f, 0.2f},
{0.666667f, 0.2f},
{1.0f, 0.2f},
void CylinderTest::solidWithTextureCoords() {
Trade::MeshData3D cylinder = cylinderSolid(2, 3, 1.5f, CylinderFlag::GenerateTextureCoords);
{0.0f, 0.5f},
{0.333333f, 0.5f},
{0.666667f, 0.5f},
{1.0f, 0.5f},
/* First vertex of each ring duplicated because it has different texture
coordinates */
CORRADE_COMPARE_AS(cylinder.positions(0), (std::vector<Vector3>{
{0.0f, -1.5f, 1.0f}, /* 0 */
{0.866025f, -1.5f, -0.5f}, /* 1 */
{-0.866025f, -1.5f, -0.5f}, /* 2 */
{0.0f, -1.5f, 1.0f}, /* 3 */
{0.0f, 0.0f, 1.0f}, /* 4 */
{0.866025f, 0.0f, -0.5f}, /* 5 */
{-0.866025f, 0.0f, -0.5f}, /* 6 */
{0.0f, 0.0f, 1.0f}, /* 7 */
{0.0f, 1.5f, 1.0f}, /* 8 */
{0.866025f, 1.5f, -0.5f}, /* 9 */
{-0.866025f, 1.5f, -0.5f}, /* 10 */
{0.0f, 1.5f, 1.0f}, /* 11 */
}), TestSuite::Compare::Container);
{0.0f, 0.8f},
{0.333333f, 0.8f},
{0.666667f, 0.8f},
{1.0f, 0.8f},
CORRADE_COMPARE_AS(cylinder.normals(0), (std::vector<Vector3>{
{0.0f, 0.0f, 1.0f}, /* 0 */
{0.866025f, 0.0f, -0.5f}, /* 1 */
{-0.866025f, 0.0f, -0.5f}, /* 2 */
{0.0f, 0.0f, 1.0f}, /* 3 */
{0.0f, 0.0f, 1.0f}, /* 4 */
{0.866025f, 0.0f, -0.5f}, /* 5 */
{-0.866025f, 0.0f, -0.5f}, /* 6 */
{0.0f, 0.0f, 1.0f}, /* 7 */
{0.0f, 0.0f, 1.0f}, /* 8 */
{0.866025f, 0.0f, -0.5f}, /* 9 */
{-0.866025f, 0.0f, -0.5f}, /* 10 */
{0.0f, 0.0f, 1.0f}, /* 11 */
}), TestSuite::Compare::Container);
{0.0f, 0.8f},
{0.333333f, 0.8f},
{0.666667f, 0.8f},
{1.0f, 0.8f},
CORRADE_COMPARE_AS(cylinder.textureCoords2D(0), (std::vector<Vector2>{
{0.0f, 0.0f}, /* 0 */
{0.333333f, 0.0f}, /* 1 */
{0.666667f, 0.0f}, /* 2 */
{1.0f, 0.0f}, /* 3 */
{0.0f, 0.5f}, /* 4 */
{0.333333f, 0.5f}, /* 5 */
{0.666667f, 0.5f}, /* 6 */
{1.0f, 0.5f}, /* 7 */
{0.0f, 1.0f}, /* 8 */
{0.333333f, 1.0f}, /* 9 */
{0.666667f, 1.0f}, /* 10 */
{1.0f, 1.0f}, /* 11 */
}), TestSuite::Compare::Container);
{0.5f, 1.0f}
/* Each ring has an extra vertex for texture coords */
CORRADE_COMPARE_AS(cylinder.indices(), (std::vector<UnsignedInt>{
0, 1, 5, 0, 5, 4, 1, 2, 6, 1, 6, 5, 2, 3, 7, 2, 7, 6,
4, 5, 9, 4, 9, 8, 5, 6, 10, 5, 10, 9, 6, 7, 11, 6, 11, 10
}), TestSuite::Compare::Container);
}
void CylinderTest::solidWithTextureCoordsAndCaps() {
Trade::MeshData3D cylinder = cylinderSolid(2, 3, 1.5f, CylinderFlag::GenerateTextureCoords|CylinderFlag::CapEnds);
/* Bottom ring duplicated because it has different normals, first vertex of
each ring duplicated because it has different texture coordinates */
CORRADE_COMPARE_AS(cylinder.positions(0), (std::vector<Vector3>{
{0.0f, -1.5f, 0.0f}, /* 0 */
{0.0f, -1.5f, 1.0f}, /* 1 */
{0.866025f, -1.5f, -0.5f}, /* 2 */
{-0.866025f, -1.5f, -0.5f}, /* 3 */
{0.0f, -1.5f, 1.0f}, /* 4 */
{0.0f, -1.5f, 1.0f}, /* 5 */
{0.866025f, -1.5f, -0.5f}, /* 6 */
{-0.866025f, -1.5f, -0.5f}, /* 7 */
{0.0f, -1.5f, 1.0f}, /* 8 */
{0.0f, 0.0f, 1.0f}, /* 9 */
{0.866025f, 0.0f, -0.5f}, /* 10 */
{-0.866025f, 0.0f, -0.5f}, /* 11 */
{0.0f, 0.0f, 1.0f}, /* 12 */
{0.0f, 1.5f, 1.0f}, /* 13 */
{0.866025f, 1.5f, -0.5f}, /* 14 */
{-0.866025f, 1.5f, -0.5f}, /* 15 */
{0.0f, 1.5f, 1.0f}, /* 16 */
{0.0f, 1.5f, 1.0f}, /* 17 */
{0.866025f, 1.5f, -0.5f}, /* 18 */
{-0.866025f, 1.5f, -0.5f}, /* 19 */
{0.0f, 1.5f, 1.0f}, /* 20 */
{0.0f, 1.5f, 0.0f} /* 21 */
}), TestSuite::Compare::Container);
CORRADE_COMPARE_AS(cylinder.normals(0), (std::vector<Vector3>{
{0.0f, -1.0f, 0.0f}, /* 0 */
{0.0f, -1.0f, 0.0f}, /* 1 */
{0.0f, -1.0f, 0.0f}, /* 2 */
{0.0f, -1.0f, 0.0f}, /* 3 */
{0.0f, -1.0f, 0.0f}, /* 4 */
{0.0f, 0.0f, 1.0f}, /* 5 */
{0.866025f, 0.0f, -0.5f}, /* 6 */
{-0.866025f, 0.0f, -0.5f}, /* 7 */
{0.0f, 0.0f, 1.0f}, /* 8 */
{0.0f, 0.0f, 1.0f}, /* 9 */
{0.866025f, 0.0f, -0.5f}, /* 10 */
{-0.866025f, 0.0f, -0.5f}, /* 11 */
{0.0f, 0.0f, 1.0f}, /* 12 */
{0.0f, 0.0f, 1.0f}, /* 13 */
{0.866025f, 0.0f, -0.5f}, /* 14 */
{-0.866025f, 0.0f, -0.5f}, /* 15 */
{0.0f, 0.0f, 1.0f}, /* 16 */
{0.0f, 1.0f, 0.0f}, /* 17 */
{0.0f, 1.0f, 0.0f}, /* 18 */
{0.0f, 1.0f, 0.0f}, /* 19 */
{0.0f, 1.0f, 0.0f}, /* 20 */
{0.0f, 1.0f, 0.0f}, /* 21 */
}), TestSuite::Compare::Container);
CORRADE_COMPARE_AS(cylinder.textureCoords2D(0), (std::vector<Vector2>{
{0.5f, 0.0f}, /* 0 */
{0.0f, 0.2f}, /* 1 */
{0.333333f, 0.2f}, /* 2 */
{0.666667f, 0.2f}, /* 3 */
{1.0f, 0.2f}, /* 4 */
{0.0f, 0.2f}, /* 5 */
{0.333333f, 0.2f}, /* 6 */
{0.666667f, 0.2f}, /* 7 */
{1.0f, 0.2f}, /* 8 */
{0.0f, 0.5f}, /* 9 */
{0.333333f, 0.5f}, /* 10 */
{0.666667f, 0.5f}, /* 11 */
{1.0f, 0.5f}, /* 12 */
{0.0f, 0.8f}, /* 13 */
{0.333333f, 0.8f}, /* 14 */
{0.666667f, 0.8f}, /* 15 */
{1.0f, 0.8f}, /* 16 */
{0.0f, 0.8f}, /* 17 */
{0.333333f, 0.8f}, /* 18 */
{0.666667f, 0.8f}, /* 19 */
{1.0f, 0.8f}, /* 20 */
{0.5f, 1.0f} /* 21 */
}), TestSuite::Compare::Container);
/* Faces of the caps and sides do not share any vertices due to different
@ -195,35 +333,36 @@ void CylinderTest::wireframe() {
Trade::MeshData3D cylinder = cylinderWireframe(2, 8, 0.5f);
CORRADE_COMPARE_AS(cylinder.positions(0), (std::vector<Vector3>{
{0.0f, -0.5f, 1.0f},
{1.0f, -0.5f, 0.0f},
{0.0f, -0.5f, -1.0f},
{-1.0f, -0.5f, 0.0f},
{0.707107f, -0.5f, 0.707107f},
{0.707107f, -0.5f, -0.707107f},
{-0.707107f, -0.5f, -0.707107f},
{-0.707107f, -0.5f, 0.707107f},
{0.0f, 0.0f, 1.0f},
{1.0f, 0.0f, 0.0f},
{0.0f, 0.0f, -1.0f},
{-1.0f, 0.0f, 0.0f},
{0.707107f, 0.0f, 0.707107f},
{0.707107f, 0.0f, -0.707107f},
{-0.707107f, 0.0f, -0.707107f},
{-0.707107f, 0.0f, 0.707107f},
{0.0f, 0.5f, 1.0f},
{1.0f, 0.5f, 0.0f},
{0.0f, 0.5f, -1.0f},
{-1.0f, 0.5f, 0.0f},
{0.707107f, 0.5f, 0.707107f},
{0.707107f, 0.5f, -0.707107f},
{-0.707107f, 0.5f, -0.707107f},
{-0.707107f, 0.5f, 0.707107f}
}), TestSuite::Compare::Container);
CORRADE_COMPARE(cylinder.normalArrayCount(), 0);
{0.0f, -0.5f, 1.0f}, /* 0 */
{1.0f, -0.5f, 0.0f}, /* 1 */
{0.0f, -0.5f, -1.0f}, /* 2 */
{-1.0f, -0.5f, 0.0f}, /* 3 */
{0.707107f, -0.5f, 0.707107f}, /* 4 */
{0.707107f, -0.5f, -0.707107f}, /* 5 */
{-0.707107f, -0.5f, -0.707107f}, /* 6 */
{-0.707107f, -0.5f, 0.707107f}, /* 7 */
{0.0f, 0.0f, 1.0f}, /* 8 */
{1.0f, 0.0f, 0.0f}, /* 9 */
{0.0f, 0.0f, -1.0f}, /* 10 */
{-1.0f, 0.0f, 0.0f}, /* 11 */
{0.707107f, 0.0f, 0.707107f}, /* 12 */
{0.707107f, 0.0f, -0.707107f}, /* 13 */
{-0.707107f, 0.0f, -0.707107f}, /* 14 */
{-0.707107f, 0.0f, 0.707107f}, /* 15 */
{0.0f, 0.5f, 1.0f}, /* 16 */
{1.0f, 0.5f, 0.0f}, /* 17 */
{0.0f, 0.5f, -1.0f}, /* 18 */
{-1.0f, 0.5f, 0.0f}, /* 19 */
{0.707107f, 0.5f, 0.707107f}, /* 20 */
{0.707107f, 0.5f, -0.707107f}, /* 21 */
{-0.707107f, 0.5f, -0.707107f}, /* 22 */
{-0.707107f, 0.5f, 0.707107f} /* 23 */
}), TestSuite::Compare::Container);
CORRADE_VERIFY(!cylinder.hasNormals());
CORRADE_VERIFY(!cylinder.hasTextureCoords2D());
CORRADE_COMPARE_AS(cylinder.indices(), (std::vector<UnsignedInt>{
0, 4, 1, 5, 2, 6, 3, 7,

Loading…
Cancel
Save