Browse Source

Added normals array to Icosphere primitive.

vectorfields
Vladimír Vondruš 14 years ago
parent
commit
eacad4895f
  1. 30
      src/Primitives/Icosphere.cpp
  2. 7
      src/Primitives/Icosphere.h

30
src/Primitives/Icosphere.cpp

@ -40,19 +40,21 @@ Icosphere<0>::Icosphere(): MeshData(Mesh::Primitive::Triangles, new vector<unsig
7, 1, 0,
3, 9, 8,
4, 8, 0
}, {new vector<Vector4>{
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),
Vector4(-0.525731f, 0.850651f, 0),
Vector4(0.525731f, 0.850651f, 0),
Vector4(0.525731f, -0.850651f, 0),
Vector4(-0.525731f, -0.850651f, 0),
Vector4(0, -0.525731f, -0.850651f),
Vector4(0, 0.525731f, -0.850651f),
Vector4(0, 0.525731f, 0.850651f)
}}, {nullptr}, {nullptr}) {}
}, {new vector<Vector4>}, {new vector<Vector3>{
Vector3(0, -0.525731f, 0.850651f),
Vector3(0.850651f, 0, 0.525731f),
Vector3(0.850651f, 0, -0.525731f),
Vector3(-0.850651f, 0, -0.525731f),
Vector3(-0.850651f, 0, 0.525731f),
Vector3(-0.525731f, 0.850651f, 0),
Vector3(0.525731f, 0.850651f, 0),
Vector3(0.525731f, -0.850651f, 0),
Vector3(-0.525731f, -0.850651f, 0),
Vector3(0, -0.525731f, -0.850651f),
Vector3(0, 0.525731f, -0.850651f),
Vector3(0, 0.525731f, 0.850651f)
}}, {nullptr}) {
vertices(0)->assign(normals(0)->begin(), normals(0)->end());
}
}}

7
src/Primitives/Icosphere.h

@ -48,11 +48,12 @@ template<size_t subdivisions> class Icosphere: public Icosphere<0> {
/** @brief Constructor */
Icosphere() {
for(size_t i = 0; i != subdivisions; ++i)
MeshTools::subdivide(*indices(), *vertices(0), [](const Vector4& a, const Vector4& b) {
return (a+b).xyz().normalized();
MeshTools::subdivide(*indices(), *normals(0), [](const Vector3& a, const Vector3& b) {
return (a+b).normalized();
});
MeshTools::clean(*indices(), *vertices(0));
MeshTools::clean(*indices(), *normals(0));
vertices(0)->assign(normals(0)->begin(), normals(0)->end());
}
};

Loading…
Cancel
Save