mirror of https://github.com/mosra/magnum.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.9 KiB
67 lines
1.9 KiB
#ifndef Magnum_Primitives_Icosphere_h |
|
#define Magnum_Primitives_Icosphere_h |
|
/* |
|
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz> |
|
|
|
This file is part of Magnum. |
|
|
|
Magnum is free software: you can redistribute it and/or modify |
|
it under the terms of the GNU Lesser General Public License version 3 |
|
only, as published by the Free Software Foundation. |
|
|
|
Magnum is distributed in the hope that it will be useful, |
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
GNU Lesser General Public License version 3 for more details. |
|
*/ |
|
|
|
/** @file |
|
* @brief Class Magnum::Primitives::Icosphere |
|
*/ |
|
|
|
#include "Math/Vector3.h" |
|
#include "MeshTools/Subdivide.h" |
|
#include "MeshTools/Clean.h" |
|
#include "Trade/MeshData3D.h" |
|
|
|
namespace Magnum { namespace Primitives { |
|
|
|
template<size_t subdivisions> class Icosphere; |
|
|
|
/** |
|
@brief %Icosphere primitive with zero subdivisions |
|
|
|
@todo Use own computed (and more precise) icosahedron data, not these stolen |
|
from Blender. |
|
*/ |
|
template<> class Icosphere<0>: public Trade::MeshData3D { |
|
public: |
|
/** @brief Constructor */ |
|
Icosphere(); |
|
}; |
|
|
|
/** |
|
* @brief %Icosphere primitive |
|
* @tparam subdivisions Number of subdivisions |
|
*/ |
|
#ifndef DOXYGEN_GENERATING_OUTPUT |
|
template<size_t subdivisions> class Icosphere: public Icosphere<0> { |
|
#else |
|
template<size_t subdivisions> class Icosphere { |
|
#endif |
|
public: |
|
/** @brief Constructor */ |
|
Icosphere() { |
|
for(size_t i = 0; i != subdivisions; ++i) |
|
MeshTools::subdivide(*indices(), *normals(0), [](const Vector3& a, const Vector3& b) { |
|
return (a+b).normalized(); |
|
}); |
|
|
|
MeshTools::clean(*indices(), *normals(0)); |
|
positions(0)->assign(normals(0)->begin(), normals(0)->end()); |
|
} |
|
}; |
|
|
|
}} |
|
|
|
#endif
|
|
|