-
Notifications
You must be signed in to change notification settings - Fork 33
/
EnvironmentCube.py
76 lines (59 loc) · 1.92 KB
/
EnvironmentCube.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
#!/usr/bin/python
from __future__ import absolute_import, division, print_function, unicode_literals
""" Different types of environment cube mapping. Change them by setting box to
values 0 to 3. in nobottom is set to True then that image can be absent, the
drawing will use the previous image which is top
"""
import demo
import pi3d
# Setup display and initialise pi3d
DISPLAY = pi3d.Display.create(x=50, y=50, frames_per_second=30)
shader = pi3d.Shader('uv_flat')
#========================================
#select the environment cube with 'box'...
box = 3
if box == 0:
ectex = [pi3d.Texture('textures/ecubes/skybox_interstellar.jpg')]
myecube = pi3d.EnvironmentCube(size=900.0, maptype='CROSS')
elif box == 1:
ectex = [pi3d.Texture('textures/ecubes/SkyBox.jpg')]
myecube = pi3d.EnvironmentCube(size=900.0, maptype='HALFCROSS')
elif box == 2:
ectex = pi3d.loadECfiles('textures/ecubes','sbox_interstellar', nobottom=True)
myecube = pi3d.EnvironmentCube(size=900.0, maptype='FACES', nobottom=True)
else:
ectex = pi3d.loadECfiles('textures/ecubes','skybox_hall')
myecube = pi3d.EnvironmentCube(size=900.0, maptype='FACES')
myecube.set_draw_details(shader, ectex)
rot = 0.0
tilt = 0.0
# Fetch key presses
mykeys = pi3d.Keyboard()
mymouse = pi3d.Mouse(restrict=False)
mymouse.start()
omx, omy = mymouse.position()
CAMERA = pi3d.Camera.instance()
# Display scene and rotate cuboid
while DISPLAY.loop_running():
CAMERA.reset()
CAMERA.rotate(tilt, 0, 0)
CAMERA.rotate(0, rot, 0)
myecube.draw()
mx, my = mymouse.position()
#if mx>display.left and mx<display.right and my>display.top and my<display.bottom:
rot -= (mx - omx)*0.4
tilt += (my - omy)*0.4
omx = mx
omy = my
#Press ESCAPE to terminate
k = mykeys.read()
if k >-1:
if k==112: #key P
pi3d.screenshot('envcube.jpg')
elif k==27: #Escape key
mykeys.close()
mymouse.stop()
DISPLAY.stop()
break
else:
print(k)