mirror of
https://github.com/raysan5/raylib.git
synced 2026-02-21 04:59:17 -05:00
REVIEWED: models_basic_voxel example
This commit is contained in:
@ -16,6 +16,7 @@
|
|||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
|
||||||
#include "raymath.h"
|
#include "raymath.h"
|
||||||
|
|
||||||
#define WORLD_SIZE 8 // Size of our voxel world (8x8x8 cubes)
|
#define WORLD_SIZE 8 // Size of our voxel world (8x8x8 cubes)
|
||||||
@ -32,7 +33,7 @@ int main(void)
|
|||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - basic voxel");
|
InitWindow(screenWidth, screenHeight, "raylib [models] example - basic voxel");
|
||||||
|
|
||||||
DisableCursor(); // Lock mouse to window center
|
DisableCursor(); // Lock mouse to window center
|
||||||
|
|
||||||
// Define the camera to look into our 3d world (first person)
|
// Define the camera to look into our 3d world (first person)
|
||||||
Camera3D camera = { 0 };
|
Camera3D camera = { 0 };
|
||||||
@ -59,7 +60,7 @@ int main(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
@ -74,7 +75,7 @@ int main(void)
|
|||||||
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
|
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
|
||||||
{
|
{
|
||||||
// Cast a ray from the screen center (where crosshair would be)
|
// Cast a ray from the screen center (where crosshair would be)
|
||||||
Vector2 screenCenter = { screenWidth/2.0f, screenHeight/2.0f };
|
Vector2 screenCenter = { GetScreenWidth()/2.0f, GetScreenHeight()/2.0f };
|
||||||
Ray ray = GetMouseRay(screenCenter, camera);
|
Ray ray = GetMouseRay(screenCenter, camera);
|
||||||
|
|
||||||
// Check ray collision with all voxels
|
// Check ray collision with all voxels
|
||||||
@ -132,8 +133,11 @@ int main(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EndMode3D();
|
EndMode3D();
|
||||||
|
|
||||||
|
// Draw reference point for raycasting to delete blocks
|
||||||
|
DrawCircle(GetRenderWidth()/2, GetScreenHeight()/2, 4, RED);
|
||||||
|
|
||||||
DrawText("Left-click a voxel to remove it!", 10, 10, 20, DARKGRAY);
|
DrawText("Left-click a voxel to remove it!", 10, 10, 20, DARKGRAY);
|
||||||
DrawText("WASD to move, mouse to look around", 10, 35, 10, GRAY);
|
DrawText("WASD to move, mouse to look around", 10, 35, 10, GRAY);
|
||||||
@ -145,6 +149,7 @@ int main(void)
|
|||||||
// De-Initialization
|
// De-Initialization
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
UnloadModel(cubeModel);
|
UnloadModel(cubeModel);
|
||||||
|
|
||||||
CloseWindow();
|
CloseWindow();
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 341 KiB After Width: | Height: | Size: 28 KiB |
Reference in New Issue
Block a user