From ab07e099dbf782c4c69cd0f0e06d1f37a3a887bf Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 14 Aug 2018 19:32:27 +0200 Subject: Updated examples --- examples/src/core/core_2d_camera.c | 4 ++-- examples/src/core/core_3d_camera_first_person.c | 11 +++++++--- examples/src/core/core_3d_camera_free.c | 7 ++++--- examples/src/core/core_3d_mode.c | 7 ++++--- examples/src/core/core_3d_picking.c | 28 ++++++++++++------------- examples/src/core/core_basic_window.c | 4 +--- examples/src/core/core_input_keys.c | 8 +++---- examples/src/core/core_vr_simulator.c | 5 +++-- examples/src/core/core_world_screen.c | 11 +++++++--- 9 files changed, 48 insertions(+), 37 deletions(-) (limited to 'examples/src/core') diff --git a/examples/src/core/core_2d_camera.c b/examples/src/core/core_2d_camera.c index f2f219e..7c35c90 100644 --- a/examples/src/core/core_2d_camera.c +++ b/examples/src/core/core_2d_camera.c @@ -97,7 +97,7 @@ int main() ClearBackground(RAYWHITE); - Begin2dMode(camera); + BeginMode2D(camera); DrawRectangle(-6000, 320, 13000, 8000, DARKGRAY); @@ -108,7 +108,7 @@ int main() DrawRectangle(camera.target.x, -500, 1, screenHeight*4, GREEN); DrawRectangle(-500, camera.target.y, screenWidth*4, 1, GREEN); - End2dMode(); + EndMode2D(); DrawText("SCREEN AREA", 640, 10, 20, RED); diff --git a/examples/src/core/core_3d_camera_first_person.c b/examples/src/core/core_3d_camera_first_person.c index 3998af8..d3a8f2e 100644 --- a/examples/src/core/core_3d_camera_first_person.c +++ b/examples/src/core/core_3d_camera_first_person.c @@ -23,7 +23,12 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera first person"); // Define the camera to look into our 3d world (position, target, up vector) - Camera camera = {{ 4.0f, 2.0f, 4.0f }, { 0.0f, 1.8f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 60.0f }; + Camera camera = { 0 }; + camera.position = (Vector3){ 4.0f, 2.0f, 4.0f }; + camera.target = (Vector3){ 0.0f, 1.8f, 0.0f }; + camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; + camera.fovy = 60.0f; + camera.type = CAMERA_PERSPECTIVE; // Generates some random columns float heights[MAX_COLUMNS]; @@ -56,7 +61,7 @@ int main() ClearBackground(RAYWHITE); - Begin3dMode(camera); + BeginMode3D(camera); DrawPlane((Vector3){ 0.0f, 0.0f, 0.0f }, (Vector2){ 32.0f, 32.0f }, LIGHTGRAY); // Draw ground DrawCube((Vector3){ -16.0f, 2.5f, 0.0f }, 1.0f, 5.0f, 32.0f, BLUE); // Draw a blue wall @@ -70,7 +75,7 @@ int main() DrawCubeWires(positions[i], 2.0f, heights[i], 2.0f, MAROON); } - End3dMode(); + EndMode3D(); DrawRectangle( 10, 10, 220, 70, Fade(SKYBLUE, 0.5f)); DrawRectangleLines( 10, 10, 220, 70, BLUE); diff --git a/examples/src/core/core_3d_camera_free.c b/examples/src/core/core_3d_camera_free.c index d446e14..9131ddf 100644 --- a/examples/src/core/core_3d_camera_free.c +++ b/examples/src/core/core_3d_camera_free.c @@ -21,11 +21,12 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free"); // Define the camera to look into our 3d world - Camera camera; + Camera3D camera; 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.type = CAMERA_PERSPECTIVE; // Camera mode type Vector3 cubePosition = { 0.0f, 0.0f, 0.0f }; @@ -50,14 +51,14 @@ int main() ClearBackground(RAYWHITE); - Begin3dMode(camera); + BeginMode3D(camera); DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED); DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON); DrawGrid(10, 1.0f); - End3dMode(); + EndMode3D(); DrawRectangle( 10, 10, 320, 133, Fade(SKYBLUE, 0.5f)); DrawRectangleLines( 10, 10, 320, 133, BLUE); diff --git a/examples/src/core/core_3d_mode.c b/examples/src/core/core_3d_mode.c index 5f76165..39c0752 100644 --- a/examples/src/core/core_3d_mode.c +++ b/examples/src/core/core_3d_mode.c @@ -21,11 +21,12 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d mode"); // Define the camera to look into our 3d world - Camera camera; + Camera3D camera; camera.position = (Vector3){ 0.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.type = CAMERA_PERSPECTIVE; // Camera mode type Vector3 cubePosition = { 0.0f, 0.0f, 0.0f }; @@ -46,14 +47,14 @@ int main() ClearBackground(RAYWHITE); - Begin3dMode(camera); + BeginMode3D(camera); DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED); DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON); DrawGrid(10, 1.0f); - End3dMode(); + EndMode3D(); DrawText("Welcome to the third dimension!", 10, 40, 20, DARKGRAY); diff --git a/examples/src/core/core_3d_picking.c b/examples/src/core/core_3d_picking.c index 7658b39..1c63e2a 100644 --- a/examples/src/core/core_3d_picking.c +++ b/examples/src/core/core_3d_picking.c @@ -26,14 +26,15 @@ int main() 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.type = CAMERA_PERSPECTIVE; // Camera mode type Vector3 cubePosition = { 0.0f, 1.0f, 0.0f }; Vector3 cubeSize = { 2.0f, 2.0f, 2.0f }; - - Ray ray; // Picking line ray - + + Ray ray = {0.0f, 0.0f, 0.0f}; // Picking line ray + bool collision = false; - + SetCameraMode(camera, CAMERA_FREE); // Set a free camera mode SetTargetFPS(60); // Set our game to run at 60 frames-per-second @@ -45,11 +46,11 @@ int main() // Update //---------------------------------------------------------------------------------- UpdateCamera(&camera); // Update camera - + if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) { ray = GetMouseRay(GetMousePosition(), camera); - + // Check collision between ray and box collision = CheckCollisionRayBox(ray, (BoundingBox){(Vector3){ cubePosition.x - cubeSize.x/2, cubePosition.y - cubeSize.y/2, cubePosition.z - cubeSize.z/2 }, @@ -63,9 +64,9 @@ int main() ClearBackground(RAYWHITE); - Begin3dMode(camera); + BeginMode3D(camera); - if (collision) + if (collision) { DrawCube(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, RED); DrawCubeWires(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, MAROON); @@ -77,15 +78,14 @@ int main() DrawCube(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, GRAY); DrawCubeWires(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, DARKGRAY); } - + DrawRay(ray, MAROON); - DrawGrid(10, 1.0f); - End3dMode(); - + EndMode3D(); + DrawText("Try selecting the box with mouse!", 240, 10, 20, DARKGRAY); - + if(collision) DrawText("BOX SELECTED", (screenWidth - MeasureText("BOX SELECTED", 30)) / 2, screenHeight * 0.1f, 30, GREEN); DrawFPS(10, 10); @@ -100,4 +100,4 @@ int main() //-------------------------------------------------------------------------------------- return 0; -} \ No newline at end of file +} diff --git a/examples/src/core/core_basic_window.c b/examples/src/core/core_basic_window.c index 1db38c9..51caa45 100644 --- a/examples/src/core/core_basic_window.c +++ b/examples/src/core/core_basic_window.c @@ -1,8 +1,6 @@ /******************************************************************************************* * -* raylib [core] example - Basic window -* -* Welcome to raylib! +* raylib [core] example - basic window * * This example has been created using raylib 1.0 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) diff --git a/examples/src/core/core_input_keys.c b/examples/src/core/core_input_keys.c index b230524..69384fd 100644 --- a/examples/src/core/core_input_keys.c +++ b/examples/src/core/core_input_keys.c @@ -30,10 +30,10 @@ int main() { // Update //---------------------------------------------------------------------------------- - if (IsKeyDown(KEY_RIGHT)) ballPosition.x += 0.8f; - if (IsKeyDown(KEY_LEFT)) ballPosition.x -= 0.8f; - if (IsKeyDown(KEY_UP)) ballPosition.y -= 0.8f; - if (IsKeyDown(KEY_DOWN)) ballPosition.y += 0.8f; + if (IsKeyDown(KEY_RIGHT)) ballPosition.x += 2.0f; + if (IsKeyDown(KEY_LEFT)) ballPosition.x -= 2.0f; + if (IsKeyDown(KEY_UP)) ballPosition.y -= 2.0f; + if (IsKeyDown(KEY_DOWN)) ballPosition.y += 2.0f; //---------------------------------------------------------------------------------- // Draw diff --git a/examples/src/core/core_vr_simulator.c b/examples/src/core/core_vr_simulator.c index d919c41..3f59e83 100644 --- a/examples/src/core/core_vr_simulator.c +++ b/examples/src/core/core_vr_simulator.c @@ -31,6 +31,7 @@ int main() 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.type = CAMERA_PERSPECTIVE; // Camera type Vector3 cubePosition = { 0.0f, 0.0f, 0.0f }; @@ -57,14 +58,14 @@ int main() BeginVrDrawing(); - Begin3dMode(camera); + BeginMode3D(camera); DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED); DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON); DrawGrid(40, 1.0f); - End3dMode(); + EndMode3D(); EndVrDrawing(); diff --git a/examples/src/core/core_world_screen.c b/examples/src/core/core_world_screen.c index f8c53c7..460f6b8 100644 --- a/examples/src/core/core_world_screen.c +++ b/examples/src/core/core_world_screen.c @@ -21,7 +21,12 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free"); // Define the camera to look into our 3d world - Camera camera = {{ 10.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f }; + 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.type = CAMERA_PERSPECTIVE; Vector3 cubePosition = { 0.0f, 0.0f, 0.0f }; @@ -49,14 +54,14 @@ int main() ClearBackground(RAYWHITE); - Begin3dMode(camera); + BeginMode3D(camera); DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED); DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON); DrawGrid(10, 1.0f); - End3dMode(); + EndMode3D(); DrawText("Enemy: 100 / 100", cubeScreenPosition.x - MeasureText("Enemy: 100 / 100", 20) / 2, 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); -- cgit v1.2.3