-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcore_world_screen.php
106 lines (85 loc) · 2.93 KB
/
core_world_screen.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
105
106
<?php
declare(strict_types=1);
require_once __DIR__ . '/../../vendor/autoload.php';
use Nawarian\Raylib\Types\{
Camera3D,
Color,
Vector3,
};
use function Nawarian\Raylib\{
BeginDrawing,
BeginMode3D,
ClearBackground,
CloseWindow,
DrawCube,
DrawCubeWires,
DrawGrid,
DrawText,
EndDrawing,
EndMode3D,
GetWorldToScreen,
InitWindow,
MeasureText,
SetCameraMode,
SetTargetFPS,
UpdateCamera,
WindowShouldClose
};
// 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, 10, 10),
new Vector3(0, 0, 0),
new Vector3(0, 1, 0),
45,
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
// Calculate cube screen space position (with a little offset to be in top)
$cubeScreenPosition = GetWorldToScreen(
new Vector3($cubePosition->x, $cubePosition->y + 2.5, $cubePosition->z),
$camera
);
//----------------------------------------------------------------------------------
// 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();
DrawText(
'Enemy: 100 / 100',
(int) ($cubeScreenPosition->x - MeasureText('Enemy: 100/100', 20) / 2),
(int) $cubeScreenPosition->y,
20,
Color::black()
);
DrawText(
'Text is always on top of the cube',
(int) (($screenWidth - MeasureText('Text is always on top of the cube', 20)) / 2),
25,
20,
Color::gray()
);
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------