[−][src]Trait broccoli::query::raycast::RaycastQuery
Raycast functions that can be called on a tree.
Provided methods
pub fn raycast_mut<'b, R: RayCast<T = Self::T, N = Self::Num>>(
&'b mut self,
ray: Ray<Self::Num>,
rtrait: &mut R
) -> CastResult<CastAnswer<'b, Self::T>> where
'a: 'b,
[src]
&'b mut self,
ray: Ray<Self::Num>,
rtrait: &mut R
) -> CastResult<CastAnswer<'b, Self::T>> where
'a: 'b,
Find the elements that are hit by a ray.
The result is returned as a Vec
. In the event of a tie, multiple
elements can be returned.
Examples
use broccoli::{prelude::*,bbox,rect}; use axgeom::{vec2,ray}; let mut bots = [bbox(rect(0,10,0,10),vec2(5,5)), bbox(rect(2,5,2,5),vec2(4,4)), bbox(rect(4,10,4,10),vec2(5,5))]; let mut bots_copy=bots.clone(); let mut tree = broccoli::new(&mut bots); let ray=ray(vec2(5,-5),vec2(1,2)); let mut handler = broccoli::query::raycast::from_closure( &tree, (), |_, _, _| None, |_, ray, a| ray.cast_to_rect(&a.rect), |_, ray, val| ray.cast_to_aaline(axgeom::XAXIS, val), |_, ray, val| ray.cast_to_aaline(axgeom::YAXIS, val), ); let res = tree.raycast_mut( ray, &mut handler); let res=res.unwrap(); assert_eq!(res.mag,2); assert_eq!(res.elems.len(),1); assert_eq!(res.elems[0].inner,vec2(5,5));