-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphics.py
189 lines (148 loc) · 3.64 KB
/
graphics.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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import OpenGL
from OpenGL.GL import *
from OpenGL.GLU import *
import math
from math_utils import *
from vector3 import *
from ui import *
def drawOrigin():
glBegin(GL_LINES)
glColor(1,0,0)
glVertex3f(0,0,0)
glVertex3f(1000, 0, 0)
glEnd()
glBegin(GL_LINES)
glColor(0,1,0)
glVertex3f(0,0,0)
glVertex3f(0, 1000, 0)
glEnd()
glBegin(GL_LINES)
glColor(0,0,1)
glVertex3f(0,0,0)
glVertex3f(0, 0, 1000)
glEnd()
def drawTerrain(t):
glColor(0, 0.8, 0)
glBegin(GL_POINTS)
for vector in t.data:
glVertex3f(vector.x, vector.y, vector.z)
glEnd()
def drawShells(shells):
glLineWidth(3)
for s in shells:
if s.flight_time > 0.04:
glColor(1, 1, 0)
glBegin(GL_LINES)
glVertex3f(s.pos.x, s.pos.y, s.pos.z)
glVertex3f(s.pos.x - s.vel.x * 0.05, s.pos.y - s.vel.y * 0.05, s.pos.z - s.vel.z * 0.05)
glEnd()
glBegin(GL_POINTS)
glVertex3f(s.pos.x, s.pos.y, s.pos.z)
glEnd()
glLineWidth(1)
def drawPanzer(p):
glColor(p.color[0], p.color[1], p.color[2])
sx = p.size.x
sy = p.size.y
sz = p.size.z
# get into panzer matrix
glPushMatrix()
glTranslate(p.pos.x, p.pos.y, p.pos.z)
glRotate(p.rot, 0, 1, 0)
glRotate(p.hull_angle, -1, 0, 0)
glBegin(GL_LINES)
glVertex3f(0, 0, sz)
glVertex3f(0, 0, -sz)
glEnd()
glBegin(GL_LINES)
glVertex3f(sx, 0, sz)
glVertex3f(sx, 0, -sz)
glEnd()
glBegin(GL_LINES)
glVertex3f(-sx, 0, sz)
glVertex3f(-sx, 0, -sz)
glEnd()
glBegin(GL_LINES)
glVertex3f(-sx, 0, sz)
glVertex3f(sx, 0, sz)
glEnd()
glBegin(GL_LINES)
glVertex3f(-sx, 0, -sz)
glVertex3f(sx, 0, -sz)
glEnd()
## up 1
glBegin(GL_LINES)
glVertex3f(0, sy, sz)
glVertex3f(0, sy, -sz)
glEnd()
glBegin(GL_LINES)
glVertex3f(sx, sy, sz)
glVertex3f(sx, sy, -sz)
glEnd()
glBegin(GL_LINES)
glVertex3f(-sx, sy, sz)
glVertex3f(-sx, sy, -sz)
glEnd()
glBegin(GL_LINES)
glVertex3f(-sx, sy, sz)
glVertex3f(sx, sy, sz)
glEnd()
glBegin(GL_LINES)
glVertex3f(-sx, sy, -sz)
glVertex3f(sx, sy, -sz)
glEnd()
# turret
local_x, local_y, local_z = p.local_x, p.local_y, p.local_z
turret_x, turret_z = p.turret_x, p.turret_z
gun_z = p.gun_z
# get into turret matrix
glPushMatrix()
glTranslate(0, sy, 0)
glRotate(p.turret_rot, 0, 1, 0)
glBegin(GL_LINES)
glVertex3f(0, 0, 0)
glVertex3f(0, 0, sz * 0.5)
glEnd()
glBegin(GL_LINES)
glVertex3f(0, 0, sz * 0.5)
glVertex3f(0.35 * sx, 0, -sz * 0.35)
glEnd()
glBegin(GL_LINES)
glVertex3f(0, 0, sz * 0.5)
glVertex3f(-0.35 * sx, 0, -sz * 0.35)
glEnd()
glBegin(GL_LINES)
glVertex3f(-0.35 * sx, 0, -sz * 0.35)
glVertex3f(0.35 * sx, 0, -sz * 0.35)
glEnd()
glBegin(GL_LINES)
glVertex3f(0, sy * 0.3, 0)
glVertex3f(0, 0, sz * 0.5)
glEnd()
glBegin(GL_LINES)
glVertex3f(0, sy * 0.3, 0)
glVertex3f(0.35 * sx, 0, -sz * 0.35)
glEnd()
glBegin(GL_LINES)
glVertex3f(0, sy * 0.3, 0)
glVertex3f(-0.35 * sx, 0, -sz * 0.35)
glEnd()
# get into gun matrix
glPushMatrix()
glRotate(p.gun_rot, -1, 0, 0)
glBegin(GL_LINES)
glVertex3f(0, 0, 0)
glVertex3f(0, 0, sz * 0.8)
glEnd()
# get out of gun matrix
glPopMatrix()
# get out of turret matrix
glPopMatrix()
# get out of panzer matrix
glPopMatrix()
def drawScene(ground, cam, p1, p2, shells):
#drawOrigin()
drawTerrain(ground)
drawPanzer(p1)
drawPanzer(p2)
drawShells(shells)