Просмотр исходного кода

Update core_3d_picking.c

pull/849/head
Ray 5 лет назад
Родитель
Сommit
3dfbeb5488
1 измененных файлов: 12 добавлений и 8 удалений
  1. +12
    -8
      examples/core/core_3d_picking.c

+ 12
- 8
examples/core/core_3d_picking.c Просмотреть файл

@ -21,7 +21,7 @@ int main(void)
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d picking");
// Define the camera to look into our 3d world
Camera camera;
Camera camera = { 0 };
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)
@ -31,7 +31,7 @@ int main(void)
Vector3 cubePosition = { 0.0f, 1.0f, 0.0f };
Vector3 cubeSize = { 2.0f, 2.0f, 2.0f };
Ray ray = {0.0f, 0.0f, 0.0f}; // Picking line ray
Ray ray = { 0 }; // Picking line ray
bool collision = false;
@ -49,12 +49,16 @@ int main(void)
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 },
(Vector3){ cubePosition.x + cubeSize.x/2, cubePosition.y + cubeSize.y/2, cubePosition.z + cubeSize.z/2 }});
if (!collision)
{
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 },
(Vector3){ cubePosition.x + cubeSize.x/2, cubePosition.y + cubeSize.y/2, cubePosition.z + cubeSize.z/2 }});
}
else collision = false;
}
//----------------------------------------------------------------------------------

Загрузка…
Отмена
Сохранить