Browse Source

Primitives: remove template crap around Icosphere.

Now it has API similar to all other primitives. This thing was long
overdue.
pull/278/head
Vladimír Vondruš 13 years ago
parent
commit
c24853b041
  1. 21
      src/Primitives/Icosphere.cpp
  2. 45
      src/Primitives/Icosphere.h

21
src/Primitives/Icosphere.cpp

@ -25,10 +25,14 @@
#include "Icosphere.h"
#include "Math/Vector3.h"
#include "Trade/MeshData3D.h"
#include "MeshTools/Subdivide.h"
#include "MeshTools/RemoveDuplicates.h"
namespace Magnum { namespace Primitives {
Icosphere<0>::Icosphere(): MeshData3D(Mesh::Primitive::Triangles, {
Trade::MeshData3D Icosphere::solid(const UnsignedInt subdivisions) {
std::vector<UnsignedInt> indices{
1, 2, 6,
1, 7, 2,
3, 4, 5,
@ -49,7 +53,9 @@ Icosphere<0>::Icosphere(): MeshData3D(Mesh::Primitive::Triangles, {
7, 1, 0,
3, 9, 8,
4, 8, 0
}, {}, {{
};
std::vector<Vector3> vertices{
{0.0f, -0.525731f, 0.850651f},
{0.850651f, 0.0f, 0.525731f},
{0.850651f, 0.0f, -0.525731f},
@ -62,8 +68,15 @@ Icosphere<0>::Icosphere(): MeshData3D(Mesh::Primitive::Triangles, {
{0.0f, -0.525731f, -0.850651f},
{0.0f, 0.525731f, -0.850651f},
{0.0f, 0.525731f, 0.850651f}
}}, {}) {
positions(0).assign(normals(0).begin(), normals(0).end());
};
for(std::size_t i = 0; i != subdivisions; ++i)
MeshTools::subdivide(indices, vertices, [](const Vector3& a, const Vector3& b) {
return (a+b).normalized();
});
MeshTools::removeDuplicates(indices, vertices);
return Trade::MeshData3D(Mesh::Primitive::Triangles, std::move(indices), {vertices}, {std::move(vertices)}, {});
}
}}

45
src/Primitives/Icosphere.h

@ -28,53 +28,26 @@
* @brief Class Magnum::Primitives::Icosphere
*/
#include "Math/Vector3.h"
#include "MeshTools/RemoveDuplicates.h"
#include "MeshTools/Subdivide.h"
#include "Trade/MeshData3D.h"
#include "Trade/Trade.h"
#include "Primitives/magnumPrimitivesVisibility.h"
namespace Magnum { namespace Primitives {
/** @todoc Remove `ifndef` when Doxygen is sane again */
#ifndef DOXYGEN_GENERATING_OUTPUT
template<std::size_t subdivisions> class MAGNUM_PRIMITIVES_EXPORT Icosphere;
#endif
/**
@brief 3D icosphere primitive with zero subdivisions
@brief 3D icosphere primitive
Indexed @ref Mesh::Primitive "Triangles" with normals.
Sphere with radius `1`.
*/
template<> class Icosphere<0>: public Trade::MeshData3D {
class MAGNUM_PRIMITIVES_EXPORT Icosphere {
public:
/** @brief Constructor */
explicit Icosphere();
};
/**
@brief 3D icosphere primitive
@tparam subdivisions Number of subdivisions
Indexed @ref Mesh::Primitive "Triangles" with normals.
* @brief Solid icosphere
* @param subdivisions Number of subdivisions
*
* Indexed @ref Mesh::Primitive "Triangles" with normals.
*/
#ifndef DOXYGEN_GENERATING_OUTPUT
template<std::size_t subdivisions> class Icosphere: public Icosphere<0> {
#else
template<std::size_t subdivisions> class Icosphere {
#endif
public:
/** @brief Constructor */
explicit Icosphere() {
for(std::size_t i = 0; i != subdivisions; ++i)
MeshTools::subdivide(indices(), normals(0), [](const Vector3& a, const Vector3& b) {
return (a+b).normalized();
});
MeshTools::removeDuplicates(indices(), normals(0));
positions(0)->assign(normals(0)->begin(), normals(0)->end());
}
static Trade::MeshData3D solid(UnsignedInt subdivisions);
};
}}

Loading…
Cancel
Save