MCPcopy Create free account
hub / github.com/RobLoach/raylib-cpp / main

Function main

examples/core/core_world_screen.cpp:14–74  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12#include "raylib-cpp.hpp"
13
14int main() {
15 // Initialization
16 //--------------------------------------------------------------------------------------
17 const int screenWidth = 800;
18 const int screenHeight = 450;
19
20 raylib::Window window(screenWidth, screenHeight, "raylib [core] example - 3d camera free");
21
22 // Define the camera to look into our 3d world
23 raylib::Camera camera(
24 raylib::Vector3(10.0f, 10.0f, 10.0f),
25 raylib::Vector3(),
26 raylib::Vector3(0.0f, 1.0f, 0.0f),
27 45.0f,
28 CAMERA_PERSPECTIVE);
29
30 Vector3 cubePosition;
31 Vector2 cubeScreenPosition;
32
33 SetTargetFPS(60); // Set our game to run at 60 frames-per-second
34 //--------------------------------------------------------------------------------------
35
36 // Main game loop
37 while (!window.ShouldClose()) { // Detect window close button or ESC key
38 // Update
39 //----------------------------------------------------------------------------------
40 camera.Update(CAMERA_THIRD_PERSON); // Update camera
41
42 // Calculate cube screen space position (with a little offset to be in top)
43 cubeScreenPosition = GetWorldToScreen(Vector3{cubePosition.x, cubePosition.y + 2.5f, cubePosition.z}, camera);
44 //----------------------------------------------------------------------------------
45
46 // Draw
47 //----------------------------------------------------------------------------------
48 BeginDrawing();
49 {
50 window.ClearBackground(RAYWHITE);
51
52 camera.BeginMode();
53 {
54 DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
55 DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);
56
57 DrawGrid(10, 1.0f);
58 }
59 camera.EndMode();
60
61 raylib::DrawText("Enemy: 100 / 100",
62 cubeScreenPosition.x - MeasureText("Enemy: 100/100", 20) / 2,
63 cubeScreenPosition.y, 20,
64 BLACK);
65 raylib::DrawText("Text is always on top of the cube",
66 (screenWidth - MeasureText("Text is always on top of the cube", 20)) / 2,
67 25, 20, GRAY);
68 }
69 EndDrawing();
70 //----------------------------------------------------------------------------------
71 }

Callers

nothing calls this directly

Calls 7

Vector3Class · 0.85
DrawCubeFunction · 0.85
DrawCubeWiresFunction · 0.85
MeasureTextFunction · 0.85
ShouldCloseMethod · 0.80
DrawTextFunction · 0.50
UpdateMethod · 0.45

Tested by

no test coverage detected