refraction/src/types.rs
2024-11-07 01:39:29 +03:00

61 lines
1.2 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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<Ray> 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<Ray>,
pub objects: Vec<Hit>,
}