Untitled
import rl "vendor:raylib" main :: proc() { // Initialize Raylib window rl.InitWindow(1080, 720, "3D Grid Example") defer rl.CloseWindow() // Set window to be resizable and set the target FPS rl.SetWindowState(rl.ConfigFlags{.WINDOW_RESIZABLE}) rl.SetTargetFPS(120) // Seed rand rl.SetRandomSeed(cast(u32) time.time_to_unix_nano(time.now())) // Define the 3D camera camera3d: rl.Camera3D camera3d.position = rl.Vector3{0, 10, 20} camera3d.target = rl.Vector3{0, 0, 0} camera3d.up = rl.Vector3{0, 1, 0} camera3d.fovy = 45 camera3d.projection = rl.CameraProjection.PERSPECTIVE // Grid size and cube size grid_size := 100 cube_size: f32 = 1.0 // Create a 2D array to represent grid data grid: [500][500]bool // Initialize the grid with some colored cubes for y in 0..<grid_size { for x in 0..<grid_size { if rl.GetRandomValue(0, 100) > 50 { grid[y][x] = true } else { grid[y][x] = false } } } // Main game loop for !rl.WindowShouldClose() { // Update camera position (optional) camera3d.position.x += 0.1 camera3d.position.z += 0.1 // Begin drawing rl.BeginDrawing() defer rl.EndDrawing() // Clear the background color rl.ClearBackground(rl.Color{49, 44, 53, 255}) // Start 3D drawing mode rl.BeginMode3D(camera3d) { // Iterate over the grid to draw cubes for y in 0..<grid_size { for x in 0..<grid_size { // Calculate cube position in 3D space cube_pos: rl.Vector3 = rl.Vector3{ cast(f32) x, cast(f32) 0.0, cast(f32) y, } // Draw cubes based on the grid data if grid[y][x] { rl.DrawCube(cube_pos, cube_size, cube_size, cube_size, rl.RED) } else { rl.DrawCube(cube_pos, cube_size, cube_size, cube_size, rl.DARKGRAY) } // Optional: Draw cube wires rl.DrawCubeWires(cube_pos, cube_size, cube_size, cube_size, rl.BLACK) } } // Draw grid lines for better visualization // rl.DrawGrid(500, 1) } rl.EndMode3D() // Draw FPS on the screen rl.DrawFPS(10, 10) } }
Leave a Comment