|
|
|
|
#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"
|
|
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
|
|
|
|
|
Indexed @ref Mesh::Primitive "Triangles" with normals.
|
|
|
|
|
*/
|
|
|
|
|
template<> class Icosphere<0>: public Trade::MeshData3D {
|
|
|
|
|
public:
|
|
|
|
|
/** @brief Constructor */
|
|
|
|
|
explicit Icosphere();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@brief 3D icosphere primitive
|
|
|
|
|
@tparam 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::clean(*indices(), *normals(0));
|
Trade: got rid of Point2D/3D in MeshData in favor of Vector2/Vector3.
Positions were originally done using Point2D/3D to simplify their
transformation using matrices and to some extent simplify their usage in
shaders. But now the disadvantages exceeded the advantages:
* They take 50% more for 2D positions and 33% more for 3D positions, as
last coordinate is always equal to 1, on the other hand when last
coordinate is errorneously not equal to 1 they have crazy behavior.
* Normalizing them or transforming them with anything else than with
matrices is PITA, as we need to strip the last component, do the
transformation, and then add the component back.
* All transformation handling classes (Complex, DualComplex,
Quaternion, DualQuaternion, Matrix3, Matrix4) now have convenience
functions for transforming points specified directly as
Vector2/Vector3 (and also for transforming vectors).
* When someone wants to use homogeneous coordinates with crazy last
component values, they can do so with plain Vector3 for 2D and
Vector4 for 3D and it will be less confusing than using Point2D/3D
which no important detail hidden.
13 years ago
|
|
|
positions(0)->assign(normals(0)->begin(), normals(0)->end());
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
|
|
#endif
|