Browse Source

Primitives: new solid and wireframe cone primitive.

pull/205/head
Vladimír Vondruš 8 years ago
parent
commit
8662919a2b
  1. 3
      doc/changelog.dox
  2. 13
      doc/generated/primitives.cpp
  3. BIN
      doc/primitives-conesolid.png
  4. BIN
      doc/primitives-conewireframe.png
  5. 2
      src/Magnum/Primitives/CMakeLists.txt
  6. 2
      src/Magnum/Primitives/Capsule.cpp
  7. 73
      src/Magnum/Primitives/Cone.cpp
  8. 100
      src/Magnum/Primitives/Cone.h
  9. 2
      src/Magnum/Primitives/Cylinder.cpp
  10. 6
      src/Magnum/Primitives/Cylinder.h
  11. 11
      src/Magnum/Primitives/Implementation/Spheroid.cpp
  12. 2
      src/Magnum/Primitives/Implementation/Spheroid.h
  13. 2
      src/Magnum/Primitives/Test/CMakeLists.txt
  14. 200
      src/Magnum/Primitives/Test/ConeTest.cpp
  15. 3
      src/Magnum/Primitives/Test/CylinderTest.cpp

3
doc/changelog.dox

@ -53,7 +53,8 @@ See also:
@subsubsection changelog-latest-new-primitives Primitives library
- New @ref Primitives::circle3DSolid() and @ref Primitives::circle3DWireframe()
- New @ref Primitives::circle3DSolid(), @ref Primitives::circle3DWireframe(),
@ref Primitives::coneSolid() and @ref Primitives::coneWireframe()
primitives
@subsection changelog-latest-deprecated Deprecated APIs

13
doc/generated/primitives.cpp

@ -53,6 +53,7 @@
#include <Magnum/Primitives/Capsule.h>
#include <Magnum/Primitives/Circle.h>
#include <Magnum/Primitives/Crosshair.h>
#include <Magnum/Primitives/Cone.h>
#include <Magnum/Primitives/Cube.h>
#include <Magnum/Primitives/Cylinder.h>
#include <Magnum/Primitives/Icosphere.h>
@ -92,6 +93,7 @@ struct PrimitiveVisualizer: Platform::WindowlessApplication {
std::pair<Trade::MeshData3D, std::string> capsule3DWireframe();
std::pair<Trade::MeshData3D, std::string> circle3DWireframe();
std::pair<Trade::MeshData3D, std::string> crosshair3D();
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> line3D();
@ -103,6 +105,7 @@ struct PrimitiveVisualizer: Platform::WindowlessApplication {
std::pair<Trade::MeshData3D, std::string> capsule3DSolid();
std::pair<Trade::MeshData3D, std::string> circle3DSolid();
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> icosphereSolid();
@ -251,6 +254,7 @@ int PrimitiveVisualizer::exec() {
for(auto fun: {&PrimitiveVisualizer::capsule3DWireframe,
&PrimitiveVisualizer::circle3DWireframe,
&PrimitiveVisualizer::crosshair3D,
&PrimitiveVisualizer::coneWireframe,
&PrimitiveVisualizer::cubeWireframe,
&PrimitiveVisualizer::cylinderWireframe,
&PrimitiveVisualizer::line3D,
@ -330,6 +334,7 @@ int PrimitiveVisualizer::exec() {
for(auto fun: {&PrimitiveVisualizer::capsule3DSolid,
&PrimitiveVisualizer::circle3DSolid,
&PrimitiveVisualizer::coneSolid,
&PrimitiveVisualizer::cubeSolid,
&PrimitiveVisualizer::cylinderSolid,
&PrimitiveVisualizer::icosphereSolid,
@ -404,6 +409,10 @@ std::pair<Trade::MeshData3D, std::string> PrimitiveVisualizer::crosshair3D() {
return {Primitives::crosshair3D(), "crosshair3d.png"};
}
std::pair<Trade::MeshData3D, std::string> PrimitiveVisualizer::coneWireframe() {
return {Primitives::coneWireframe(32, 1.25f), "conewireframe.png"};
}
std::pair<Trade::MeshData3D, std::string> PrimitiveVisualizer::cubeWireframe() {
return {Primitives::cubeWireframe(), "cubewireframe.png"};
}
@ -444,6 +453,10 @@ std::pair<Trade::MeshData3D, std::string> PrimitiveVisualizer::circle3DSolid() {
return {Primitives::circle3DSolid(16), "circle3dsolid.png"};
}
std::pair<Trade::MeshData3D, std::string> PrimitiveVisualizer::coneSolid() {
return {Primitives::coneSolid(1, 12, 1.25f, Primitives::ConeFlag::CapEnd), "conesolid.png"};
}
std::pair<Trade::MeshData3D, std::string> PrimitiveVisualizer::cubeSolid() {
return {Primitives::cubeSolid(), "cubesolid.png"};
}

BIN
doc/primitives-conesolid.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
doc/primitives-conewireframe.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

2
src/Magnum/Primitives/CMakeLists.txt

@ -28,6 +28,7 @@ set(MagnumPrimitives_SRCS
Capsule.cpp
Circle.cpp
Crosshair.cpp
Cone.cpp
Cube.cpp
Cylinder.cpp
Icosphere.cpp
@ -44,6 +45,7 @@ set(MagnumPrimitives_HEADERS
Capsule.h
Circle.h
Crosshair.h
Cone.h
Cube.h
Cylinder.h
Icosphere.h

2
src/Magnum/Primitives/Capsule.cpp

@ -112,7 +112,7 @@ Trade::MeshData3D capsule3DSolid(const UnsignedInt hemisphereRings, const Unsign
capsule.hemisphereVertexRings(hemisphereRings-1, -halfLength, -Rad(Constants::piHalf())+hemisphereRingAngleIncrement, hemisphereRingAngleIncrement, hemisphereTextureCoordsVIncrement, hemisphereTextureCoordsVIncrement);
/* Rings of cylinder */
capsule.cylinderVertexRings(cylinderRings+1, -halfLength, 2.0f*halfLength/cylinderRings, 1.0f/height, 2.0f*halfLength/(cylinderRings*height));
capsule.cylinderVertexRings(cylinderRings+1, -halfLength, {0.0f, 2.0f*halfLength/cylinderRings}, 1.0f/height, 2.0f*halfLength/(cylinderRings*height));
/* Rings of top hemisphere */
capsule.hemisphereVertexRings(hemisphereRings-1, halfLength, hemisphereRingAngleIncrement, hemisphereRingAngleIncrement, (1.0f + 2.0f*halfLength)/height+hemisphereTextureCoordsVIncrement, hemisphereTextureCoordsVIncrement);

73
src/Magnum/Primitives/Cone.cpp

@ -0,0 +1,73 @@
/*
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 "Cone.h"
#include "Magnum/Mesh.h"
#include "Magnum/Math/Color.h"
#include "Magnum/Primitives/Implementation/Spheroid.h"
#include "Magnum/Primitives/Implementation/WireframeSpheroid.h"
#include "Magnum/Trade/MeshData3D.h"
namespace Magnum { namespace Primitives {
Trade::MeshData3D coneSolid(const UnsignedInt rings, const UnsignedInt segments, const Float halfLength, const ConeFlags flags) {
CORRADE_ASSERT(rings >= 1 && segments >= 3,
"Primitives::coneSolid(): at least one ring and three segments expected",
(Trade::MeshData3D{MeshPrimitive::Triangles, {}, {}, {}, {}, {}, nullptr}));
Implementation::Spheroid cone{segments, flags & ConeFlag::GenerateTextureCoords ? Implementation::Spheroid::TextureCoords::Generate : Implementation::Spheroid::TextureCoords::DontGenerate};
const Float length = 2.0f*halfLength;
const Float textureCoordsV = flags & ConeFlag::CapEnd ? 1.0f/(length + 1.0f) : 0.0f;
/* Bottom cap */
if(flags & ConeFlag::CapEnd) {
cone.capVertex(-halfLength, -1.0f, 0.0f);
cone.capVertexRing(-halfLength, textureCoordsV, Vector3::yAxis(-1.0f));
}
/* Vertex rings */
cone.cylinderVertexRings(rings+1, -halfLength, {-1.0f/rings, length/rings}, textureCoordsV, length/(rings*(flags & ConeFlag::CapEnd ? length + 1.0f : length)));
/* Faces */
if(flags & ConeFlag::CapEnd) cone.bottomFaceRing();
cone.faceRings(rings, flags & ConeFlag::CapEnd ? (1 + segments) : 0);
return cone.finalize();
}
Trade::MeshData3D coneWireframe(const UnsignedInt segments, const Float halfLength) {
CORRADE_ASSERT(segments >= 4 && segments%4 == 0,
"Primitives::cylinderWireframe(): multiples of 4 segments expected",
(Trade::MeshData3D{MeshPrimitive::Lines, {}, {}, {}, {}, {}, nullptr}));
Implementation::WireframeSpheroid cone{segments/4};
cone.ring(-halfLength);
cone.topHemisphere(halfLength - 1.0f, 1);
return cone.finalize();
}
}}

100
src/Magnum/Primitives/Cone.h

@ -0,0 +1,100 @@
#ifndef Magnum_Primitives_Cone_h
#define Magnum_Primitives_Cone_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::coneSolid(), @ref Magnum::Primitives::coneWireframe()
*/
#include <Corrade/Containers/EnumSet.h>
#include "Magnum/Magnum.h"
#include "Magnum/Primitives/visibility.h"
#include "Magnum/Trade/Trade.h"
namespace Magnum { namespace Primitives {
/**
@brief Cone flag
@see @ref ConeFlags, @ref coneSolid()
*/
enum class ConeFlag {
GenerateTextureCoords = 1 << 0, /**< Generate texture coordinates */
CapEnd = 1 << 1 /**< Cap end */
};
/**
@brief Cone flags
@see @ref coneSolid()
*/
typedef Containers::EnumSet<ConeFlag> ConeFlags;
CORRADE_ENUMSET_OPERATORS(ConeFlags)
/**
@brief Solid 3D cone
@param rings Number of (face) rings. Must be larger or equal to
@cpp 1 @ce.
@param segments Number of (face) segments. Must be larger or equal to
@cpp 3 @ce.
@param halfLength Half the cone length
@param flags Flags
Cone along Y axis of radius @cpp 1.0f @ce. Indexed
@ref MeshPrimitive::Triangles. Note that in order to have properly smooth
normals over the whole area, the tip consists of @cpp segments*2 @ce vertices
instead of just one.
@image html primitives-conesolid.png
The cone is by default created with radius set to @f$ 1.0 @f$. In order to get
radius @f$ r @f$, length @f$ l @f$ and preserve correct normals, set
@p halfLength to @f$ 0.5 \frac{l}{r} @f$ and then scale all
@ref Trade::MeshData3D::positions() by @f$ r @f$, for example using
@ref MeshTools::transformPointsInPlace().
@see @ref coneWireframe(), @ref cylinderSolid()
*/
MAGNUM_PRIMITIVES_EXPORT Trade::MeshData3D coneSolid(UnsignedInt rings, UnsignedInt segments, Float halfLength, ConeFlags flags = {});
/**
@brief Wireframe 3D cone
@param segments Number of (line) segments. Must be larger or equal to
@cpp 4 @ce and multiple of @cpp 4 @ce.
@param halfLength Half the cone length
Cone along Y axis of radius @cpp 1.0f @ce. Indexed @ref MeshPrimitive::Lines.
@image html primitives-conewireframe.png
@see @ref coneSolid(), @ref cylinderWireframe()
*/
MAGNUM_PRIMITIVES_EXPORT Trade::MeshData3D coneWireframe(UnsignedInt segments, Float halfLength);
}}
#endif

2
src/Magnum/Primitives/Cylinder.cpp

@ -50,7 +50,7 @@ Trade::MeshData3D cylinderSolid(const UnsignedInt rings, const UnsignedInt segme
}
/* Vertex rings */
cylinder.cylinderVertexRings(rings+1, -halfLength, length/rings, textureCoordsV, length/(rings*(flags & CylinderFlag::CapEnds ? length + 2.0f : length)));
cylinder.cylinderVertexRings(rings+1, -halfLength, {0.0f, length/rings}, textureCoordsV, length/(rings*(flags & CylinderFlag::CapEnds ? length + 2.0f : length)));
/* Top cap */
if(flags & CylinderFlag::CapEnds) {

6
src/Magnum/Primitives/Cylinder.h

@ -44,7 +44,7 @@ namespace Magnum { namespace Primitives {
*/
enum class CylinderFlag {
GenerateTextureCoords = 1 << 0, /**< Generate texture coordinates */
CapEnds = 1 << 1 /**< Cap ends */
CapEnds = 1 << 1 /**< Cap ends */
};
/**
@ -77,7 +77,7 @@ get radius @f$ r @f$, length @f$ l @f$ and preserve correct normals, set
@p halfLength to @f$ 0.5 \frac{l}{r} @f$ and then scale all
@ref Trade::MeshData3D::positions() by @f$ r @f$, for example using
@ref MeshTools::transformPointsInPlace().
@see @ref cylinderWireframe()
@see @ref cylinderWireframe(), @ref coneSolid()
*/
MAGNUM_PRIMITIVES_EXPORT Trade::MeshData3D cylinderSolid(UnsignedInt rings, UnsignedInt segments, Float halfLength, CylinderFlags flags = {});
@ -94,7 +94,7 @@ Cylinder along Y axis of radius @cpp 1.0f @ce. Indexed
@image html primitives-cylinderwireframe.png
@see @ref cylinderSolid()
@see @ref cylinderSolid(), @ref coneWireframe()
*/
MAGNUM_PRIMITIVES_EXPORT Trade::MeshData3D cylinderWireframe(UnsignedInt rings, UnsignedInt segments, Float halfLength);

11
src/Magnum/Primitives/Implementation/Spheroid.cpp

@ -68,13 +68,16 @@ void Spheroid::hemisphereVertexRings(UnsignedInt count, Float centerY, Rad start
}
}
void Spheroid::cylinderVertexRings(UnsignedInt count, Float startY, Float yIncrement, Float startTextureCoordsV, Float textureCoordsVIncrement) {
void Spheroid::cylinderVertexRings(const UnsignedInt count, const Float startY, const Vector2& increment, const Float startTextureCoordsV, const Float textureCoordsVIncrement) {
const Vector2 baseNormal = -increment.perpendicular().normalized();
Vector2 base = {1.0f, startY};
Rad segmentAngleIncrement(Constants::tau()/segments);
for(UnsignedInt i = 0; i != count; ++i) {
for(UnsignedInt j = 0; j != segments; ++j) {
Rad segmentAngle = Float(j)*segmentAngleIncrement;
positions.emplace_back(Math::sin(segmentAngle), startY, Math::cos(segmentAngle));
normals.emplace_back(Math::sin(segmentAngle), 0.0f, Math::cos(segmentAngle));
positions.emplace_back(base.x()*Math::sin(segmentAngle), base.y(), base.x()*Math::cos(segmentAngle));
normals.emplace_back(baseNormal.x()*Math::sin(segmentAngle), baseNormal.y(), baseNormal.x()*Math::cos(segmentAngle));
if(textureCoords == TextureCoords::Generate)
textureCoords2D.emplace_back(j*1.0f/segments, startTextureCoordsV + i*textureCoordsVIncrement);
@ -87,7 +90,7 @@ void Spheroid::cylinderVertexRings(UnsignedInt count, Float startY, Float yIncre
textureCoords2D.emplace_back(1.0f, startTextureCoordsV + i*textureCoordsVIncrement);
}
startY += yIncrement;
base += increment;
}
}

2
src/Magnum/Primitives/Implementation/Spheroid.h

@ -43,7 +43,7 @@ class Spheroid {
void capVertex(Float y, Float normalY, Float textureCoordsV);
void hemisphereVertexRings(UnsignedInt count, Float centerY, Rad startRingAngle, Rad ringAngleIncrement, Float startTextureCoordsV, Float textureCoordsVIncrement);
void cylinderVertexRings(UnsignedInt count, Float startY, Float yIncrement, Float startTextureCoordsV, Float textureCoordsVIncrement);
void cylinderVertexRings(UnsignedInt count, Float startY, const Vector2& increment, Float startTextureCoordsV, Float textureCoordsVIncrement);
void bottomFaceRing();
void faceRings(UnsignedInt count, UnsignedInt offset = 1);
void topFaceRing();

2
src/Magnum/Primitives/Test/CMakeLists.txt

@ -28,6 +28,7 @@ corrade_add_test(PrimitivesCapsuleTest CapsuleTest.cpp LIBRARIES MagnumPrimitive
corrade_add_test(PrimitivesCircleTest CircleTest.cpp LIBRARIES MagnumPrimitives)
corrade_add_test(PrimitivesCrosshairTest CrosshairTest.cpp LIBRARIES MagnumPrimitives)
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(PrimitivesIcosphereTest IcosphereTest.cpp LIBRARIES MagnumPrimitives)
corrade_add_test(PrimitivesLineTest LineTest.cpp LIBRARIES MagnumPrimitives)
@ -41,6 +42,7 @@ set_target_properties(
PrimitivesCircleTest
PrimitivesCrosshairTest
PrimitivesCubeTest
PrimitivesConeTest
PrimitivesCylinderTest
PrimitivesIcosphereTest
PrimitivesLineTest

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

@ -0,0 +1,200 @@
/*
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/Cone.h"
#include "Magnum/Trade/MeshData3D.h"
namespace Magnum { namespace Primitives { namespace Test {
struct ConeTest: TestSuite::Tester {
explicit ConeTest();
void solidWithoutAnything();
void solidWithTextureCoordsAndCaps();
void wireframe();
};
ConeTest::ConeTest() {
addTests({&ConeTest::solidWithoutAnything,
&ConeTest::solidWithTextureCoordsAndCaps,
&ConeTest::wireframe});
}
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, 0.0f, 0.5f},
{0.433013f, 0.0f, -0.25f},
{-0.433013f, 0.0f, -0.25f},
{0.0f, 1.0f, 0.0f},
{0.0f, 1.0f, 0.0f},
{0.0f, 1.0f, 0.0f}
}), 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.774597f, 0.447214f, -0.447214f},
{-0.774597f, 0.447214f, -0.447214f},
{0.0f, 0.447214f, 0.894427f},
{0.774597f, 0.447214f, -0.447214f},
{-0.774597f, 0.447214f, -0.447214f}
}), TestSuite::Compare::Container);
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);
/* 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, 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},
{0.866025f, -1.0f, -0.5f},
{-0.866025f, -1.0f, -0.5f},
{0.0f, -1.0f, 1.0f},
{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, 1.0f, 0.0f},
{0.0f, 1.0f, 0.0f},
{0.0f, 1.0f, 0.0f},
{0.0f, 1.0f, 0.0f}
}), 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.0f, -1.0f, 0.0f},
{0.0f, -1.0f, 0.0f},
{0.0f, -1.0f, 0.0f},
{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},
{0.774597f, 0.447214f, -0.447214f},
{-0.774597f, 0.447214f, -0.447214f},
{0.0f, 0.447214f, 0.894427f},
{0.0f, 0.447214f, 0.894427f},
{0.774597f, 0.447214f, -0.447214f},
{-0.774597f, 0.447214f, -0.447214f},
{0.0f, 0.447214f, 0.894427f}
}), TestSuite::Compare::Container);
CORRADE_COMPARE_AS(cone.textureCoords2D(0), (std::vector<Vector2>{
{0.5f, 0.0f},
{0.0f, 0.333333f},
{0.333333f, 0.333333f},
{0.666667f, 0.333333f},
{1.0f, 0.333333f},
{0.0f, 0.333333f},
{0.333333f, 0.333333f},
{0.666667f, 0.333333f},
{1.0f, 0.333333f},
{0.0f, 0.666667f},
{0.333333f, 0.666667f},
{0.666667f, 0.666667f},
{1.0f, 0.666667f},
{0.0f, 1.0f},
{0.333333f, 1.0f},
{0.666667f, 1.0f},
{1.0f, 1.0f},
}), TestSuite::Compare::Container);
/* 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, 4, 3,
4, 5, 9, 4, 9, 8, 5, 6, 10, 5, 10, 9, 6, 7, 11, 6, 11, 10,
8, 9, 13, 8, 13, 12, 9, 10, 14, 9, 14, 13, 10, 11, 15, 10, 15, 14
}), TestSuite::Compare::Container);
}
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}
}), TestSuite::Compare::Container);
CORRADE_COMPARE(cone.normalArrayCount(), 0);
CORRADE_COMPARE_AS(cone.indices(), (std::vector<UnsignedInt>{
0, 4, 1, 5, 2, 6, 3, 7,
4, 1, 5, 2, 6, 3, 7, 0,
0, 8, 1, 8, 2, 8, 3, 8
}), TestSuite::Compare::Container);
}
}}}
CORRADE_TEST_MAIN(Magnum::Primitives::Test::ConeTest)

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

@ -86,7 +86,8 @@ void CylinderTest::solidWithoutAnything() {
void CylinderTest::solidWithTextureCoordsAndCaps() {
Trade::MeshData3D cylinder = cylinderSolid(2, 3, 1.5f, CylinderFlag::GenerateTextureCoords|CylinderFlag::CapEnds);
/* First and last ring are duplicated because they have different normals */
/* 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},

Loading…
Cancel
Save