forked from pi3d/pi3d_demos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BuckfastAbbey.py
107 lines (89 loc) · 2.49 KB
/
BuckfastAbbey.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
#!/usr/bin/python
from __future__ import absolute_import, division, print_function, unicode_literals
""" 3D model loading: complex architectural model with multiple vertex groups
and images
"""
import math, random
import demo
import pi3d
# Setup display and initialise pi3d
DISPLAY = pi3d.Display.create(x=100, y=100, frames_per_second=30)
DISPLAY.set_background(1.0,0.4,0.6,1) # r,g,b,alpha
pi3d.Light((5, -10, -20), (0.6, 0.6, 0.5), (0.3, 0.3, 0.4))
# load shader
shader = pi3d.Shader("uv_light")
flatsh = pi3d.Shader("uv_flat")
print("==============================================================")
print("Instructions:")
print("")
print("Keys- W - Forward,")
print(" A - Left S - Back D - right")
print("")
print("Move mouse to pan view. Click mouse to exit or press ESCAPE")
print("==============================================================")
ectex = pi3d.loadECfiles("textures/ecubes","sbox")
myecube = pi3d.EnvironmentCube(size=900.0, maptype="FACES",
name="bfa", y=50.0)
myecube.set_draw_details(flatsh, ectex)
# load model_loadmodel
mymodel = pi3d.Model(
file_string="models/Buckfast Abbey/BuckfastAbbey.egg",
name="Abbey",
rx=90, sx=0.03, sy=0.03, sz=0.03)
mymodel.set_shader(shader)
# Create keyboard and mouse event objects
mykeys = pi3d.Keyboard()
mymouse = pi3d.Mouse(restrict = False)
mymouse.start()
#screenshot number
scshots = 1
#avatar camera
rot = 220.0
tilt = 10.0
avhgt = 2.0
xm = 0.0
zm = 0.0
ym = avhgt
omx, omy = mymouse.position()
CAMERA = pi3d.Camera.instance()
while DISPLAY.loop_running():
CAMERA.reset()
CAMERA.rotate(tilt, 0, 0)
CAMERA.rotate(0, rot, 0)
CAMERA.position((xm, ym, zm))
mymodel.draw()
myecube.draw()
mx, my = mymouse.position()
rot -= (mx-omx)*0.8
tilt += (my-omy)*0.8
omx=mx
omy=my
#Press ESCAPE to terminate
k = mykeys.read()
if k > -1:
if k == 119: #key W
xm -= math.sin(math.radians(rot))
zm += math.cos(math.radians(rot))
elif k == 115: #kry S
xm += math.sin(math.radians(rot))
zm -= math.cos(math.radians(rot))
elif k == 39: #key '
tilt -= 2.0
print(tilt)
elif k == 47: #key /
tilt += 2.0
elif k == 97: #key A
rot -= 2
elif k == 100: #key D
rot += 2
elif k == 112: #key P
pi3d.screenshot("BuckfastAbbey"+str(scshots)+".jpg")
scshots += 1
elif k == 27: #Escape key
mykeys.close()
mymouse.stop()
DISPLAY.destroy()
break
else:
print(k)
quit()