diff --git a/src/main.rs b/src/main.rs index 2e689ef..833b512 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +mod voxel; + use std::borrow::Cow; use winit::{ event::{Event, WindowEvent}, diff --git a/src/voxel.rs b/src/voxel.rs new file mode 100644 index 0000000..87b13b3 --- /dev/null +++ b/src/voxel.rs @@ -0,0 +1,40 @@ +#[derive(Clone, Copy)] +struct Voxel { + r: u8, + g: u8, + b: u8 +} + +const AIR_VOXEL: Voxel = Voxel { r: 0, g: 0, b: 0 }; + +struct VoxelMap { + data: Vec, + width: usize, + height: usize, + depth: usize +} + +impl VoxelMap { + fn new(width: usize, height: usize, depth: usize) -> Self { + Self { + data: vec![AIR_VOXEL, width * height * depth], + width, + height, + depth + } + } + + fn set(&mut self, x: usize, y: usize, z: usize, voxel: Voxel) { + if x < self.width && y < self.height && z < self.depth { + self.data[x + y * self.width + z * self.width * self.height] = voxel; + } + } + + fn get(&self, x: usize, y: usize, z: usize) -> Voxel { + if x < self.width && y < self.height && z < self.depth { + self.data[x + y * self.width + z * self.width * self.height] + } else { + AIR_VOXEL + } + } +}