summaryrefslogtreecommitdiffhomepage
path: root/examples/core_3d_picking.c
diff options
context:
space:
mode:
authorvictorfisac <[email protected]>2016-02-26 14:32:30 +0100
committervictorfisac <[email protected]>2016-02-26 14:32:30 +0100
commitce56fcb1eda06385b88c1a906f0968d742ff8130 (patch)
tree4c82fa8ce61db1ae4af3ab1e174dd8c7d5918919 /examples/core_3d_picking.c
parentf582ab06add085594f2579ee6e7d625212abd204 (diff)
parent75a73d94171051037fcf670852877977d9251520 (diff)
downloadraylib-ce56fcb1eda06385b88c1a906f0968d742ff8130.tar.gz
raylib-ce56fcb1eda06385b88c1a906f0968d742ff8130.zip
Merge remote-tracking branch 'refs/remotes/raysan5/master'
Diffstat (limited to 'examples/core_3d_picking.c')
-rw-r--r--examples/core_3d_picking.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/examples/core_3d_picking.c b/examples/core_3d_picking.c
index 2fc05e81..fdf77030 100644
--- a/examples/core_3d_picking.c
+++ b/examples/core_3d_picking.c
@@ -21,12 +21,18 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d picking");
// Define the camera to look into our 3d world
- Camera camera = {{ 0.0, 10.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }};
+ Camera 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)
- Vector3 cubePosition = { 0.0, 1.0, 0.0 };
+ Vector3 cubePosition = { 0.0f, 1.0f, 0.0f };
+ Vector3 cubeSize = { 2.0f, 2.0f, 2.0f };
Ray ray; // Picking line ray
+ bool collision = false;
+
SetCameraMode(CAMERA_FREE); // Set a free camera mode
SetCameraPosition(camera.position); // Set internal camera position to match our camera position
@@ -45,7 +51,10 @@ int main()
// NOTE: This function is NOT WORKING properly!
ray = GetMouseRay(GetMousePosition(), camera);
- // TODO: Check collision between ray and box
+ // 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 });
}
//----------------------------------------------------------------------------------
@@ -57,16 +66,18 @@ int main()
Begin3dMode(camera);
- DrawCube(cubePosition, 2, 2, 2, GRAY);
- DrawCubeWires(cubePosition, 2, 2, 2, DARKGRAY);
-
- DrawGrid(10.0, 1.0);
+ 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();
DrawText("Try selecting the box with mouse!", 240, 10, 20, GRAY);
+
+ if(collision) DrawText("BOX SELECTED", (screenWidth - MeasureText("BOX SELECTED", 30)) / 2, screenHeight * 0.1f, 30, GREEN);
DrawFPS(10, 10);