crystal_ball/math/hit.rs
1use crate::math::{Point2, Point3, Vec3, Vec4};
2
3/// The intersection of a [`Ray`](crate::math::Ray) with an [`Object`](crate::shapes::Object).
4#[derive(Copy, Clone, Debug)]
5pub struct Hit {
6 /// The hit's position in world space.
7 pub position: Point3,
8 /// The hit's normal in world space.
9 pub normal: Vec3,
10 /// The hit's tangent in world space, if any.
11 pub tangent: Option<Vec4>,
12 /// The distance between the [`Ray`](crate::math::Ray)'s origin and the hit's position.
13 pub distance: f64,
14 /// The hit's UV coordinates on the [`Object`](crate::shapes::Object).
15 pub uv: Point2,
16}
17
18impl Hit {
19 /// Create a new [`Hit`].
20 pub fn new(
21 position: Point3,
22 normal: Vec3,
23 tangent: Option<Vec4>,
24 distance: f64,
25 uv: Point2,
26 ) -> Self {
27 Hit {
28 position,
29 normal,
30 tangent,
31 distance,
32 uv,
33 }
34 }
35}