use crate::{Vector3, Vector2};
#[derive(Debug)]
pub struct RaycastInfoBuilder {
point: Option<Vector3>,
normal: Option<Vector3>,
uv: Option<Vector2>,
distance: Option<f32>,
is_hit: bool,
}
impl RaycastInfoBuilder {
pub fn new() -> Self {
RaycastInfoBuilder { is_hit: false, point: None, normal: None, uv: None, distance: None }
}
}
impl RaycastInfoBuilder {
pub fn build(self) -> RaycastInfo {
RaycastInfo {
is_hit: self.is_hit,
point: self.point.unwrap_or(Vector3::zero()),
normal: self.normal.unwrap_or(Vector3::zero()),
uv: self.uv.unwrap_or(Vector2::zero()),
distance: self.distance.unwrap_or(0.0),
}
}
pub fn set_point(mut self, value: Vector3) -> Self {
self.point = Some(value);
return self;
}
pub fn set_normal(mut self, value: Vector3) -> Self {
self.normal = Some(value);
return self;
}
pub fn set_distance(mut self, value: f32) -> Self {
self.distance = Some(value);
return self;
}
pub fn set_hit(mut self, value: bool) -> Self {
self.is_hit = value;
return self;
}
}
#[derive(Debug)]
pub struct RaycastInfo {
point: Vector3,
normal: Vector3,
uv: Vector2,
distance: f32,
is_hit: bool,
}
impl RaycastInfo {
pub fn empty() -> Self {
RaycastInfo {
is_hit: false,
point: Vector3::zero(),
normal: Vector3::zero(),
uv: Vector2::zero(),
distance: 0.0
}
}
}
impl RaycastInfo {
pub fn point(&self) -> Vector3 { self.point }
pub fn normal(&self) -> Vector3 { self.normal }
pub fn uv(&self) -> Vector2 { self.uv }
pub fn distance(&self) -> f32 { self.distance }
pub fn is_hit(&self) -> bool { self.is_hit }
}