summaryrefslogtreecommitdiffhomepage
path: root/examples/core
diff options
context:
space:
mode:
authorRay <[email protected]>2023-02-14 20:00:51 +0100
committerRay <[email protected]>2023-02-14 20:00:51 +0100
commitea590c44a967075b3f6b420fa76e6387075ecf1d (patch)
treeb456de45fef83507415dcc309c05e64cb9232946 /examples/core
parent73989a49817225f11f547d270598e93745bf7df0 (diff)
downloadraylib-ea590c44a967075b3f6b420fa76e6387075ecf1d.tar.gz
raylib-ea590c44a967075b3f6b420fa76e6387075ecf1d.zip
REVIEWED: Camera redesign PR
Diffstat (limited to 'examples/core')
-rw-r--r--examples/core/core_3d_camera_first_person.c41
-rw-r--r--examples/core/core_3d_camera_free.c4
-rw-r--r--examples/core/core_3d_picking.c9
-rw-r--r--examples/core/core_vr_simulator.c6
-rw-r--r--examples/core/core_world_screen.c17
5 files changed, 44 insertions, 33 deletions
diff --git a/examples/core/core_3d_camera_first_person.c b/examples/core/core_3d_camera_first_person.c
index d98a002f..0fc784fa 100644
--- a/examples/core/core_3d_camera_first_person.c
+++ b/examples/core/core_3d_camera_first_person.c
@@ -30,13 +30,12 @@ int main(void)
// Define the camera to look into our 3d world (position, target, up vector)
Camera camera = { 0 };
- camera.position = (Vector3){ 0.0f, 2.0f, 4.0f };
- camera.target = (Vector3){ 0.0f, 2.0f, 0.0f };
- camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
- camera.fovy = 60.0f;
- camera.projection = CAMERA_PERSPECTIVE;
- camera.swingCounter = 1; // Enable view bobbing
-
+ camera.position = (Vector3){ 0.0f, 2.0f, 4.0f }; // Camera position
+ camera.target = (Vector3){ 0.0f, 2.0f, 0.0f }; // Camera looking at point
+ camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
+ camera.fovy = 60.0f; // Camera field-of-view Y
+ camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
+
int cameraMode = CAMERA_FIRST_PERSON;
// Generates some random columns
@@ -51,36 +50,46 @@ int main(void)
colors[i] = (Color){ GetRandomValue(20, 255), GetRandomValue(10, 55), 30, 255 };
}
- DisableCursor(); // Catch cursor
- SetTargetFPS(60); // Set our game to run at 60 frames-per-second
+ DisableCursor(); // Limit cursor to relative movement inside the window
+
+ SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
// Main game loop
- while (!WindowShouldClose()) // Detect window close button or ESC key
+ while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
// Switch camera mode
- if (IsKeyPressed(KEY_ONE)) {
+ if (IsKeyPressed(KEY_ONE))
+ {
cameraMode = CAMERA_FREE;
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Reset roll
}
- if (IsKeyPressed(KEY_TWO)) {
+
+ if (IsKeyPressed(KEY_TWO))
+ {
cameraMode = CAMERA_FIRST_PERSON;
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Reset roll
}
- if (IsKeyPressed(KEY_THREE)) {
+
+ if (IsKeyPressed(KEY_THREE))
+ {
cameraMode = CAMERA_THIRD_PERSON;
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Reset roll
}
- if (IsKeyPressed(KEY_FOUR)) {
+
+ if (IsKeyPressed(KEY_FOUR))
+ {
cameraMode = CAMERA_ORBITAL;
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Reset roll
}
// Switch camera projection
- if (IsKeyPressed(KEY_P)) {
- if (camera.projection == CAMERA_PERSPECTIVE) {
+ if (IsKeyPressed(KEY_P))
+ {
+ if (camera.projection == CAMERA_PERSPECTIVE)
+ {
// Create isometric view
cameraMode = CAMERA_THIRD_PERSON;
// Note: The target distance is related to the render distance in the orthographic projection
diff --git a/examples/core/core_3d_camera_free.c b/examples/core/core_3d_camera_free.c
index 887a1df3..59bd158a 100644
--- a/examples/core/core_3d_camera_free.c
+++ b/examples/core/core_3d_camera_free.c
@@ -31,10 +31,12 @@ int main(void)
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
camera.fovy = 45.0f; // Camera field-of-view Y
- camera.projection = CAMERA_PERSPECTIVE; // Camera mode type
+ camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
+ DisableCursor(); // Limit cursor to relative movement inside the window
+
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
diff --git a/examples/core/core_3d_picking.c b/examples/core/core_3d_picking.c
index 0cf56f5f..c7bf9466 100644
--- a/examples/core/core_3d_picking.c
+++ b/examples/core/core_3d_picking.c
@@ -31,16 +31,13 @@ int main(void)
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
camera.fovy = 45.0f; // Camera field-of-view Y
- camera.projection = CAMERA_PERSPECTIVE; // Camera mode type
+ camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
Vector3 cubePosition = { 0.0f, 1.0f, 0.0f };
Vector3 cubeSize = { 2.0f, 2.0f, 2.0f };
Ray ray = { 0 }; // Picking line ray
-
- RayCollision collision = { 0 };
-
- EnableCursor(); // Disable camera controls
+ RayCollision collision = { 0 }; // Ray collision hit info
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@@ -50,7 +47,7 @@ int main(void)
{
// Update
//----------------------------------------------------------------------------------
- if (IsCursorHidden()) UpdateCamera(&camera, CAMERA_FIRST_PERSON); // Update camera
+ if (IsCursorHidden()) UpdateCamera(&camera, CAMERA_FIRST_PERSON);
// Toggle camera controls
if (IsMouseButtonPressed(MOUSE_BUTTON_RIGHT))
diff --git a/examples/core/core_vr_simulator.c b/examples/core/core_vr_simulator.c
index 3024b785..bc69cc69 100644
--- a/examples/core/core_vr_simulator.c
+++ b/examples/core/core_vr_simulator.c
@@ -95,12 +95,12 @@ int main(void)
camera.target = (Vector3){ 0.0f, 2.0f, 0.0f }; // Camera looking at point
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector
camera.fovy = 60.0f; // Camera field-of-view Y
- camera.projection = CAMERA_PERSPECTIVE; // Camera type
- camera.swingCounter = 1; // Enable view bobbing
+ camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
- DisableCursor(); // Catch cursor
+ DisableCursor(); // Limit cursor to relative movement inside the window
+
SetTargetFPS(90); // Set our game to run at 90 frames-per-second
//--------------------------------------------------------------------------------------
diff --git a/examples/core/core_world_screen.c b/examples/core/core_world_screen.c
index f96690ba..6c811a50 100644
--- a/examples/core/core_world_screen.c
+++ b/examples/core/core_world_screen.c
@@ -27,16 +27,17 @@ int main(void)
// Define the camera to look into our 3d world
Camera camera = { 0 };
- camera.position = (Vector3){ 10.0f, 10.0f, 10.0f };
- camera.target = (Vector3){ 0.0f, 0.0f, 0.0f };
- camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
- camera.fovy = 45.0f;
- camera.projection = CAMERA_PERSPECTIVE;
+ camera.position = (Vector3){ 10.0f, 10.0f, 10.0f }; // Camera position
+ camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
+ camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
+ camera.fovy = 45.0f; // Camera field-of-view Y
+ camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
Vector2 cubeScreenPosition = { 0.0f, 0.0f };
- DisableCursor(); // Catch cursor
+ DisableCursor(); // Limit cursor to relative movement inside the window
+
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@@ -67,7 +68,9 @@ int main(void)
EndMode3D();
DrawText("Enemy: 100 / 100", (int)cubeScreenPosition.x - MeasureText("Enemy: 100/100", 20)/2, (int)cubeScreenPosition.y, 20, BLACK);
- DrawText("Text is always on top of the cube", (screenWidth - MeasureText("Text is always on top of the cube", 20))/2, 25, 20, GRAY);
+
+ DrawText(TextFormat("Cube position in screen space coordinates: [%i, %i]", (int)cubeScreenPosition.x, (int)cubeScreenPosition.y), 10, 10, 20, LIME);
+ DrawText("Text 2d should be always on top of the cube", 10, 40, 20, GRAY);
EndDrawing();
//----------------------------------------------------------------------------------