-
Notifications
You must be signed in to change notification settings - Fork 1
/
core_3d_camera_free.php
104 lines (81 loc) · 3.07 KB
/
core_3d_camera_free.php
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
<?php
declare(strict_types=1);
require_once __DIR__ . '/../../vendor/autoload.php';
use Nawarian\Raylib\Raylib;
use Nawarian\Raylib\Types\{
Camera3D,
Color,
Vector3,
};
use function Nawarian\Raylib\{
BeginDrawing,
BeginMode3D,
ClearBackground,
CloseWindow,
DrawCube,
DrawCubeWires,
DrawGrid,
DrawRectangle,
DrawRectangleLines,
DrawText,
EndDrawing,
EndMode3D,
Fade,
InitWindow,
IsKeyDown,
SetCameraMode,
SetTargetFPS,
UpdateCamera,
WindowShouldClose
};
const MAX_COLUMNS = 20;
// Initialization
//--------------------------------------------------------------------------------------
$screenWidth = 800;
$screenHeight = 450;
InitWindow($screenWidth, $screenHeight, "raylib [core] example - 3d camera free");
// Define the camera to look into our 3d world
$camera = new Camera3D(
new Vector3(10.0, 10.0, 10.0),
new Vector3(0.0, 0.0, 0.0),
new Vector3(0.0, 1.0, 0.0),
45.0,
Camera3D::PROJECTION_PERSPECTIVE,
);
$cubePosition = new Vector3(0, 0, 0);
SetCameraMode($camera, Camera3D::MODE_FREE); // Set a free camera mode
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) { // Detect window close button or ESC key
// Update
//----------------------------------------------------------------------------------
UpdateCamera($camera); // Update camera
if (IsKeyDown(Raylib::KEY_Z)) {
$camera->target = new Vector3(0, 0, 0);
}
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(Color::rayWhite());
BeginMode3D($camera);
DrawCube($cubePosition, 2.0, 2.0, 2.0, Color::red());
DrawCubeWires($cubePosition, 2.0, 2.0, 2.0, Color::maroon());
DrawGrid(10, 1.0);
EndMode3D();
DrawRectangle(10, 10, 320, 133, Fade(Color::skyBlue(), 0.5));
DrawRectangleLines(10, 10, 320, 133, Color::blue());
DrawText("Free camera default controls:", 20, 20, 10, Color::black());
DrawText("- Mouse Wheel to Zoom in-out", 40, 40, 10, Color::darkGray());
DrawText("- Mouse Wheel Pressed to Pan", 40, 60, 10, Color::darkGray());
DrawText("- Alt + Mouse Wheel Pressed to Rotate", 40, 80, 10, Color::darkGray());
DrawText("- Alt + Ctrl + Mouse Wheel Pressed for Smooth Zoom", 40, 100, 10, Color::darkGray());
DrawText("- Z to zoom to (0, 0, 0)", 40, 120, 10, Color::darkGray());
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------