first implementation, clamp seems to be off?

This commit is contained in:
zomseffen 2025-03-06 18:11:44 +01:00
parent 7a58ba9733
commit b581364f5a
8 changed files with 157 additions and 132 deletions
src/scene

View file

@ -27,6 +27,7 @@ pub struct OctTree<T> {
pub blocks: Vec<Option<T>>,
pub size: usize,
pub scale: f32,
}
#[warn(non_snake_case)]
@ -43,7 +44,7 @@ impl OctTree<Cube> {
}
impl<T: Clone> OctTree<T> {
pub fn create(size: usize) -> Result<Self> {
pub fn create(size: usize, scale: f32) -> Result<Self> {
let mut blocks: Vec<Option<T>> = vec![];
if size == MIN_CHUNK_SIZE {
for _ in 0..MIN_CHUNK_SIZE {
@ -68,6 +69,7 @@ impl<T: Clone> OctTree<T> {
blocks: blocks,
size,
scale,
})
}
@ -89,7 +91,7 @@ impl<T: Clone> OctTree<T> {
child.borrow_mut().set_element_internal(element, x - mid_point, y - mid_point, z - mid_point);
},
None => {
let mut child = OctTree::create(self.size / 2).unwrap();
let mut child = OctTree::create(self.size / 2, self.scale).unwrap();
child.set_element_internal(element, x - mid_point, y - mid_point, z - mid_point);
self.child_XYZ = Some(Rc::new(RefCell::new(child)));
}
@ -101,7 +103,7 @@ impl<T: Clone> OctTree<T> {
child.borrow_mut().set_element_internal(element, x - mid_point, y - mid_point, z);
},
None => {
let mut child = OctTree::create(self.size / 2).unwrap();
let mut child = OctTree::create(self.size / 2, self.scale).unwrap();
child.set_element_internal(element, x - mid_point, y - mid_point, z);
self.child_XYz = Some(Rc::new(RefCell::new(child)));
}
@ -115,7 +117,7 @@ impl<T: Clone> OctTree<T> {
child.borrow_mut().set_element_internal(element, x - mid_point, y, z - mid_point);
},
None => {
let mut child = OctTree::create(self.size / 2).unwrap();
let mut child = OctTree::create(self.size / 2, self.scale).unwrap();
child.set_element_internal(element, x - mid_point, y, z - mid_point);
self.child_XyZ = Some(Rc::new(RefCell::new(child)));
}
@ -127,7 +129,7 @@ impl<T: Clone> OctTree<T> {
child.borrow_mut().set_element_internal(element, x - mid_point, y, z);
},
None => {
let mut child = OctTree::create(self.size / 2).unwrap();
let mut child = OctTree::create(self.size / 2, self.scale).unwrap();
child.set_element_internal(element, x - mid_point, y, z);
self.child_Xyz = Some(Rc::new(RefCell::new(child)));
}
@ -143,7 +145,7 @@ impl<T: Clone> OctTree<T> {
child.borrow_mut().set_element_internal(element, x, y - mid_point, z - mid_point);
},
None => {
let mut child = OctTree::create(self.size / 2).unwrap();
let mut child = OctTree::create(self.size / 2, self.scale).unwrap();
child.set_element_internal(element, x, y - mid_point, z - mid_point);
self.child_xYZ = Some(Rc::new(RefCell::new(child)));
}
@ -155,7 +157,7 @@ impl<T: Clone> OctTree<T> {
child.borrow_mut().set_element_internal(element, x, y - mid_point, z);
},
None => {
let mut child = OctTree::create(self.size / 2).unwrap();
let mut child = OctTree::create(self.size / 2, self.scale).unwrap();
child.set_element_internal(element, x, y - mid_point, z);
self.child_xYz = Some(Rc::new(RefCell::new(child)));
}
@ -169,7 +171,7 @@ impl<T: Clone> OctTree<T> {
child.borrow_mut().set_element_internal(element, x, y, z - mid_point);
},
None => {
let mut child = OctTree::create(self.size / 2).unwrap();
let mut child = OctTree::create(self.size / 2, self.scale).unwrap();
child.set_element_internal(element, x, y, z - mid_point);
self.child_xyZ = Some(Rc::new(RefCell::new(child)));
}
@ -181,7 +183,7 @@ impl<T: Clone> OctTree<T> {
child.borrow_mut().set_element_internal(element, x, y, z);
},
None => {
let mut child = OctTree::create(self.size / 2).unwrap();
let mut child = OctTree::create(self.size / 2, self.scale).unwrap();
child.set_element_internal(element, x, y, z);
self.child_xyz = Some(Rc::new(RefCell::new(child)));
}
@ -600,7 +602,7 @@ mod test {
#[test]
fn test_oct_tree(){
let mut test_tree: OctTree<Cube> = OctTree::create(512).unwrap();
let mut test_tree: OctTree<Cube> = OctTree::create(512, 1.0).unwrap();
let test_cube = Cube{color: Vector3 { x: 1.0, y: 0.0, z: 0.0 }, pos: Vector3 { x: 5.0, y: 2.0, z: 10.0 }, tex_coord: Vector2{x: 0.0, y: 0.0}, transparent: false, roughness: 128};
test_tree.set_cube(test_cube.clone());