-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_constructor.cpp
More file actions
151 lines (102 loc) · 2.97 KB
/
Copy pathbasic_constructor.cpp
File metadata and controls
151 lines (102 loc) · 2.97 KB
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
#include "basic_constructor.h"
#include <windows.h>
#include <GL/gl.h>
#include <math.h>
// Object implementation
Object::Object()
{
name = "made";
}
void Object::draw(std::vector<float> &verts, RECT &rect)
{
}
std::string Object::getName()
{
return name;
}
Circle::Circle()
{
}
void Circle::draw(std::vector<float> &verts, RECT &rect)
{
float screenWidth = float(rect.right-rect.left);
float screenHeight = float(rect.bottom-rect.top);
float pxWidth = 100.0f;
float ndcSize = pxWidth / (screenWidth / 2.0f); // size in NDC
// Convert pixel position to NDC
float centerX = (2.0f * posX / screenWidth) - 1.0f;
float centerY = 1.0f - (2.0f * posY / screenHeight);
// Now create triangle vertices relative to center
float x1 = centerX - ndcSize / 2.0f;
float y1 = centerY + ndcSize / 2.0f;
float x2 = centerX + ndcSize / 2.0f;
float y2 = centerY + ndcSize / 2.0f;
float x3 = centerX + ndcSize / 2.0f;
float y3 = centerY - ndcSize / 2.0f;
std::vector<float> toadd = {
};
float degree = 2.0f;
float increment = degree * 3.14159/180;
float rad = degree * 3.14159/180;
for (int i = 0; i < 360/degree; i++)
{
toadd.push_back(0.0f);
toadd.push_back(0.0f);
toadd.push_back(0.0f);
if(i > 0)
{
toadd.push_back(cos(rad+(increment * (i-1))) * 0.1f );
toadd.push_back(sin(rad+(increment * (i-1))) * 0.1f );
toadd.push_back(0.0f);
}
else
{
toadd.push_back(0.1f);
toadd.push_back(0.0f);
toadd.push_back(0.0f);
}
toadd.push_back(cos(rad + (increment * i))*0.1f);
toadd.push_back(sin(rad + (increment * i))*0.1f);
toadd.push_back(0.0f);
}
for (float f : toadd)
{
verts.push_back(f);
}
}
// Box implementation
Box::Box()
{
// Optionally do something with x
}
void Box::draw(std::vector<float> &verts, RECT &rect)
{
float screenWidth = float(rect.right-rect.left);
float screenHeight = float(rect.bottom-rect.top);
float pxWidth = 100.0f;
float ndcSize = pxWidth / (screenWidth / 2.0f); // size in NDC
// Convert pixel position to NDC
float centerX = (2.0f * posX / screenWidth) - 1.0f;
float centerY = 1.0f - (2.0f * posY / screenHeight);
// Now create triangle vertices relative to center
float x1 = centerX - ndcSize / 2.0f;
float y1 = centerY + ndcSize / 2.0f;
float x2 = centerX + ndcSize / 2.0f;
float y2 = centerY + ndcSize / 2.0f;
float x3 = centerX + ndcSize / 2.0f;
float y3 = centerY - ndcSize / 2.0f;
float x4 = centerX - ndcSize / 2.0f;
float y4 = centerY - ndcSize / 2.0f;
float toadd[] = {
x1, y1, 0.0f,
x2, y2, 0.0f,
x3, y3, 0.0f,
x1, y1, 0.0f,
x4, y4, 0.0f,
x3, y3, 0.0f
};
for (float f : toadd)
{
verts.push_back(f);
}
}