From 456236678180ac084f4a11fb08aba53edf20eb88 Mon Sep 17 00:00:00 2001 From: Astie Teddy Date: Sat, 5 Sep 2020 16:16:15 +0200 Subject: [PATCH] Add models_waving_cubes example. --- examples/models_waving_cubes.lua | 69 ++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 examples/models_waving_cubes.lua diff --git a/examples/models_waving_cubes.lua b/examples/models_waving_cubes.lua new file mode 100644 index 0000000..eedcca1 --- /dev/null +++ b/examples/models_waving_cubes.lua @@ -0,0 +1,69 @@ +--[[ + Contributed by Codecat (@codecat) + Reviewed by Ramon Santamaria (@raysan5) + + Modified by Teddy Astie (@TSnake41) for Lua binding. +]] + +local width, height = 800, 450 + +rl.SetConfigFlags(rl.FLAG_VSYNC_HINT) + +rl.InitWindow(width, height, "raylib [models] example - waving cubes") + +local camera = rl.new("Camera3D", { + position = { 30, 20, 30 }, + target = { 0, 0, 0 }, + up = { 0, 1, 0 }, + fovy = 70, + type = rl.CAMERA_PERSPECTIVE +}) + +local num_blocks = 15 + +while not rl.WindowShouldClose() do + local time = rl.GetTime() + + local scale = (2.0 + math.sin(time)) * 0.7 + local camera_time = time * 0.3 + + camera.position.x = math.cos(camera_time) * 40.0 + camera.position.z = math.sin(camera_time) * 40.0 + + rl.BeginDrawing() + rl.ClearBackground(rl.RAYWHITE) + + rl.BeginMode3D(camera) + rl.DrawGrid(10, 5.0) + + for x=0,num_blocks-1 do + for y=0,num_blocks-1 do + for z=0,num_blocks-1 do + local block_scale = (x + y + z) / 30 + local scatter = math.sin(block_scale * 20.0 + time * 4.0) + + local cube_pos = rl.new("Vector3", + (x - num_blocks / 2) * (scale * 3.0) + scatter, + (y - num_blocks / 2) * (scale * 2.0) + scatter, + (z - num_blocks / 2) * (scale * 3.0) + scatter) + + local cube_color = rl.ColorFromHSV( + rl.new("Vector3", + (((x + y + z) * 18) % 360), 0.75, 0.9 + ) + ) + + local cube_size = (2.4 - scale) * block_scale + + rl.DrawCube(cube_pos, cube_size, cube_size, cube_size, cube_color) + end + end + end + + rl.EndMode3D() + rl.DrawFPS(10, 10) + + rl.EndDrawing() +end + +rl.CloseWindow()