3es  0.7
3esspheretessellator.h
1 //
2 // author: Kazys Stepanas
3 //
4 #ifndef _3ESSPHERETESSELLATOR_H_
5 #define _3ESSPHERETESSELLATOR_H_
6 
7 #include "3es-core.h"
8 
9 #include "3esvector3.h"
10 #include "3esvectorhash.h"
11 
12 #include <unordered_map>
13 #include <vector>
14 
15 namespace tes
16 {
17  struct _3es_coreAPI SphereVertexHash
18  {
19  size_t operator()(const Vector3f &v) const;
20  size_t operator()(const Vector3d &v) const;
21  };
22 
23  typedef std::unordered_map<Vector3f, unsigned, SphereVertexHash> SphereVertexMap;
24 
25  inline size_t SphereVertexHash::operator()(const Vector3f &v) const
26  {
27  return vhash::hash(v.x, v.y, v.z);
28  }
29 
30 
31  inline size_t SphereVertexHash::operator()(const Vector3d &v) const
32  {
33  return vhash::hash(float(v.x), float(v.y), float(v.z));
34  }
35 
40  void _3es_coreAPI sphereInitialise(std::vector<Vector3f> &vertices, std::vector<unsigned> &indices, SphereVertexMap *vertexMap = nullptr);
41 
46  void _3es_coreAPI subdivideUnitSphere(std::vector<Vector3f> &vertices, std::vector<unsigned> &indices, SphereVertexMap &vertexMap);
47 
49  void _3es_coreAPI sphereSubdivision(std::vector<Vector3f> &vertices, std::vector<unsigned> &indices, float radius = 1.0f, const Vector3f &origin = Vector3f(0.0f), int depth = 2);
50 };
51 
52 #endif // _3ESSPHERETESSELLATOR_H_
void _3es_coreAPI sphereSubdivision(std::vector< Vector3f > &vertices, std::vector< unsigned > &indices, float radius=1.0f, const Vector3f &origin=Vector3f(0.0f), int depth=2)
Tessellate a sphere using a subdivision technique starting from an icosahedron.
Definition: 3esbounds.h:13
Vector3< float > Vector3f
Defines a single precision vector.
Definition: 3esvector3.h:14
void _3es_coreAPI subdivideUnitSphere(std::vector< Vector3f > &vertices, std::vector< unsigned > &indices, SphereVertexMap &vertexMap)
Subdivide a unit sphere.
Represents a vector in R3.
Definition: 3esvector3.h:14
uint32_t hash(float x, float y, float z)
Generate a hash code for a 3-component vertex.
Definition: 3esvectorhash.h:94
void _3es_coreAPI sphereInitialise(std::vector< Vector3f > &vertices, std::vector< unsigned > &indices, SphereVertexMap *vertexMap=nullptr)
Initialise a unity sphere as an icosahedron.
T x
Direct data member access.
Definition: 3esvector3.h:30
Definition: 3esspheretessellator.h:17