-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4-1.py
More file actions
104 lines (85 loc) · 1.92 KB
/
4-1.py
File metadata and controls
104 lines (85 loc) · 1.92 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
import glfw
from OpenGL.GL import *
import numpy as np
from OpenGL.GLU import *
def render():
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glEnable(GL_DEPTH_TEST)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glOrtho(-2,2, -2,2, -1,1)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
drawFrame()
t=glfw.get_time()
#blue base transformation
glPushMatrix()
glTranslatef(np.sin(t), 0, 0)
#blue base drawing
glPushMatrix()
drawFrame()
glScalef(.2,.2,.2)
glColor3ub(0, 0, 225)
drawBox()
glPopMatrix()
#red arm transformation
glPushMatrix()
glRotatef(t*(180/np.pi),0,0,1)
glTranslatef(.5,0,.01)
#red arm drawing
glPushMatrix()
drawFrame()
glScalef(.5,.1,.1)
glColor3ub(255,0,0)
drawBox()
glPopMatrix()
#green base transformation
glPushMatrix()
glTranslatef(.5,0,.01)
glRotatef(t*(180/np.pi),0,0,1)
#green box drawing
glPushMatrix()
drawFrame()
glScalef(.2,.2,.2)
glColor3ub(0,255,0)
drawBox()
glPopMatrix()
glPopMatrix()
glPopMatrix()
glPopMatrix()
def drawBox():
glBegin(GL_QUADS)
glVertex3fv(np.array([1,1,0.]))
glVertex3fv(np.array([-1,1,0.]))
glVertex3fv(np.array([-1,-1,0.]))
glVertex3fv(np.array([1,-1,0.]))
glEnd()
def drawFrame():
#draw coordinate: x in red, y in green, Z in blue
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 main():
if not glfw.init():
return
window=glfw.create_window(480,480,"2021005923-assignment4-1", 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()