-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathexample.py
More file actions
54 lines (39 loc) · 1.58 KB
/
example.py
File metadata and controls
54 lines (39 loc) · 1.58 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
import pygame
import pygame3D
# initialize pygame3D scene and models
pygame.init()
scene = pygame3D.Scene(700, 700, gravity=True, title="Pygame3D Example") # new scene
# 3D models
model_location = "example_3D_models/"
cube_model = pygame3D.read_model(model_location + "cube_model.txt")
plane_model = pygame3D.read_model(model_location + "plane_model.txt")
pyramid_model = pygame3D.read_model(model_location + "big_pyramid.txt")
floor_model = pygame3D.read_model(model_location + "floor.txt")
# change the colours of multiple objects in one line
pyramid_model, cube_model, plane_model = map(lambda x: x.set_colour("white"), [pyramid_model, cube_model, plane_model])
floor_model.set_colour("blue")
# add models to scene
scene.add_shape(floor_model)
scene.add_shape(pyramid_model, pygame3D.Vec3([100,0,1000]))
scene.add_shape(cube_model, pygame3D.Vec3([-300, 0, 1000]))
scene.add_shape(cube_model, pygame3D.Vec3([-100, 0, 1000]))
scene.add_shape(plane_model, pygame3D.Vec3([-300, 0, 1000]))
delay_time = 10
v_rot = 0.002 * delay_time # radians per delay tick
v_mov = 0.3 * delay_time # units of movement per delay tick
running = True
while running:
# small delay between step events. 10 steps per second
pygame.time.delay(delay_time)
""" process user input """
# check all events
for event in pygame.event.get():
# user quit the program
if event.type == pygame.QUIT:
running = False
""" key presses """
keys = pygame.key.get_pressed()
scene.camera.move(keys, v_mov, v_rot)
""" draw current scene """
scene.refresh()
pygame.quit()