|
| 1 | +from raylib import Fade |
| 2 | +import pyray |
| 3 | +from pyray import * |
| 4 | + |
| 5 | +# Initialization |
| 6 | +screenWidth = 800 |
| 7 | +screenHeight = 450 |
| 8 | + |
| 9 | +init_window(screenWidth, screenHeight, "raylib [core] example - 3d camera free") |
| 10 | + |
| 11 | +# Define the camera to look into our 3d world |
| 12 | +camera = Camera3D() |
| 13 | +camera.position = Vector3(10.0, 10.0, 10.0) # Camera position |
| 14 | +camera.target = Vector3(0.0, 0.0, 0.0) # Camera looking at point |
| 15 | +camera.up = Vector3(0.0, 1.0, 0.0) # Camera up vector (rotation towards target) |
| 16 | +camera.fovy = 45.0 # Camera field-of-view Y |
| 17 | +camera.projection = pyray.CAMERA_PERSPECTIVE # Camera projection type |
| 18 | + |
| 19 | +cubePosition = Vector3(0.0, 0.0, 0.0) |
| 20 | + |
| 21 | +disable_cursor() # Limit cursor to relative movement inside the window |
| 22 | + |
| 23 | +set_target_fps(60) # Set our game to run at 60 frames-per-second |
| 24 | + |
| 25 | +# Main game loop |
| 26 | +while not window_should_close(): # Detect window close button or ESC key |
| 27 | + # Update |
| 28 | + update_camera(camera, pyray.CAMERA_FREE) |
| 29 | + |
| 30 | + if is_key_down(pyray.KEY_Z): |
| 31 | + camera.target = Vector3(0.0, 0.0, 0.0) |
| 32 | + |
| 33 | + # Draw |
| 34 | + begin_drawing() |
| 35 | + |
| 36 | + clear_background(RAYWHITE) |
| 37 | + |
| 38 | + begin_mode_3d(camera) |
| 39 | + |
| 40 | + draw_cube(cubePosition, 2.0, 2.0, 2.0, RED) |
| 41 | + draw_cube_wires(cubePosition, 2.0, 2.0, 2.0, MAROON) |
| 42 | + |
| 43 | + draw_grid(10, 1.0) |
| 44 | + |
| 45 | + end_mode_3d() |
| 46 | + |
| 47 | + draw_rectangle(10, 10, 320, 133, Fade(SKYBLUE, 0.5)) |
| 48 | + draw_rectangle_lines(10, 10, 320, 133, BLUE) |
| 49 | + |
| 50 | + draw_text("Free camera default controls:", 20, 20, 10, BLACK) |
| 51 | + draw_text("- Mouse Wheel to Zoom in-out", 40, 40, 10, DARKGRAY) |
| 52 | + draw_text("- Mouse Wheel Pressed to Pan", 40, 60, 10, DARKGRAY) |
| 53 | + draw_text("- Alt + Mouse Wheel Pressed to Rotate", 40, 80, 10, DARKGRAY) |
| 54 | + draw_text("- Alt + Ctrl + Mouse Wheel Pressed for Smooth Zoom", 40, 100, 10, DARKGRAY) |
| 55 | + draw_text("- Z to zoom to (0, 0, 0)", 40, 120, 10, DARKGRAY) |
| 56 | + |
| 57 | + end_drawing() |
| 58 | + |
| 59 | +# De-Initialization |
| 60 | +close_window() # Close window and OpenGL context |
0 commit comments