-
Notifications
You must be signed in to change notification settings - Fork 3
/
mesh.h
65 lines (54 loc) · 1.02 KB
/
mesh.h
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
#ifndef MESH_H
#define MESH_H
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include "mathutil.h"
using std::vector;
using std::max;
struct Face;
struct Vertex
{
double v[3];
double n[3];
double t[2];
bool has_normal, has_texture;
size_t index;
vector<Face*> f;
};
struct Edge
{
Vertex* v[2];
Face* f[2];
size_t index;
};
struct Face
{
vector<Vertex*> v;
vector<Edge*> e;
size_t index;
};
class Mesh
{
public:
void add(Vertex* v);
void add(Edge* e);
void add(Face* f);
Vertex* get_vertex(int i);
Edge* get_edge(int i);
Face* get_face(int i);
size_t vertex_count() const;
size_t edge_count() const;
size_t face_count() const;
private:
vector<Vertex*> vertices;
vector<Edge*> edges;
vector<Face*> faces;
};
Edge* get_edge(Vertex* v0, Vertex* v1);
Edge* create_edge(Vertex* v0, Vertex* v1, Face* f, Mesh& mesh);
void normalize(Mesh& mesh);
void compute_normals(Mesh& mesh);
void center_on_screen(Mesh& mesh);
#endif