Simplex noise for chunk

This commit is contained in:
oupson 2022-07-28 08:22:03 +02:00
parent c73f084c09
commit 931d5343ff
1 changed files with 31 additions and 5 deletions

View File

@ -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<const N: u32> {
@ -15,9 +15,14 @@ impl<const N: u32> World<N> {
}
}
pub struct Chunk<const N: u32>(f64, f64);
pub struct Chunk<'w, const N: u32> {
world: &'w World<N>,
x: f64,
y: f64,
z: f64,
}
impl<const N: u32> Chunk<N> {
impl<'w, const N: u32> Chunk<'w, N> {
pub fn view<I>(&self, image: &mut SubImage<I>)
where
I: DerefMut,
@ -25,7 +30,17 @@ impl<const N: u32> Chunk<N> {
{
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<const N: u32> Chunk<N> {
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));
}