Use the WQuadtree for the exhaustive ray-cast too.
This commit is contained in:
@@ -309,11 +309,9 @@ impl<T: IndexedData> WQuadtree<T> {
|
|||||||
|
|
||||||
// FIXME: implement a visitor pattern to merge intersect_aabb
|
// FIXME: implement a visitor pattern to merge intersect_aabb
|
||||||
// and intersect_ray into a single method.
|
// and intersect_ray into a single method.
|
||||||
pub fn intersect_aabb(&self, aabb: &AABB) -> Vec<T> {
|
pub fn intersect_aabb(&self, aabb: &AABB, out: &mut Vec<T>) {
|
||||||
let mut res = Vec::new();
|
|
||||||
|
|
||||||
if self.nodes.is_empty() {
|
if self.nodes.is_empty() {
|
||||||
return res;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Special case for the root.
|
// Special case for the root.
|
||||||
@@ -330,7 +328,7 @@ impl<T: IndexedData> WQuadtree<T> {
|
|||||||
// We found a leaf!
|
// We found a leaf!
|
||||||
// Unfortunately, invalid AABBs return a intersection as well.
|
// Unfortunately, invalid AABBs return a intersection as well.
|
||||||
if let Some(proxy) = self.proxies.get(node.children[ii] as usize) {
|
if let Some(proxy) = self.proxies.get(node.children[ii] as usize) {
|
||||||
res.push(proxy.data);
|
out.push(proxy.data);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Internal node, visit the child.
|
// Internal node, visit the child.
|
||||||
@@ -343,15 +341,11 @@ impl<T: IndexedData> WQuadtree<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
res
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cast_ray(&self, ray: &Ray, max_toi: f32) -> Vec<T> {
|
pub fn cast_ray(&self, ray: &Ray, max_toi: f32, out: &mut Vec<T>) {
|
||||||
let mut res = Vec::new();
|
|
||||||
|
|
||||||
if self.nodes.is_empty() {
|
if self.nodes.is_empty() {
|
||||||
return res;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Special case for the root.
|
// Special case for the root.
|
||||||
@@ -369,7 +363,7 @@ impl<T: IndexedData> WQuadtree<T> {
|
|||||||
// We found a leaf!
|
// We found a leaf!
|
||||||
// Unfortunately, invalid AABBs return a hit as well.
|
// Unfortunately, invalid AABBs return a hit as well.
|
||||||
if let Some(proxy) = self.proxies.get(node.children[ii] as usize) {
|
if let Some(proxy) = self.proxies.get(node.children[ii] as usize) {
|
||||||
res.push(proxy.data);
|
out.push(proxy.data);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Internal node, visit the child.
|
// Internal node, visit the child.
|
||||||
@@ -382,8 +376,6 @@ impl<T: IndexedData> WQuadtree<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
res
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user