-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cube.cpp
115 lines (95 loc) · 2.51 KB
/
Cube.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//
// Created by wasya on 16.03.2019.
//
#include <GL/gl.h>
#include "Cube.hpp"
void Cube::draw() {
GLfloat left = this->x - EDGE_LENGTH / 2;
GLfloat right = left + EDGE_LENGTH;
GLfloat bottom = this->y - EDGE_LENGTH / 2;
GLfloat top = bottom + EDGE_LENGTH;
GLfloat back = this->z - EDGE_LENGTH / 2;
GLfloat front = back + EDGE_LENGTH;
GLfloat vertices[] = {
//face
left, top, front,
right, top, front,
right, bottom ,front,
left, bottom, front,
// back
left, top, back,
right, top, back,
right, bottom, back,
left, bottom, back,
//left
left, top, front,
left, top, back,
left, bottom, back,
left, bottom, front,
//right
right, top, front,
right, top, back,
right, bottom, back,
right, bottom, front,
//top
left, top, front,
left, top, back,
right, top, back,
right, top, front,
//bottom
left, bottom, front,
left, bottom, back,
right, bottom, back,
right, bottom, front,
};
GLfloat color[] = {
//red
1, 0, 0,
1, 0, 0,
1, 0 ,0,
1, 0, 0,
//green
0.5, 0.5, 0.5,
0.5, 0.5, 0.5,
0.5, 0.5, 0.5,
0.5, 0.5, 0.5,
//blue
0, 0, 1,
0, 0, 1,
0, 0 ,1,
0, 0, 1,
//yellow
1, 1, 0,
1, 1, 0,
1, 1 ,0,
1, 1, 0,
//pink
1, 0, 1,
1, 0, 1,
1, 0 ,1,
1, 0, 1,
//blue!
0, 1, 1,
0, 1, 1,
0, 1 ,1,
0, 1, 1,
};
glPolygonMode(GL_FRONT_AND_BACK,mode);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertices);
glDrawArrays(GL_QUADS, 0, 24);
glColorPointer(3, GL_FLOAT, 0, color);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
}
Cube::Cube(GLfloat x, GLfloat y, GLfloat z, int len, GLenum mode) {
this->y = y;
this->z = z;
this->x = x;
this->EDGE_LENGTH = len;
this->mode = mode;
}
void Cube::setMode(GLenum Mode) {
mode = Mode;
}