mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-27 16:36:02 +03:00
a start to drawing bikes with more personality
This commit is contained in:
parent
b0ca4429ad
commit
c034040b27
@ -1,15 +1,13 @@
|
||||
use crate::helpers::{ColorScheme, ID};
|
||||
use crate::render::{DrawCtx, DrawOptions, Renderable};
|
||||
use ezgui::{Color, Drawable, GfxCtx, Prerender};
|
||||
use geom::{Distance, Polygon};
|
||||
use map_model::Map;
|
||||
use geom::{Circle, Distance, Line, Polygon};
|
||||
use map_model::{Map, LANE_THICKNESS};
|
||||
use sim::{CarID, CarStatus, DrawCarInput};
|
||||
|
||||
const BIKE_WIDTH: Distance = Distance::const_meters(0.8);
|
||||
|
||||
pub struct DrawBike {
|
||||
pub id: CarID,
|
||||
polygon: Polygon,
|
||||
body_circle: Circle,
|
||||
// TODO the turn arrows for bikes look way wrong
|
||||
zorder: isize,
|
||||
|
||||
@ -23,25 +21,49 @@ impl DrawBike {
|
||||
prerender: &Prerender,
|
||||
cs: &ColorScheme,
|
||||
) -> DrawBike {
|
||||
let polygon = input.body.make_polygons(BIKE_WIDTH);
|
||||
let mut draw_default = Vec::new();
|
||||
|
||||
let draw_default = prerender.upload_borrowed(vec![(
|
||||
match input.status {
|
||||
// TODO color.shift(input.id.0) actually looks pretty bad still
|
||||
CarStatus::Debug => cs.get_def("debug bike", Color::BLUE.alpha(0.8)),
|
||||
// TODO Hard to see on the greenish bike lanes? :P
|
||||
CarStatus::Moving => cs.get_def("moving bike", Color::GREEN),
|
||||
CarStatus::Stuck => cs.get_def("stuck bike", Color::RED),
|
||||
CarStatus::Parked => panic!("Can't have a parked bike {}", input.id),
|
||||
},
|
||||
&polygon,
|
||||
)]);
|
||||
// TODO Share constants with DrawPedestrian
|
||||
let body_radius = LANE_THICKNESS / 4.0;
|
||||
let body_color = match input.status {
|
||||
// TODO color.shift(input.id.0) actually looks pretty bad still
|
||||
CarStatus::Debug => cs.get_def("debug bike", Color::BLUE.alpha(0.8)),
|
||||
// TODO Hard to see on the greenish bike lanes? :P
|
||||
CarStatus::Moving => cs.get_def("moving bike", Color::GREEN),
|
||||
CarStatus::Stuck => cs.get_def("stuck bike", Color::RED),
|
||||
CarStatus::Parked => panic!("Can't have a parked bike {}", input.id),
|
||||
};
|
||||
|
||||
draw_default.push((
|
||||
cs.get_def("bike frame", Color::grey(0.6)),
|
||||
input.body.make_polygons(Distance::meters(0.4)),
|
||||
));
|
||||
{
|
||||
// Handlebars
|
||||
let (pos, angle) = input.body.dist_along(0.9 * input.body.length());
|
||||
draw_default.push((
|
||||
cs.get("bike frame"),
|
||||
Line::new(
|
||||
pos.project_away(body_radius, angle.rotate_degs(90.0)),
|
||||
pos.project_away(body_radius, angle.rotate_degs(-90.0)),
|
||||
)
|
||||
.make_polygons(Distance::meters(0.1)),
|
||||
));
|
||||
}
|
||||
|
||||
let (pos, facing) = input.body.dist_along(0.4 * input.body.length());
|
||||
let body_circle = Circle::new(pos, body_radius);
|
||||
draw_default.push((body_color, body_circle.to_polygon()));
|
||||
draw_default.push((
|
||||
cs.get("pedestrian head"),
|
||||
Circle::new(pos, 0.5 * body_radius).to_polygon(),
|
||||
));
|
||||
|
||||
DrawBike {
|
||||
id: input.id,
|
||||
polygon,
|
||||
body_circle,
|
||||
zorder: input.on.get_zorder(map),
|
||||
draw_default,
|
||||
draw_default: prerender.upload(draw_default),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -53,14 +75,14 @@ impl Renderable for DrawBike {
|
||||
|
||||
fn draw(&self, g: &mut GfxCtx, opts: &DrawOptions, _: &DrawCtx) {
|
||||
if let Some(color) = opts.color(self.get_id()) {
|
||||
g.draw_polygon(color, &self.polygon);
|
||||
g.draw_circle(color, &self.body_circle);
|
||||
} else {
|
||||
g.redraw(&self.draw_default);
|
||||
}
|
||||
}
|
||||
|
||||
fn get_outline(&self, _: &Map) -> Polygon {
|
||||
self.polygon.clone()
|
||||
self.body_circle.to_polygon()
|
||||
}
|
||||
|
||||
fn get_zorder(&self) -> isize {
|
||||
|
@ -7,7 +7,7 @@ use sim::{DrawPedestrianInput, PedestrianID};
|
||||
|
||||
pub struct DrawPedestrian {
|
||||
pub id: PedestrianID,
|
||||
circle: Circle,
|
||||
body_circle: Circle,
|
||||
turn_arrow: Option<Vec<Polygon>>,
|
||||
zorder: isize,
|
||||
|
||||
@ -86,7 +86,7 @@ impl DrawPedestrian {
|
||||
|
||||
DrawPedestrian {
|
||||
id: input.id,
|
||||
circle: body_circle,
|
||||
body_circle,
|
||||
turn_arrow,
|
||||
zorder: input.on.get_zorder(map),
|
||||
draw_default: prerender.upload(draw_default),
|
||||
@ -101,7 +101,7 @@ impl Renderable for DrawPedestrian {
|
||||
|
||||
fn draw(&self, g: &mut GfxCtx, opts: &DrawOptions, ctx: &DrawCtx) {
|
||||
if let Some(color) = opts.color(self.get_id()) {
|
||||
g.draw_circle(color, &self.circle);
|
||||
g.draw_circle(color, &self.body_circle);
|
||||
} else {
|
||||
g.redraw(&self.draw_default);
|
||||
}
|
||||
@ -114,7 +114,7 @@ impl Renderable for DrawPedestrian {
|
||||
}
|
||||
|
||||
fn get_outline(&self, _: &Map) -> Polygon {
|
||||
self.circle.to_polygon()
|
||||
self.body_circle.to_polygon()
|
||||
}
|
||||
|
||||
fn get_zorder(&self) -> isize {
|
||||
|
Loading…
Reference in New Issue
Block a user