use std::ops::{Deref, DerefMut, Range}; use evenio::component::Component; use nalgebra::{Rotation3, Vector3}; use ndarray::{Array3, ArrayBase, Dim, SliceArg}; use crate::client::render::voxel::VoxelColor; #[derive(Debug, Component, Default)] pub struct Pos(pub Vector3); #[derive(Debug, Component, Default)] pub struct Orientation(pub Rotation3); pub type VoxelGrid = TrackedGrid; pub type GridRegion = (Range, Range, Range); #[derive(Debug, Clone, Component)] pub struct TrackedGrid { data: Array3, changes: Vec, } impl TrackedGrid { pub fn new(data: Array3) -> Self { Self { data, changes: Vec::new(), } } pub fn view_slice_mut>>( &mut self, slice: I, ) -> ArrayBase, >>::OutDim> { self.data.slice_mut(slice) } pub fn take_changes(&mut self) -> Vec { std::mem::take(&mut self.changes) } } impl Pos { pub fn new(x: f32, y: f32, z: f32) -> Self { Self(Vector3::new(x, y, z)) } } impl Orientation { pub fn from_axis_angle>>( axis: &nalgebra::Unit, nalgebra::Const<1>, SB>>, angle: f32, ) -> Self { Self(Rotation3::from_axis_angle(axis, angle)) } } impl From> for Pos { fn from(val: Vector3) -> Self { Pos(val) } } impl From> for Orientation { fn from(val: Rotation3) -> Self { Orientation(val) } } // reref boilerplate :pensive: impl Deref for Pos { type Target = Vector3; fn deref(&self) -> &Self::Target { &self.0 } } impl DerefMut for Pos { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 } } impl Deref for Orientation { type Target = Rotation3; fn deref(&self) -> &Self::Target { &self.0 } } impl DerefMut for Orientation { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 } } impl Deref for TrackedGrid { type Target = Array3; fn deref(&self) -> &Self::Target { &self.data } }