diff options
| author | victorfisac <[email protected]> | 2017-03-06 09:47:08 +0100 |
|---|---|---|
| committer | victorfisac <[email protected]> | 2017-03-06 09:47:08 +0100 |
| commit | f9277f216372179560c560427beccdd2e5c5d094 (patch) | |
| tree | 8d3858c978f2b36ea8912f25e3cbe6fa56952aff /examples/core_3d_picking.c | |
| parent | ce56fcb1eda06385b88c1a906f0968d742ff8130 (diff) | |
| parent | c05701253e0a4eda211a0d7ced74ae29d6585917 (diff) | |
| download | raylib-f9277f216372179560c560427beccdd2e5c5d094.tar.gz raylib-f9277f216372179560c560427beccdd2e5c5d094.zip | |
Merge remote-tracking branch 'refs/remotes/raysan5/master'
Diffstat (limited to 'examples/core_3d_picking.c')
| -rw-r--r-- | examples/core_3d_picking.c | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/examples/core_3d_picking.c b/examples/core_3d_picking.c index fdf77030..bd5c3347 100644 --- a/examples/core_3d_picking.c +++ b/examples/core_3d_picking.c @@ -22,9 +22,10 @@ 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 Vector3 cubePosition = { 0.0f, 1.0f, 0.0f }; Vector3 cubeSize = { 2.0f, 2.0f, 2.0f }; @@ -33,8 +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 + SetCameraMode(camera, CAMERA_FREE); // Set a free camera mode SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- @@ -44,7 +44,7 @@ int main() { // Update //---------------------------------------------------------------------------------- - UpdateCamera(&camera); // Update internal camera and our camera + UpdateCamera(&camera); // Update camera if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) { @@ -53,8 +53,8 @@ int main() // Check collision between ray and box collision = CheckCollisionRayBox(ray, - (Vector3){ cubePosition.x - cubeSize.x/2, cubePosition.y - cubeSize.y/2, cubePosition.z - cubeSize.z/2 }, - (Vector3){ cubePosition.x + cubeSize.x/2, cubePosition.y + cubeSize.y/2, cubePosition.z + cubeSize.z/2 }); + (BoundingBox){(Vector3){ cubePosition.x - cubeSize.x/2, cubePosition.y - cubeSize.y/2, cubePosition.z - cubeSize.z/2 }, + (Vector3){ cubePosition.x + cubeSize.x/2, cubePosition.y + cubeSize.y/2, cubePosition.z + cubeSize.z/2 }}); } //---------------------------------------------------------------------------------- @@ -66,8 +66,18 @@ int main() Begin3dMode(camera); - DrawCube(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, GRAY); - DrawCubeWires(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, DARKGRAY); + if (collision) + { + DrawCube(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, RED); + DrawCubeWires(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, MAROON); + + DrawCubeWires(cubePosition, cubeSize.x + 0.2f, cubeSize.y + 0.2f, cubeSize.z + 0.2f, GREEN); + } + else + { + DrawCube(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, GRAY); + DrawCubeWires(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, DARKGRAY); + } DrawRay(ray, MAROON); @@ -75,7 +85,7 @@ int main() End3dMode(); - DrawText("Try selecting the box with mouse!", 240, 10, 20, GRAY); + 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); |
