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. 85
      src/Primitives/Icosphere.cpp
  2. 47
      src/Primitives/Icosphere.h

85
src/Primitives/Icosphere.cpp

@ -25,45 +25,58 @@
#include "Icosphere.h" #include "Icosphere.h"
#include "Math/Vector3.h" #include "Math/Vector3.h"
#include "Trade/MeshData3D.h"
#include "MeshTools/Subdivide.h"
#include "MeshTools/RemoveDuplicates.h"
namespace Magnum { namespace Primitives { namespace Magnum { namespace Primitives {
Icosphere<0>::Icosphere(): MeshData3D(Mesh::Primitive::Triangles, { Trade::MeshData3D Icosphere::solid(const UnsignedInt subdivisions) {
1, 2, 6, std::vector<UnsignedInt> indices{
1, 7, 2, 1, 2, 6,
3, 4, 5, 1, 7, 2,
4, 3, 8, 3, 4, 5,
6, 5, 11, 4, 3, 8,
5, 6, 10, 6, 5, 11,
9, 10, 2, 5, 6, 10,
10, 9, 3, 9, 10, 2,
7, 8, 9, 10, 9, 3,
8, 7, 0, 7, 8, 9,
11, 0, 1, 8, 7, 0,
0, 11, 4, 11, 0, 1,
6, 2, 10, 0, 11, 4,
1, 6, 11, 6, 2, 10,
3, 5, 10, 1, 6, 11,
5, 4, 11, 3, 5, 10,
2, 7, 9, 5, 4, 11,
7, 1, 0, 2, 7, 9,
3, 9, 8, 7, 1, 0,
4, 8, 0 3, 9, 8,
}, {}, {{ 4, 8, 0
{0.0f, -0.525731f, 0.850651f}, };
{0.850651f, 0.0f, 0.525731f},
{0.850651f, 0.0f, -0.525731f}, std::vector<Vector3> vertices{
{-0.850651f, 0.0f, -0.525731f}, {0.0f, -0.525731f, 0.850651f},
{-0.850651f, 0.0f, 0.525731f}, {0.850651f, 0.0f, 0.525731f},
{-0.525731f, 0.850651f, 0.0f}, {0.850651f, 0.0f, -0.525731f},
{0.525731f, 0.850651f, 0.0f}, {-0.850651f, 0.0f, -0.525731f},
{0.525731f, -0.850651f, 0.0f}, {-0.850651f, 0.0f, 0.525731f},
{-0.525731f, -0.850651f, 0.0f}, {-0.525731f, 0.850651f, 0.0f},
{0.0f, -0.525731f, -0.850651f}, {0.525731f, 0.850651f, 0.0f},
{0.0f, 0.525731f, -0.850651f}, {0.525731f, -0.850651f, 0.0f},
{0.0f, 0.525731f, 0.850651f} {-0.525731f, -0.850651f, 0.0f},
}}, {}) { {0.0f, -0.525731f, -0.850651f},
positions(0).assign(normals(0).begin(), normals(0).end()); {0.0f, 0.525731f, -0.850651f},
{0.0f, 0.525731f, 0.850651f}
};
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)}, {});
} }
}} }}

47
src/Primitives/Icosphere.h

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

Loading…
Cancel
Save