forked from tharvik/COG
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMesh.h
More file actions
146 lines (129 loc) · 3.97 KB
/
Copy pathMesh.h
File metadata and controls
146 lines (129 loc) · 3.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#pragma once
#include "opengl.h"
#include <array>
#include <string>
#include <vector>
#include <fstream>
#include "config.h"
#include "Vvector.h"
/**
* A mesh referes to a set of faces, UV vertices and normals to draw. A mesh
* uses the power of the openGL VBO indexing. It means that all vertices,
* UV vertices and normals are stored in openGL buffers and an index "links"
* them to makes faces.
*
* A mesh have a multi-resolution system. A mesh far from a camera will have
* a lower quality than a mesh near the camera (less faces will be drawn).
* The resolution is called "level":
* - level 1 : best quality
* - level 2 : good quality
* - level 3 : medium quality
* - level 4 : bad quality
* - level 5 : worst quality
*
* To assure this multi-resolution system, the notion of mesh radius have to
* be instored. It's precisly the distance between the center of the mesh and
* the farest point. It assures the same treatment to a sphere and a cuboid.
*
* The distances for the mesh levels can be setted by changing in the config
* file the values of MESH_LEVEL_DISTANCES.
*
*/
class Mesh {
private:
/**
* mesh radius
*/
float radius;
/**
* number of indices to draw for each mesh levels
*/
std::array<unsigned int, 5> sizeIndices;
/**
* buffers used by OpenGL
*
* buffers[x][0] contains the vertices of the level x
* buffers[x][1] contains the UV vertices of the level x
* buffers[x][2] contains the normals of the level x
* buffers[x][3] contains the indices of the level x
*/
std::array<std::array<GLuint,4>,5> buffers;
/**
* fill a buffer of elements T with the next block of a stream
*
* \param buffer openGL reference of a writeable buffer of elements T
* \param file the stream containing the block
*
* \return the size (number of elements) of the block
*/
template<typename T>
static unsigned int fillBuffer(GLuint buffer, std::ifstream& file);
public:
/**
* default constructor
*/
Mesh();
/**
* Deleted copy constructor
*/
Mesh(const Mesh&) = delete;
/**
* move constructor. Leave m in a valid but useless state
*
* \param m mesh to move, which will be left in the default
* state
*
* \attention the function has never been tested
*/
Mesh(Mesh&& m);
/**
* constructor
*
* load a .mesh file
*
* \param filePath path to the .mesh file
*/
Mesh(const std::string& filePath);
/**
* construct with the given vertices, UV vertices and indices for each
* mesh level
*
* \param v vertices
* \param vt vertices on the texture
* \param indices indices to write
* \param rad radius of the mesh
*
* \attention the function has never been tested
*/
Mesh(const std::array<std::vector<std::array<float, 3>>, 5>& v,
const std::array<std::vector<std::array<float, 2>>, 5>& vt,
const std::array<std::vector<unsigned int>, 5>& indices,
const float rad);
/**
* draw the faces (send faces to openGL)
*
* \param level specifie the mesh level to draw
*/
void draw(const uint8_t level) const;
/**
* implement the less operator based on the values of the
* buffers
*
* \param m other mesh to compare to
*
* \return return true if \f$ \sum_{i=0}^{4} buffers_i.size() < \sum_{i=0}^{4} b.buffers_i.size()\f$
*/
bool operator<(const Mesh &m) const;
/**
* get the mesh radius
*
* \return mesh radius
*/
float getRadius();
/**
* delete the allocated buffers
*
* \attention the function has never been tested
*/
~Mesh();
};