-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathMyMesh.h
225 lines (218 loc) · 7.7 KB
/
MyMesh.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
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/*----------------------------------------------
Programmer: Alberto Bobadilla (labigm@rit.edu)
Date: 2021/05
----------------------------------------------*/
#ifndef __MYMESH_H_
#define __MYMESH_H_
#include "BTX\BTX.h"
namespace BTX
{
class MyMesh
{
bool m_bBinded = false; //Binded flag
uint m_uVertexCount = 0; //Number of vertices in this MyMesh
GLuint m_VAO = 0; //OpenGL Vertex Array Object
GLuint m_VBO = 0; //OpenGL Vertex Array Object
std::vector<vector3> m_lVertex; //Composed vertex array
std::vector<vector3> m_lVertexPos; //List of Vertices
std::vector<vector3> m_lVertexCol; //List of Colors
ShaderManager* m_pShaderMngr = nullptr; //Shader Manager
public:
/*
USAGE: Initialize the object's fields
ARGUMENTS: ---
OUTPUT: ---
*/
void Init(void);
/*
USAGE: Releases the object from memory
ARGUMENTS: ---
OUTPUT: ---
*/
void Release(void);
/*
USAGE: Constructor
ARGUMENTS: ---
OUTPUT: class object
*/
MyMesh();
/*
USAGE: Destructor
ARGUMENTS: ---
OUTPUT: ---
*/
~MyMesh();
/*
USAGE: Copy Constructor -> MyMesh does not allow to copy
from other MyMesh objects, create an empty MyMesh
and use the Instantiate method instead
ARGUMENTS: class object (to copy)
OUTPUT: class object
*/
MyMesh(MyMesh& other);
/*
USAGE: Copy Assignment Operator -> MyMesh does not allow to copy
from other SimpleMesh objects, use the Instantiate method instead.
ARGUMENTS: class object (to copy)
OUTPUT: class object
*/
MyMesh& operator=(MyMesh& other);
/*
USAGE: Swaps the contents of the object with another object's content
ARGUMENTS: class object (to swap with)
OUTPUT: ---
*/
void Swap(MyMesh& other);
/*
USAGE: Completes the information missing to create the mesh.
This method iterates through the mesh's vertex information and pairs each position with
a color to "complete" the mesh for rendering. As of right now the method completes the mesh with only colors but
it is possible to add other attribute information such as normals, binormals, etc.
ARGUMENTS: - vector3 a_v3Color -> vector input -> vector3(r-value, g-value, b-value)
This argument will be what the color of the mesh is in the form of a vector3 with 1.0 representing 100% in
an rgb value. For example vector3(1.0f, 0.0f, 0.0f) is red and vector3(0.0f, 0.0f, 1.0f) is blue.
OUTPUT: ---
*/
void CompleteMesh(vector3 a_v3Color = vector3(1.0f, 0.0f, 0.0f));
/*
USAGE: Adds a new point to the vector of vertices
These vertices will be displayed at the position in 3D-space entered once the mesh is rendered.
ARGUMENTS:
- vector3 a_v3Input -> vector input -> vector3(x-value, y-value, z-value)
This argument will be what the position of the vertex is in the form of a vector3 with 1.0 representing 1 unit in
an x, y, or z value. vector3(0.0f) will represent the origin of the mesh, not the origin in global space. This would make
a vertex including a vector3(0.0f, 1.0f, 0.0f) have a position 1 unit in the y-direction relative to the origin of the mesh
OUTPUT: ---
*/
void AddVertexPosition(vector3 a_v3Input);
/*
USAGE: Adds a new color to the vector of vertices
These vertices will be paired with positional vertices to add color to the mesh.
ARGUMENTS:
- vector3 a_v3Input -> vector input -> vector3(r-value, g-value, b-value)
This argument will be what the color of the vertex is in the form of a vector3 with 1.0 representing 100% in
an rgb value. For example vector3(1.0f, 0.0f, 0.0f) is red and vector3(0.0f, 0.0f, 1.0f) is blue.
OUTPUT: ---
*/
void AddVertexColor(vector3 a_v3Input);
/*
USAGE: Compiles the MyMesh for OpenGL 3.X use
This method prepares the mesh to be rendered by generating and binding the VAO & VBO,
opening up enough space for the VBO to use certain attributes,
and then binding those attributes. The VAO will be unbinded at the end so it does not
interfere with generation of other meshes.
ARGUMENTS: ---
OUTPUT: ---
*/
void CompileOpenGL3X(void);
/*
USAGE: Renders the mesh on the specified position by the
provided camera view and projection.
ARGUMENTS:
- matrix4 a_mProjection -> Projection matrix
- matrix4 a_mView -> View matrix
- matrix4 a_mModel -> matrix of the model in the world
The model matrix will include information for different transformations applied
to the mesh once it is in the world such as translation, rotation, and scale. This is the difference
between positions in the mesh with vertices entered in the mesh being relative to the mesh's origin
and the transformatons applied in the model matrix being in global space.
OUTPUT: ---
*/
void Render(matrix4 a_mProjection, matrix4 a_mView, matrix4 a_mModel);
/*
USAGE: Adds a tri to the list points in the buffer to be compiled
//C
//| \
//A--B
//This will make the triangle A->B->C
ARGUMENTS:
- vector3 a_vBottomLeft (A)
- vector3 a_vBottomRight (B)
- vector3 a_vTopLeft (C)
OUTPUT: ---
*/
void AddTri(vector3 a_vBottomLeft, vector3 a_vBottomRight, vector3 a_vTopLeft);
/*
USAGE: Adds a quad to the list points in the buffer to be compiled
//C--D
//| |
//A--B
//Will make the triangle A->B->C and then the triangle C->B->D
ARGUMENTS:
- vector3 a_vBottomLeft (A)
- vector3 a_vBottomRight (B)
- vector3 a_vTopLeft (C)
- vector3 a_vTopRight (D)
OUTPUT: ---
*/
void AddQuad(vector3 a_vBottomLeft, vector3 a_vBottomRight, vector3 a_vTopLeft, vector3 a_vTopRight);
/*
USAGE: Generates a cube
ARGUMENTS:
- float a_fSize -> Size of each side
- vector3 a_v3Color -> Color of the mesh
OUTPUT: ---
*/
void GenerateCube(float a_fSize, vector3 a_v3Color = C_WHITE);
/*
USAGE: Generates a cuboid
ARGUMENTS:
- vector3 a_v3Dimensions -> Dimensions of each side of the cuboid
- vector3 a_v3Color -> Color of the mesh
OUTPUT: ---
*/
void GenerateCuboid(vector3 a_v3Dimensions, vector3 a_v3Color = C_WHITE);
/*
USAGE: Generates a cone mesh
ARGUMENTS:
- float a_fRadius -> radius
- float a_fHeight -> how tall is the mesh
- int a_nSubdivisions -> divisions of the cap
- vector3 a_v3Color -> Color of the mesh
OUTPUT: ---
*/
void GenerateCone(float a_fRadius, float a_fHeight, int a_nSubdivisions, vector3 a_v3Color = C_WHITE);
/*
USAGE: Generates a cylinder mesh
ARGUMENTS:
- float a_fRadius -> radius
- float a_fHeight -> how tall is the mesh
- int a_nSubdivisions -> divisions on the cap
- vector3 a_v3Color -> Color of the mesh
OUTPUT: ---
*/
void GenerateCylinder(float a_fRadius, float a_fHeight, int a_nSubdivisions, vector3 a_v3Color = C_WHITE);
/*
USAGE: Generates a tube mesh
ARGUMENTS:
- float a_fOuterRadius -> outer radius
- float a_fInnerRadius -> inner radius
- float a_fHeight -> how tall is the mesh
- int a_nSubdivisions -> divisions on the cap
- a_v3Color -> Color of the mesh
OUTPUT: ---
*/
void GenerateTube(float a_fOuterRadius, float a_fInnerRadius, float a_fHeight, int a_nSubdivisions, vector3 a_v3Color = C_WHITE);
/*
USAGE: Generates a torus mesh
ARGUMENTS:
- float a_fOuterRadius -> Outer radius
- float a_fInnerRadius -> Inner Radius
- int a_nSubdivisionHeight -> divisions vertical
- int a_nSubdivisionAxis -> divisions along the roundness of the mesh
- a_v3Color -> Color of the mesh
OUTPUT: ---
*/
void GenerateTorus(float a_fOuterRadius, float a_fInnerRadius, int a_nSubdivisionHeight, int a_nSubdivisionAxis, vector3 a_v3Color = C_WHITE);
/*
USAGE: Generates a Sphere mesh
ARGUMENTS:
- float a_fRadius -> radius of the sphere
- int a_nSubdivisions -> Number of divisions, not a lot of difference in shapes larger than 3 subd
- a_v3Color -> Color of the mesh
OUTPUT: ---
*/
void GenerateSphere(float a_fRadius, int a_nSubdivisions, vector3 a_v3Color = C_WHITE);
};
}
#endif //__MYMESH_H_