Initial work on rollback and refactor

This commit is contained in:
2026-08-12 12:27:35 +02:00
parent ad6c1e17ac
commit a21f24b2d9
45 changed files with 1451 additions and 717 deletions
+34
View File
@@ -0,0 +1,34 @@
//! Stage collision geometry.
use bevy::{math::InvalidDirectionError, prelude::*};
use crate::math::SegmentIntersection;
#[derive(Component, Reflect, Clone, Default)]
#[reflect(Component)]
pub struct StageLine {
pub segment: Segment2d,
pub normal: Vec2,
}
pub struct StagePlaneIntersectResult {
pub position: Vec2,
}
impl StageLine {
pub fn new(start: Vec2, end: Vec2) -> Result<Self, InvalidDirectionError> {
let segment = Segment2d::new(start, end);
let normal = segment.left_normal().as_vec2();
Ok(Self { segment, normal })
}
pub fn intersect_ray(&self, segment: Segment2d) -> Option<StagePlaneIntersectResult> {
self.segment
.segment_intersection(&segment)
.map(|position| StagePlaneIntersectResult { position })
}
pub fn project(&self, vec: Vec2) -> Vec2 {
vec - vec.project_onto_normalized(self.normal)
}
}