-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSwiatlo.cpp
53 lines (45 loc) · 1.71 KB
/
Swiatlo.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
#include "Swiatlo.h"
Swiatlo::Swiatlo(float x, float y, float z) {
this->x = x;
this->y = y;
this->z = z;
sides = 50; // Domyœlna liczba boków kola
}
void Swiatlo::draw() {
glPushMatrix();
glTranslatef(x, y, z);
glRotatef(90.0f, 1.0f, 0.0f, 90.0f);
// Rysuj górn¹ powierzchniê kola
glColor3f(1.0f, 1.0f, 0.0f);
glBegin(GL_TRIANGLE_FAN);
glVertex3f(0.0f, height / 2.0f, 0.0f);
for (int i = 0; i <= sides; i++) {
float angle = 2.0f * 3.14 * (float)i / (float)sides;
glVertex3f(radius * cos(angle), height / 2.0f, radius * sin(angle));
}
glEnd();
// Rysuj doln¹ powierzchniê kola
glBegin(GL_TRIANGLE_FAN);
glVertex3f(0.0f, -height / 2.0f, 0.0f);
for (int i = 0; i <= sides; i++) {
float angle = 2.0f * 3.14 * (float)i / (float)sides;
glVertex3f(radius * cos(angle), -height / 2.0f, radius * sin(angle));
}
glEnd();
// Rysuj boki kola za pomoc¹ trójk¹tów
glBegin(GL_TRIANGLES);
for (int i = 0; i < sides; i++) {
float angle1 = 2.0f * 3.14 * (float)i / (float)sides;
float angle2 = 2.0f * 3.14 * (float)(i + 1) / (float)sides;
// Górna trójk¹tna œciana
glVertex3f(radius * cos(angle1), height / 2.0f, radius * sin(angle1));
glVertex3f(radius * cos(angle2), height / 2.0f, radius * sin(angle2));
glVertex3f(radius * cos(angle2), -height / 2.0f, radius * sin(angle2));
// Dolna trójk¹tna œciana
glVertex3f(radius * cos(angle2), -height / 2.0f, radius * sin(angle2));
glVertex3f(radius * cos(angle1), -height / 2.0f, radius * sin(angle1));
glVertex3f(radius * cos(angle1), height / 2.0f, radius * sin(angle1));
}
glEnd();
glPopMatrix();
}