-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeometryGenerator.cpp
More file actions
41 lines (29 loc) · 975 Bytes
/
Copy pathGeometryGenerator.cpp
File metadata and controls
41 lines (29 loc) · 975 Bytes
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
#include <glad/glad.h>
#include <vector>
#define PI 3.14159f
#include <cmath>
namespace GeometryGenerator{
std::vector<GLfloat> circleGeometry(int segments,float radius){
std::vector<GLfloat> vertices(segments * 3);
float tetha = 0;
int i = 3;
int segment = 1;
//GL_TRIANGLE_FAN requieres the initial vertex to be the center
vertices[0] = 0;
vertices[1] = 0;
vertices[2] = 0;
while(segment < segments - 1 ){
tetha = segment * 2.0f * PI / segments;
vertices[i] = std::sin(tetha) * radius;
vertices[i+1] = std::cos(tetha) * radius;
vertices[i+2] = 0;
i = i + 3;
segment++;
}
// Also the last vertex needs to connect with the first one
vertices[i] = vertices[3];
vertices[i+1] = vertices[4];
vertices[i+2] = 0.0f;
return vertices;
}
};