Remove unused Chunk::raycast

This commit is contained in:
Sijmen 2021-06-01 16:00:03 +02:00
parent 6c6a321a0c
commit aec8d36647
Signed by: vijfhoek
GPG key ID: 82D05C89B28B0DAE

View file

@ -361,92 +361,4 @@ impl Chunk {
Self::quads_to_geometry(quads) Self::quads_to_geometry(quads)
} }
pub fn get_block(&self, x: usize, y: usize, z: usize) -> Option<&Block> {
if x >= CHUNK_SIZE || y >= CHUNK_SIZE || z >= CHUNK_SIZE {
return None;
}
self.blocks[y][z][x].as_ref()
}
fn calc_scale(vector: Vector3<f32>, scalar: f32) -> f32 {
if scalar == 0.0 {
f32::INFINITY
} else {
(vector / scalar).magnitude()
}
}
#[allow(dead_code)]
pub fn raycast(
&self,
chunk_position: Vector3<usize>,
origin: Vector3<f32>,
direction: Vector3<f32>,
) -> Option<(Vector3<usize>, Vector3<i32>)> {
let origin = origin - chunk_position.map(|x| (x * 16) as f32);
let scale = Vector3::new(
Self::calc_scale(direction, direction.x),
Self::calc_scale(direction, direction.y),
Self::calc_scale(direction, direction.z),
);
let direction = direction.normalize();
let mut position = origin.map(|x| x as i32);
let step = direction.map(|x| x.signum() as i32);
// Truncate the origin
let mut lengths = Vector3 {
x: if direction.x < 0.0 {
(origin.x - position.x as f32) * scale.x
} else {
(position.x as f32 + 1.0 - origin.x) * scale.x
},
y: if direction.y < 0.0 {
(origin.y - position.y as f32) * scale.y
} else {
(position.y as f32 + 1.0 - origin.y) * scale.y
},
z: if direction.z < 0.0 {
(origin.z - position.z as f32) * scale.z
} else {
(position.z as f32 + 1.0 - origin.z) * scale.z
},
};
let mut face;
while lengths.magnitude() < 100.0 {
if lengths.x <= lengths.y && lengths.x <= lengths.z {
lengths.x += scale.x;
position.x += step.x;
face = Vector3::unit_x() * step.x;
} else if lengths.y <= lengths.x && lengths.y <= lengths.z {
lengths.y += scale.y;
position.y += step.y;
face = Vector3::unit_y() * step.y;
} else if lengths.z <= lengths.x && lengths.z <= lengths.y {
lengths.z += scale.z;
position.z += step.z;
face = Vector3::unit_z() * step.z;
} else {
return None;
}
if self
.get_block(
position.x as usize,
position.y as usize,
position.z as usize,
)
.is_some()
{
// Intersection occurred
return Some((position.map(|x| x as usize), face));
}
}
None
}
} }