8000 add example core 3d camera first person · sDos280/raylib-python-cffi@36afd60 · GitHub
[go: up one dir, main page]

Skip to content

Commit 36afd60

Browse files
committed
add example core 3d camera first person
1 parent 9ad06e6 commit 36afd60

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
"""
2+
raylib [core] example - 3d camera first person
3+
adapted from https://github.com/raysan5/raylib/blob/master/examples/core/core_3d_camera_first_person.c
4+
"""
5+
6+
import pyray
7+
8+
MAX_COLUMNS = 20
9+
10+
SCREEN_WIDTH = 800
11+
SCREEN_HEIGHT = 450
12+
13+
pyray.init_window(SCREEN_WIDTH, SCREEN_HEIGHT, b"raylib [core] example - 3d camera first person")
14+
15+
# Define the camera to look into our 3d world (position, target, up vector)
16+
camera = pyray.Camera3D()
17+
camera.position = pyray.Vector3(4.0, 2.0, 4.0)
18+
camera.target = pyray.Vector3(0.0, 1.8, 0.0)
19+
camera.up = pyray.Vector3(0.0, 1.0, 0.0)
20+
camera.fovy = 60.0
21+
camera.projection = pyray.CAMERA_PERSPECTIVE
22+
23+
# Generates some random columns
24+
heights = [None] * MAX_COLUMNS
25+
positions = [None] * MAX_COLUMNS
26+
colors = [None] * MAX_COLUMNS
27+
28+
for i in range(MAX_COLUMNS):
29+
heights[i] = pyray.get_random_value(1, 12) * 1.0
30+
positions[i] = pyray.Vector3(pyray.get_random_value(-15, 15) * 1.0, heights[i]/2.0 * 1.0, pyray.get_random_value(-15, 15) * 1.0)
31+
colors[i] = pyray.Color(pyray.get_random_value(20, 255), pyray.get_random_value(10, 55), 30, 255)
32+
33+
34+
pyray.set_camera_mode(camera, pyray.CAMERA_FIRST_PERSON) # Set a first person camera mode
35+
36+
pyray.set_target_fps(60)
37+
38+
while not pyray.window_should_close():
39+
40+
pyray.update_camera(camera)
41+
42+
pyray.begin_drawing()
43+
44+
pyray.clear_background(pyray.RAYWHITE)
45+
46+
pyray.begin_mode_3d(camera)
47+
48+
pyray.draw_plane(pyray.Vector3(0.0, 0.0, 0.0), pyray.Vector2(32.0, 32.0), pyray.LIGHTGRAY)
49+
pyray.draw_cube(pyray.Vector3(-16.0, 2.5, 0.0), 1.0, 5.0, 32.0, pyray.BLUE)
50+
pyray.draw_cube(pyray.Vector3(16.0, 2.5, 0.0), 1.0, 5.0, 32.0, pyray.LIME)
51+
pyray.draw_cube(pyray.Vector3(0.0, 2.5, 16.0), 32.0, 5.0, 1.0, pyray.GOLD)
52+
53+
for i in range(MAX_COLUMNS):
54+
pyray.draw_cube(positions[i], 2.0, heights[i], 2.0, colors[i])
55+
pyray.draw_cube_wires(positions[i], 2.0, heights[i], 2.0, pyray.MAROON)
56+
57+
58+
pyray.end_mode_3d()
59+
60+
pyray.draw_rectangle( 10, 10, 220, 70, pyray.fade(pyray.SKYBLUE, 0.5))
61+
pyray.draw_rectangle_lines( 10, 10, 220, 70, pyray.BLUE)
62+
63+
pyray.draw_text("First person camera default controls:", 20, 20, 10, pyray.BLACK)
64+
pyray.draw_text("- Move with keys: W, A, S, D", 40, 40, 10, pyray.DARKGRAY)
65+
pyray.draw_text("- Mouse move to look around", 40, 60, 10, pyray.DARKGRAY)
66+
67+
pyray.end_drawing()
68+
69+
pyray.close_window()

0 commit comments

Comments
 (0)
0