X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fcore%2Flevel%2Fmod.rs;h=bdc6cb0e292bad415ad694d05fcc8eaf3c61391b;hb=b1075e661c2ce2f107350b8d4f5f9a92e047b93e;hp=4d828dec04321cd635b4d72c82c203321ed3a56e;hpb=2e679e6fb2c1a93d1cb9b6cd66d19f6239953394;p=kaka%2Frust-sdl-test.git diff --git a/src/core/level/mod.rs b/src/core/level/mod.rs index 4d828de..bdc6cb0 100644 --- a/src/core/level/mod.rs +++ b/src/core/level/mod.rs @@ -135,11 +135,13 @@ impl Level { for c in self.wall_grid.grid_coordinates_on_line(p1, p2) { for w in &self.wall_grid.cells[c.x][c.y] { if let Intersection::Point(p) = Intersection::lines(p1, p2, w.p1, w.p2) { - let wall = Wall { - region: Rc::clone(&self.walls[w.region]), - edge: Rc::clone(w), - }; - return IntersectResult::Intersection(wall, p) + if w.point_is_in_front(p1) { + let wall = Wall { + region: Rc::clone(&self.walls[w.region]), + edge: Rc::clone(w), + }; + return IntersectResult::Intersection(wall, p) + } } } } @@ -243,6 +245,13 @@ struct WallEdge { pub p2: Point, } +impl WallEdge { + fn point_is_in_front(&self, p: Point) -> bool { + let cross = (self.p2 - self.p1).cross_product(p - self.p1); + cross > 0.0 + } +} + ////////// WALL //////////////////////////////////////////////////////////////// pub struct Wall {