-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3-2.py
More file actions
100 lines (82 loc) · 2.1 KB
/
3-2.py
File metadata and controls
100 lines (82 loc) · 2.1 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
import glfw
from OpenGL.GL import *
from OpenGL.GLU import *
import numpy as np
def render():
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glEnable(GL_DEPTH_TEST)
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE )
glLoadIdentity()
glOrtho(-5,5, -5,5, -8,8)
# Replace this call with two glRotatef() calls and one glTranslatef() call
#gluLookAt(3,3,3, 0,0,0, 0,1,0)
glRotatef(36.264, 1, 0, 0)
glRotatef(-45, 0, 1, 0)
glTranslatef(-3, -3, -3)
drawFrame()
glColor3ub(255, 255, 255)
drawCubeArray()
def drawFrame():
glBegin(GL_LINES)
glColor3ub(255, 0, 0)
glVertex3fv(np.array([0.,0.,0.]))
glVertex3fv(np.array([1.,0.,0.]))
glColor3ub(0, 255, 0)
glVertex3fv(np.array([0.,0.,0.]))
glVertex3fv(np.array([0.,1.,0.]))
glColor3ub(0, 0, 255)
glVertex3fv(np.array([0.,0.,0.]))
glVertex3fv(np.array([0.,0.,1.]))
glEnd()
def drawCube():
glBegin(GL_QUADS)
glVertex3f(0.5, 0.5, -0.5)
glVertex3f(-0.5, 0.5, -0.5)
glVertex3f(-0.5, 0.5, 0.5)
glVertex3f(0.5, 0.5, 0.5)
glVertex3f(0.5, -0.5, 0.5)
glVertex3f(-0.5, -0.5, 0.5)
glVertex3f(-0.5, -0.5, -0.5)
glVertex3f(0.5, -0.5, -0.5)
glVertex3f(0.5, 0.5, 0.5)
glVertex3f(-0.5, 0.5, 0.5)
glVertex3f(-0.5, -0.5, 0.5)
glVertex3f(0.5, -0.5, 0.5)
glVertex3f(0.5, -0.5, -0.5)
glVertex3f(-0.5, -0.5, -0.5)
glVertex3f(-0.5, 0.5, -0.5)
glVertex3f(0.5, 0.5, -0.5)
glVertex3f(-0.5, 0.5, 0.5)
glVertex3f(-0.5, 0.5, -0.5)
glVertex3f(-0.5, -0.5, -0.5)
glVertex3f(-0.5, -0.5, 0.5)
glVertex3f(0.5, 0.5, -0.5)
glVertex3f(0.5, 0.5, 0.5)
glVertex3f(0.5, -0.5, 0.5)
glVertex3f(0.5, -0.5, -0.5)
glEnd()
def drawCubeArray():
for i in range(5):
for j in range(5):
for k in range(5):
glPushMatrix()
glTranslatef(i, j, -k-1)
glScalef(.5, .5, .5)
drawCube()
glPopMatrix()
def main():
if not glfw.init():
return
window=glfw.create_window(480,480,"2021005923-3-2", None, None)
if not window:
glfw.terminate()
return
glfw.make_context_current(window)
glfw.swap_interval(1)
while not glfw.window_should_close(window):
glfw.poll_events()
render()
glfw.swap_buffers(window)
glfw.terminate()
if __name__ == "__main__":
main()