Browse Source

Making Icosahedron primitive data public, so it could be reused.

pull/279/head
Vladimír Vondruš 15 years ago
parent
commit
2b3aab35f6
  1. 11
      src/Primitives/Icosphere.cpp
  2. 21
      src/Primitives/Icosphere.h

11
src/Primitives/Icosphere.cpp

@ -17,13 +17,7 @@
namespace Magnum { namespace Primitives { namespace Magnum { namespace Primitives {
/** const Vector4 Icosahedron::vertices[] = {
* @todo Use own computed (and more precise) icosahedron data, not these stolen
* from Blender.
*/
#ifndef DOXYGEN_GENERATING_OUTPUT
const Vector4 _AbstractIcosphere::initialVertices[] = {
Vector4(0, -0.525731f, 0.850651f), Vector4(0, -0.525731f, 0.850651f),
Vector4(0.850651f, 0, 0.525731f), Vector4(0.850651f, 0, 0.525731f),
Vector4(0.850651f, 0, -0.525731f), Vector4(0.850651f, 0, -0.525731f),
@ -37,7 +31,7 @@ const Vector4 _AbstractIcosphere::initialVertices[] = {
Vector4(0, 0.525731f, -0.850651f), Vector4(0, 0.525731f, -0.850651f),
Vector4(0, 0.525731f, 0.850651f), Vector4(0, 0.525731f, 0.850651f),
}; };
const GLubyte _AbstractIcosphere::initialIndices[] = { const GLubyte Icosahedron::indices[] = {
1, 2, 6, 1, 2, 6,
1, 7, 2, 1, 7, 2,
3, 4, 5, 3, 4, 5,
@ -59,6 +53,5 @@ const GLubyte _AbstractIcosphere::initialIndices[] = {
3, 9, 8, 3, 9, 8,
4, 8, 0 4, 8, 0
}; };
#endif
}} }}

21
src/Primitives/Icosphere.h

@ -25,22 +25,23 @@
namespace Magnum { namespace Primitives { namespace Magnum { namespace Primitives {
#ifndef DOXYGEN_GENERATING_OUTPUT /**
class _AbstractIcosphere { @brief Icosahedron
public:
~_AbstractIcosphere() {}
protected: @todo Use own computed (and more precise) icosahedron data, not these stolen
static const Vector4 initialVertices[]; from Blender.
static const GLubyte initialIndices[]; */
class Icosahedron {
public:
static const Vector4 vertices[]; /**< @brief Vertices */
static const GLubyte indices[]; /**< @brief Indices */
}; };
#endif
/** /**
* @brief %Icosphere primitive * @brief %Icosphere primitive
* @tparam subdivisions Number of subdivisions * @tparam subdivisions Number of subdivisions
*/ */
template<size_t subdivisions> class Icosphere: public AbstractPrimitive<typename SizeTraits<Log<256, Pow<4, subdivisions>::value*20*3>::value>::SizeType>, _AbstractIcosphere { template<size_t subdivisions> class Icosphere: public AbstractPrimitive<typename SizeTraits<Log<256, Pow<4, subdivisions>::value*20*3>::value>::SizeType> {
public: public:
Icosphere() { Icosphere() {
if(vertexCount() == 0) subdivide(); if(vertexCount() == 0) subdivide();
@ -63,7 +64,7 @@ template<size_t subdivisions> class Icosphere: public AbstractPrimitive<typename
} }
static void subdivide() { static void subdivide() {
builder()->setData(initialVertices, initialIndices, 12, 60); builder()->setData(Icosahedron::vertices, Icosahedron::indices, 12, 60);
for(size_t i = 0; i != subdivisions; ++i) for(size_t i = 0; i != subdivisions; ++i)
builder()->subdivide([](const Vector4& a, const Vector4& b) { builder()->subdivide([](const Vector4& a, const Vector4& b) {

Loading…
Cancel
Save