use glam::{f32, i32, Mat3, Vec3}; #[derive(Copy, Clone, Debug, PartialEq)] pub struct Ray { pub pos: Vec3, pub dir: Vec3, } pub fn ray(pos: Vec3, dir: Vec3) -> Ray { Ray { pos, dir } } impl Ray { pub fn forward(&self, dist: f32) -> Ray { Ray { pos: self.pos + self.dir * dist, dir: self.dir, } } } impl std::ops::Mul for Mat3 { type Output = Ray; fn mul(self, rhs: Ray) -> Self::Output { Ray { pos: self * rhs.pos, dir: self * rhs.dir, } } } #[derive(Copy, Clone, Debug, PartialEq)] pub struct Location { /// Положение в основной СК pub pos: Vec3, /// Преобразование вектора из локальной ортонормированной в основную СК pub rot: Mat3, } #[derive(Copy, Clone, Debug)] pub struct Object { pub id: i32, pub loc: Location, pub r: f32, } #[derive(Copy, Clone, Debug)] pub struct Hit { pub distance: f32, pub id: i32, pub pos: Vec3, // положение в основной СК pub rel: Ray, // в локальной ортонормированной СК объекта } #[derive(Clone, Debug)] pub struct FlatTraceResult { pub end: Option, pub objects: Vec, }