-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrimitives.cpp
93 lines (81 loc) · 2.12 KB
/
Primitives.cpp
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
#include "Primitives.h"
Primitives::Primitives() {
this->circleMesh = this->CreateCircleMesh();
this->rectangleMesh = this->CreateRectangleMesh();
}
Mesh* Primitives::CreateCircleMesh() {
const int step = 10;
std::vector<Vertex> circle_vertices = {
Vertex {
glm::vec3( 0.0f, 0.0f, 0.0f ),
glm::vec3( 1.0f, 0.0f, 0.0f ),
glm::vec3( 1.0f, 1.0f, 1.0f ),
glm::vec2( 0.0f, 0.0f )
}
};
for( int i = 0; i < 360; i += step ) {
circle_vertices.push_back(
Vertex {
glm::vec3(
std::cos( i * glm::pi<float>() / 180 ),
std::sin( i * glm::pi<float>() / 180 ),
0.0f
),
glm::vec3( 0.0f, 0.0f, 1.0f ),
glm::vec3( 1.0f, 1.0f, 1.0f ),
glm::vec2( 0.0f, 0.0f )
}
);
}
std::vector<GLuint> indices;
for( int i = 1; i < circle_vertices.size() - 1; i ++ ) {
indices.push_back( i );
indices.push_back( i + 1 );
indices.push_back( 0 );
}
indices.push_back( circle_vertices.size() - 1 );
indices.push_back( 1 );
indices.push_back( 0 );
return new Mesh( circle_vertices, indices, tex );
}
Mesh* Primitives::CreateRectangleMesh() {
return new Mesh( plane_vertices, plane_indices, tex );
}
void Primitives::DrawCircle(
Shader& shader,
Camera& camera,
glm::mat4 matrix,
glm::vec3 translation,
glm::quat rotation,
glm::vec3 scale,
bool isWire
) const {
this->circleMesh->DrawInstance(
shader,
camera,
matrix,
translation,
rotation,
scale,
isWire
);
}
void Primitives::DrawRectangle (
Shader& shader,
Camera& camera,
glm::mat4 matrix,
glm::vec3 translation,
glm::quat rotation,
glm::vec3 scale,
bool isWire
) const {
this->rectangleMesh->DrawInstance(
shader,
camera,
matrix,
translation,
rotation,
scale,
isWire
);
}