-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mesh.h
110 lines (93 loc) · 3.27 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
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
// --------------------------------------------------------------------------
// Copyright(C) 2009-2015
// Tamy Boubekeur
//
// All rights reserved.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program 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 General Public License (http://www.gnu.org/licenses/gpl.txt)
// for more details.
// --------------------------------------------------------------------------
#pragma once
#include "Vec4.h"
/// A simple vertex class storing position and normal
class Vertex {
public:
inline Vertex () {}
inline Vertex (const Vec4f & p, const Vec4f & n) : p (p), n (n) {}
inline virtual ~Vertex () {}
Vec4f p;
Vec4f n;
Vec4f vt;
};
/// A Triangle class expressed as a triplet of indices (over an external vertex list)
class Triangle {
public:
inline Triangle () {
ve[0] = ve[1] = ve[2] = 0;
}
inline Triangle (const Triangle & t) {
ve[0] = t.ve[0];
ve[1] = t.ve[1];
ve[2] = t.ve[2];
}
inline Triangle (unsigned int v0, unsigned int v1, unsigned int v2) {
ve[0] = v0;
ve[1] = v1;
ve[2] = v2;
}
inline virtual ~Triangle () {}
inline Triangle & operator= (const Triangle & t) {
ve[0] = t.ve[0];
ve[1] = t.ve[1];
ve[2] = t.ve[2];
return (*this);
}
unsigned int ve[3];
};
class Square {
public:
inline Square () {
v[0] = v[1] = v[2] = v[3]= 0;
}
inline Square (const Square & s) {
v[0] = s.v[0];
v[1] = s.v[1];
v[2] = s.v[2];
v[3] = s.v[3];
}
inline Square (unsigned int v0, unsigned int v1, unsigned int v2, unsigned int v3) {
v[0] = v0;
v[1] = v1;
v[2] = v2;
v[3] = v3;
}
inline virtual ~Square () {}
inline Square & operator= (const Square & s) {
v[0] = s.v[0];
v[1] = s.v[1];
v[2] = s.v[2];
v[3] = s.v[3];
return (*this);
}
unsigned int v[4];
};
/// A Mesh class, storing a list of vertices and a list of triangles indexed over it.
class Mesh {
public:
std::vector<Vertex> V;
std::vector<Triangle> T;
std::vector<Square> S;
/// Compute smooth per-vertex normals
void recomputeNormals ();
/// scale to the unit cube and center at original
void centerAndScaleToUnit ();
void deplacer(Vec4f pocition1, Vec4f position2);
};