From 931d5343ff0ad628584bb362f5ff7631930f7929 Mon Sep 17 00:00:00 2001 From: oupson Date: Thu, 28 Jul 2022 08:22:03 +0200 Subject: [PATCH] Simplex noise for chunk --- src/main.rs | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index aafaafd..4a97432 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ -use std::ops::DerefMut; +use std::ops::{DerefMut, Deref}; -use image::{GenericImage, SubImage}; +use image::{GenericImage, ImageBuffer, SubImage, GenericImageView, RgbImage, Rgb, Pixel, Primitive}; use opensimplex_noise_rs::OpenSimplexNoise; pub struct World { @@ -15,9 +15,14 @@ impl World { } } -pub struct Chunk(f64, f64); +pub struct Chunk<'w, const N: u32> { + world: &'w World, + x: f64, + y: f64, + z: f64, +} -impl Chunk { +impl<'w, const N: u32> Chunk<'w, N> { pub fn view(&self, image: &mut SubImage) where I: DerefMut, @@ -25,7 +30,17 @@ impl Chunk { { for x in 0..N { for y in 0..N { - for z in (N - 1)..0 {} + for z in (0..(N - 1)).rev() { + let value = (self.world + .generator + .eval_3d(self.x + x as f64, self.y + y as f64, self.z + z as f64) + 1.0) * 50.0; + if value > 60.0 { + + + println!("{} {} {}", x, y, z); + break; + } + } } } } @@ -34,4 +49,15 @@ impl Chunk { fn main() { println!("Hello, world!"); let world = World::<16>::new(None); + + let chunk = Chunk { + world: &world, + x: 0.0, + y: 0.0, + z: 0.0, + }; + + let mut image : RgbImage = ImageBuffer::new(16, 16); + + chunk.view(&mut image.sub_image(0, 0, 16, 16)); }