From 648676f46b01327f0fbd6f017292a3159ea9ab2f Mon Sep 17 00:00:00 2001 From: raysan5 Date: Mon, 10 Oct 2016 19:43:27 +0200 Subject: [PATCH] Update examples to new camera system --- examples/core_3d_camera_first_person.c | 2 +- examples/core_3d_camera_free.c | 2 +- examples/core_3d_picking.c | 8 +++----- examples/core_oculus_rift.c | 12 ++++++------ examples/core_world_screen.c | 9 +++------ examples/models_billboard.c | 11 ++++------- examples/models_cubicmap.c | 2 +- examples/models_heightmap.c | 11 +++++------ examples/shaders_custom_uniform.c | 6 ++---- examples/shaders_model_shader.c | 5 ++++- examples/shaders_postprocessing.c | 8 +++----- examples/shaders_standard_lighting.c | 6 ++---- 12 files changed, 35 insertions(+), 47 deletions(-) diff --git a/examples/core_3d_camera_first_person.c b/examples/core_3d_camera_first_person.c index 27ff5135..3998af81 100644 --- a/examples/core_3d_camera_first_person.c +++ b/examples/core_3d_camera_first_person.c @@ -47,7 +47,7 @@ int main() { // Update //---------------------------------------------------------------------------------- - UpdateCamera(&camera); // Update camera and player position + UpdateCamera(&camera); // Update camera //---------------------------------------------------------------------------------- // Draw diff --git a/examples/core_3d_camera_free.c b/examples/core_3d_camera_free.c index c798f225..d446e14a 100644 --- a/examples/core_3d_camera_free.c +++ b/examples/core_3d_camera_free.c @@ -39,7 +39,7 @@ int main() { // Update //---------------------------------------------------------------------------------- - UpdateCamera(&camera); // Update internal camera and our camera + UpdateCamera(&camera); // Update camera if (IsKeyDown('Z')) camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; //---------------------------------------------------------------------------------- diff --git a/examples/core_3d_picking.c b/examples/core_3d_picking.c index 7f904f7f..bd5c3347 100644 --- a/examples/core_3d_picking.c +++ b/examples/core_3d_picking.c @@ -22,7 +22,7 @@ int main() // Define the camera to look into our 3d world Camera camera; - camera.position = (Vector3){ 0.0f, 10.0f, 10.0f }; // Camera position + 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 @@ -34,9 +34,7 @@ int main() bool collision = false; - SetCameraMode(CAMERA_FREE); // Set a free camera mode - SetCameraPosition(camera.position); // Set internal camera position to match our camera position - SetCameraFovy(camera.fovy); // Set internal camera field-of-view Y + SetCameraMode(camera, CAMERA_FREE); // Set a free camera mode SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- @@ -46,7 +44,7 @@ int main() { // Update //---------------------------------------------------------------------------------- - UpdateCamera(&camera); // Update internal camera and our camera + UpdateCamera(&camera); // Update camera if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) { diff --git a/examples/core_oculus_rift.c b/examples/core_oculus_rift.c index 3d8bb278..7276e3de 100644 --- a/examples/core_oculus_rift.c +++ b/examples/core_oculus_rift.c @@ -30,14 +30,14 @@ int main() // Define the camera to look into our 3d world Camera camera; - camera.position = (Vector3){ 5.0f, 5.0f, 5.0f }; // Camera position - camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point + camera.position = (Vector3){ 5.0f, 2.0f, 5.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 Vector3 cubePosition = { 0.0f, 0.0f, 0.0f }; - SetCameraMode(camera, CAMERA_FIRST_PERSON); + SetCameraMode(camera, CAMERA_FIRST_PERSON); // Set first person camera mode SetTargetFPS(90); // Set our game to run at 90 frames-per-second //-------------------------------------------------------------------------------------- @@ -47,10 +47,10 @@ int main() { // Update //---------------------------------------------------------------------------------- - if (IsVrSimulator()) UpdateCamera(&camera); - else UpdateVrTracking(); + if (IsVrSimulator()) UpdateCamera(&camera); // Update camera (simulator mode) + else UpdateVrTracking(&camera); // Update camera with device tracking data - if (IsKeyPressed(KEY_SPACE)) ToggleVrMode(); + if (IsKeyPressed(KEY_SPACE)) ToggleVrMode(); // Toggle VR mode //---------------------------------------------------------------------------------- // Draw diff --git a/examples/core_world_screen.c b/examples/core_world_screen.c index aa9505e8..f8c53c70 100644 --- a/examples/core_world_screen.c +++ b/examples/core_world_screen.c @@ -21,16 +21,13 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free"); // Define the camera to look into our 3d world - Camera camera = {{ 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f }; + Camera camera = {{ 10.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f }; Vector3 cubePosition = { 0.0f, 0.0f, 0.0f }; Vector2 cubeScreenPosition; - SetCameraMode(CAMERA_FREE); // Set a free camera mode - SetCameraPosition(camera.position); // Set internal camera position to match our camera position - SetCameraTarget(camera.target); // Set internal camera target to match our camera target - SetCameraFovy(camera.fovy); // Set internal camera field-of-view Y + SetCameraMode(camera, CAMERA_FREE); // Set a free camera mode SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- @@ -40,7 +37,7 @@ int main() { // Update //---------------------------------------------------------------------------------- - UpdateCamera(&camera); // Update internal camera and our camera + UpdateCamera(&camera); // Update camera // Calculate cube screen space position (with a little offset to be in top) cubeScreenPosition = GetWorldToScreen((Vector3){cubePosition.x, cubePosition.y + 2.5f, cubePosition.z}, camera); diff --git a/examples/models_billboard.c b/examples/models_billboard.c index 654b3618..bca9faf8 100644 --- a/examples/models_billboard.c +++ b/examples/models_billboard.c @@ -26,20 +26,17 @@ int main() Texture2D bill = LoadTexture("resources/billboard.png"); // Our texture billboard Vector3 billPosition = { 0.0f, 2.0f, 0.0f }; // Position where draw billboard - SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode - SetCameraPosition(camera.position); // Set internal camera position to match our camera position - SetCameraTarget(camera.target); // Set internal camera target to match our camera target - SetCameraFovy(camera.fovy); // Set internal camera field-of-view Y + SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode - SetTargetFPS(60); // Set our game to run at 60 frames-per-second + 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 //---------------------------------------------------------------------------------- - UpdateCamera(&camera); // Update internal camera and our camera + UpdateCamera(&camera); // Update camera //---------------------------------------------------------------------------------- // Draw diff --git a/examples/models_cubicmap.c b/examples/models_cubicmap.c index df700d65..0e613029 100644 --- a/examples/models_cubicmap.c +++ b/examples/models_cubicmap.c @@ -45,7 +45,7 @@ int main() { // Update //---------------------------------------------------------------------------------- - UpdateCamera(&camera); // Update internal camera and our camera + UpdateCamera(&camera); // Update camera //---------------------------------------------------------------------------------- // Draw diff --git a/examples/models_heightmap.c b/examples/models_heightmap.c index 90e5f5bb..10069e03 100644 --- a/examples/models_heightmap.c +++ b/examples/models_heightmap.c @@ -29,20 +29,19 @@ int main() map.material.texDiffuse = texture; // Set map diffuse texture Vector3 mapPosition = { -8.0f, 0.0f, -8.0f }; // Set model position (depends on model scaling!) - UnloadImage(image); // Unload heightmap image from RAM, already uploaded to VRAM + UnloadImage(image); // Unload heightmap image from RAM, already uploaded to VRAM - SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode - SetCameraPosition(camera.position); // Set internal camera position to match our custom camera position + SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode - SetTargetFPS(60); // Set our game to run at 60 frames-per-second + 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 //---------------------------------------------------------------------------------- - UpdateCamera(&camera); // Update internal camera and our camera + UpdateCamera(&camera); // Update camera //---------------------------------------------------------------------------------- // Draw diff --git a/examples/shaders_custom_uniform.c b/examples/shaders_custom_uniform.c index c4f87259..89f87df9 100644 --- a/examples/shaders_custom_uniform.c +++ b/examples/shaders_custom_uniform.c @@ -51,9 +51,7 @@ int main() RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight); // Setup orbital camera - SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode - SetCameraPosition(camera.position); // Set internal camera position to match our camera position - SetCameraTarget(camera.target); // Set internal camera target to match our camera target + SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- @@ -71,7 +69,7 @@ int main() // Send new value to the shader to be used on drawing SetShaderValue(shader, swirlCenterLoc, swirlCenter, 2); - UpdateCamera(&camera); // Update internal camera and our camera + UpdateCamera(&camera); // Update camera //---------------------------------------------------------------------------------- // Draw diff --git a/examples/shaders_model_shader.c b/examples/shaders_model_shader.c index a5516eba..26de4922 100644 --- a/examples/shaders_model_shader.c +++ b/examples/shaders_model_shader.c @@ -42,7 +42,7 @@ int main() Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position - SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode + SetCameraMode(camera, CAMERA_FREE); // Set an orbital camera mode SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- @@ -70,6 +70,9 @@ int main() End3dMode(); DrawText("(c) Dwarf 3D model by David Moreno", screenWidth - 200, screenHeight - 20, 10, GRAY); + + DrawText(FormatText("Camera position: (%.2f, %.2f, %.2f)", camera.position.x, camera.position.y, camera.position.z), 600, 20, 10, BLACK); + DrawText(FormatText("Camera target: (%.2f, %.2f, %.2f)", camera.target.x, camera.target.y, camera.target.z), 600, 40, 10, GRAY); DrawFPS(10, 10); diff --git a/examples/shaders_postprocessing.c b/examples/shaders_postprocessing.c index 43d21e08..43d1af72 100644 --- a/examples/shaders_postprocessing.c +++ b/examples/shaders_postprocessing.c @@ -45,9 +45,7 @@ int main() RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight); // Setup orbital camera - SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode - SetCameraPosition(camera.position); // Set internal camera position to match our camera position - SetCameraTarget(camera.target); // Set internal camera target to match our camera target + SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- @@ -57,7 +55,7 @@ int main() { // Update //---------------------------------------------------------------------------------- - UpdateCamera(&camera); // Update internal camera and our camera + UpdateCamera(&camera); // Update camera //---------------------------------------------------------------------------------- // Draw @@ -67,7 +65,7 @@ int main() ClearBackground(RAYWHITE); BeginTextureMode(target); // Enable drawing to texture - + Begin3dMode(camera); DrawModel(dwarf, position, 2.0f, WHITE); // Draw 3d model with texture diff --git a/examples/shaders_standard_lighting.c b/examples/shaders_standard_lighting.c index f2b35171..e539ec47 100644 --- a/examples/shaders_standard_lighting.c +++ b/examples/shaders_standard_lighting.c @@ -64,9 +64,7 @@ int main() pointLight->radius = 3.0f; // Setup orbital camera - SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode - SetCameraPosition(camera.position); // Set internal camera position to match our camera position - SetCameraTarget(camera.target); // Set internal camera target to match our camera target + SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- @@ -76,7 +74,7 @@ int main() { // Update //---------------------------------------------------------------------------------- - UpdateCamera(&camera); // Update internal camera and our camera + UpdateCamera(&camera); // Update camera //---------------------------------------------------------------------------------- // Draw