From b58c29c734978766db2c86acb436ca9425491b99 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Mon, 17 Oct 2022 16:57:07 +0200 Subject: naive renderer --- src/main.rs | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/main.rs b/src/main.rs index 609041b..5f4e621 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,7 +11,7 @@ use image::ImageBuffer; use log::debug; use std::{collections::HashMap, fs::File, path::Path}; -const SEG_SIZE: isize = 64; +const SEG_SIZE: isize = 128; fn main() { env_logger::builder() @@ -27,21 +27,25 @@ fn main() { for y in -64..256 { for z in 0..SEG_SIZE { let solid = |x: isize, y: isize, z: isize| { - if x >= 0 && z >= 0 && x < SEG_SIZE && z < SEG_SIZE && y >= -64 && y < 256 { - dim.block(x, y, z) - .map(|b| { - !matches!( - b.name(), - "minecraft:air" | "minecraft:water" | "minecraft:cave_air" - ) - }) - .unwrap_or(false) - } else { - false - } + dim.block(x, y, z) + .map(|b| { + !matches!( + b.name(), + "minecraft:air" | "minecraft:water" | "minecraft:cave_air" + ) + }) + .unwrap_or(false) }; let visible = |b: &Block| !matches!(b.name(), "minecraft:air" | "minecraft:cave_air"); + let ray_visible = || { + for i in 1..100 { + if solid(x - i, y + i, z - i) { + return false; + } + } + true + }; if visible(&dim.block(x, y, z).unwrap()) && !(solid(x + 1, y, z) @@ -50,6 +54,7 @@ fn main() { && solid(x, y - 1, z) && solid(x, y, z + 1) && solid(x, y, z - 1)) + && ray_visible() { visible_blocks.push((x, y, z)) } -- cgit v1.2.3-70-g09d2