-
Notifications
You must be signed in to change notification settings - Fork 0
/
Block.py
54 lines (43 loc) · 1.54 KB
/
Block.py
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
import math
from OpenGL.GL import *
class Block:
def __init__(self, pos_bottom, pos_top, sided_flag, color):
self.long_flag = sided_flag
self.pos_a = pos_bottom
self.pos_b = pos_top
self.vertices = []
self.edges = []
self.sides = []
self.color = color
self.size_z = math.fabs(pos_bottom[2][2] - pos_bottom[0][2])
self.size_x = math.fabs(pos_bottom[0][0] - pos_bottom[1][0])
self.size_y = math.fabs(pos_bottom[0][1] - pos_top[0][1])
def build(self):
for v in self.pos_a:
self.vertices.append(v)
for v in self.pos_b:
self.vertices.append(v)
for i in range(0, 4):
self.edges.append([i, (i + 1) % 4])
for i in range(0, 4):
self.edges.append([i + 4, (i + 1) % 4 + 4])
for i in range(0, 4):
self.edges.append([i, i + 4])
for i in range(0, 1):
self.sides.append([4 * i, 4 * i + 1, 4 * i + 2, 4 * i + 3])
for i in range(0, 4):
self.sides.append([i, (i + 1) % 4, (i + 1) % 4 + 4, i + 4])
def draw(self):
glBegin(GL_QUADS)
for side in self.sides:
for vertex in side:
glColor3f(self.color[0], self.color[1], self.color[2])
glVertex3fv(self.vertices[vertex])
glEnd()
glLineWidth(4)
glBegin(GL_LINES)
for edge in self.edges:
for vertex in edge:
glColor3f(0, 0, 0)
glVertex3fv(self.vertices[vertex])
glEnd()