|
@ -29,11 +29,11 @@ int main() |
|
|
|
|
|
|
|
|
Vector3 cubePosition = { 0.0f, 1.0f, 0.0f }; |
|
|
Vector3 cubePosition = { 0.0f, 1.0f, 0.0f }; |
|
|
Vector3 cubeSize = { 2.0f, 2.0f, 2.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; |
|
|
bool collision = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SetCameraMode(camera, CAMERA_FREE); // Set a free camera mode |
|
|
SetCameraMode(camera, CAMERA_FREE); // Set a free 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 |
|
@ -45,11 +45,11 @@ int main() |
|
|
// Update |
|
|
// Update |
|
|
//---------------------------------------------------------------------------------- |
|
|
//---------------------------------------------------------------------------------- |
|
|
UpdateCamera(&camera); // Update camera |
|
|
UpdateCamera(&camera); // Update camera |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) |
|
|
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) |
|
|
{ |
|
|
{ |
|
|
ray = GetMouseRay(GetMousePosition(), camera); |
|
|
ray = GetMouseRay(GetMousePosition(), camera); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check collision between ray and box |
|
|
// Check collision between ray and box |
|
|
collision = CheckCollisionRayBox(ray, |
|
|
collision = CheckCollisionRayBox(ray, |
|
|
(BoundingBox){(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 }, |
|
@ -65,7 +65,7 @@ int main() |
|
|
|
|
|
|
|
|
Begin3dMode(camera); |
|
|
Begin3dMode(camera); |
|
|
|
|
|
|
|
|
if (collision) |
|
|
|
|
|
|
|
|
if (collision) |
|
|
{ |
|
|
{ |
|
|
DrawCube(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, RED); |
|
|
DrawCube(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, RED); |
|
|
DrawCubeWires(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, MAROON); |
|
|
DrawCubeWires(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, MAROON); |
|
@ -77,15 +77,14 @@ int main() |
|
|
DrawCube(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, GRAY); |
|
|
DrawCube(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, GRAY); |
|
|
DrawCubeWires(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, DARKGRAY); |
|
|
DrawCubeWires(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, DARKGRAY); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DrawRay(ray, MAROON); |
|
|
DrawRay(ray, MAROON); |
|
|
|
|
|
|
|
|
DrawGrid(10, 1.0f); |
|
|
DrawGrid(10, 1.0f); |
|
|
|
|
|
|
|
|
End3dMode(); |
|
|
End3dMode(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DrawText("Try selecting the box with mouse!", 240, 10, 20, DARKGRAY); |
|
|
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); |
|
|
if(collision) DrawText("BOX SELECTED", (screenWidth - MeasureText("BOX SELECTED", 30)) / 2, screenHeight * 0.1f, 30, GREEN); |
|
|
|
|
|
|
|
|
DrawFPS(10, 10); |
|
|
DrawFPS(10, 10); |
|
@ -100,4 +99,4 @@ int main() |
|
|
//-------------------------------------------------------------------------------------- |
|
|
//-------------------------------------------------------------------------------------- |
|
|
|
|
|
|
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
|
|
|
|
|
|
} |