mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-25 15:33:44 +03:00
draw ped waiting for a turn
This commit is contained in:
parent
c7aced1112
commit
3941621127
@ -7,7 +7,6 @@
|
|||||||
- when parking is full or no parking at goal road, roam until parking is found
|
- when parking is full or no parking at goal road, roam until parking is found
|
||||||
|
|
||||||
- code cleanup
|
- code cleanup
|
||||||
- try to simplify straw_model step (less phases?)
|
|
||||||
- figure out responsibility btwn agents and managers, then fix up visibility
|
- figure out responsibility btwn agents and managers, then fix up visibility
|
||||||
- rng should live in a scenario spec layer, not in the sim itself
|
- rng should live in a scenario spec layer, not in the sim itself
|
||||||
|
|
||||||
@ -27,9 +26,9 @@
|
|||||||
|
|
||||||
## pedestrians
|
## pedestrians
|
||||||
|
|
||||||
- make them obey intersections (deterministically!)
|
|
||||||
- make them start and end at buildings
|
- make them start and end at buildings
|
||||||
- trim the sidewalk path to the edge of a building
|
- trim the sidewalk path to the edge of a building
|
||||||
|
- render overlapping peds reasonably
|
||||||
|
|
||||||
## General
|
## General
|
||||||
|
|
||||||
|
@ -1,28 +1,47 @@
|
|||||||
use ezgui::GfxCtx;
|
use ezgui::GfxCtx;
|
||||||
use geom::Pt2D;
|
use geom::Pt2D;
|
||||||
use graphics;
|
use graphics;
|
||||||
use map_model::geometry;
|
use map_model::{geometry, Turn};
|
||||||
use PedestrianID;
|
use PedestrianID;
|
||||||
|
|
||||||
const RADIUS: f64 = 1.0;
|
const RADIUS: f64 = 1.0;
|
||||||
|
|
||||||
// TODO should this live in editor/render?
|
// TODO should this live in editor/render?
|
||||||
// TODO show turns waited for
|
|
||||||
pub struct DrawPedestrian {
|
pub struct DrawPedestrian {
|
||||||
pub id: PedestrianID,
|
pub id: PedestrianID,
|
||||||
circle: [f64; 4],
|
circle: [f64; 4],
|
||||||
|
turn_arrow: Option<[f64; 4]>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DrawPedestrian {
|
impl DrawPedestrian {
|
||||||
pub fn new(id: PedestrianID, pos: Pt2D) -> DrawPedestrian {
|
pub fn new(id: PedestrianID, pos: Pt2D, waiting_for_turn: Option<&Turn>) -> DrawPedestrian {
|
||||||
|
let turn_arrow = if let Some(t) = waiting_for_turn {
|
||||||
|
// TODO this isn't quite right, but good enough for now
|
||||||
|
let angle = t.line.angle();
|
||||||
|
let arrow_pt = pos.project_away(RADIUS, angle.opposite());
|
||||||
|
Some([arrow_pt.x(), arrow_pt.y(), pos.x(), pos.y()])
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
DrawPedestrian {
|
DrawPedestrian {
|
||||||
id,
|
id,
|
||||||
circle: geometry::circle(pos.x(), pos.y(), RADIUS),
|
circle: geometry::circle(pos.x(), pos.y(), RADIUS),
|
||||||
|
turn_arrow,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw(&self, g: &mut GfxCtx, color: graphics::types::Color) {
|
pub fn draw(&self, g: &mut GfxCtx, color: graphics::types::Color) {
|
||||||
g.draw_ellipse(color, self.circle);
|
g.draw_ellipse(color, self.circle);
|
||||||
|
|
||||||
|
// TODO tune color, sizes
|
||||||
|
if let Some(a) = self.turn_arrow {
|
||||||
|
g.draw_arrow(
|
||||||
|
&graphics::Line::new_round([0.0, 1.0, 1.0, 1.0], 0.25),
|
||||||
|
a,
|
||||||
|
0.3,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn contains_pt(&self, x: f64, y: f64) -> bool {
|
pub fn contains_pt(&self, x: f64, y: f64) -> bool {
|
||||||
|
@ -289,7 +289,7 @@ impl Sim {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_draw_peds_on_lane(&self, l: LaneID, map: &Map) -> Vec<DrawPedestrian> {
|
pub fn get_draw_peds_on_lane(&self, l: LaneID, map: &Map) -> Vec<DrawPedestrian> {
|
||||||
self.walking_state.get_draw_peds_on_lane(map.get_l(l))
|
self.walking_state.get_draw_peds_on_lane(map.get_l(l), map)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_draw_peds_on_turn(&self, t: TurnID, map: &Map) -> Vec<DrawPedestrian> {
|
pub fn get_draw_peds_on_turn(&self, t: TurnID, map: &Map) -> Vec<DrawPedestrian> {
|
||||||
|
@ -239,15 +239,19 @@ impl WalkingSimState {
|
|||||||
Some(DrawPedestrian::new(
|
Some(DrawPedestrian::new(
|
||||||
id,
|
id,
|
||||||
ped.on.dist_along(ped.dist_along * si::M, map).0,
|
ped.on.dist_along(ped.dist_along * si::M, map).0,
|
||||||
|
// TODO this isnt correct, but works right now because this is only called by warp
|
||||||
|
None,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_draw_peds_on_lane(&self, l: &Lane) -> Vec<DrawPedestrian> {
|
pub fn get_draw_peds_on_lane(&self, l: &Lane, map: &Map) -> Vec<DrawPedestrian> {
|
||||||
let mut result = Vec::new();
|
let mut result = Vec::new();
|
||||||
for id in self.peds_per_sidewalk.get_vec(&l.id).unwrap_or(&Vec::new()) {
|
for id in self.peds_per_sidewalk.get_vec(&l.id).unwrap_or(&Vec::new()) {
|
||||||
|
let ped = &self.peds[id];
|
||||||
result.push(DrawPedestrian::new(
|
result.push(DrawPedestrian::new(
|
||||||
*id,
|
*id,
|
||||||
l.dist_along(self.peds[id].dist_along * si::M).0,
|
l.dist_along(ped.dist_along * si::M).0,
|
||||||
|
ped.waiting_for.map(|on| map.get_t(on.as_turn())),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
result
|
result
|
||||||
@ -259,6 +263,7 @@ impl WalkingSimState {
|
|||||||
result.push(DrawPedestrian::new(
|
result.push(DrawPedestrian::new(
|
||||||
*id,
|
*id,
|
||||||
t.dist_along(self.peds[id].dist_along * si::M).0,
|
t.dist_along(self.peds[id].dist_along * si::M).0,
|
||||||
|
None,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
result
|
result
|
||||||
|
Loading…
Reference in New Issue
Block a user