mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-25 15:33:44 +03:00
preupload pedestrian geometry
This commit is contained in:
parent
8a7413ac68
commit
d08751fb64
@ -1,7 +1,7 @@
|
||||
use crate::colors::ColorScheme;
|
||||
use crate::objects::{Ctx, ID};
|
||||
use crate::render::{RenderOptions, Renderable};
|
||||
use ezgui::{Color, GfxCtx, Prerender};
|
||||
use ezgui::{Color, Drawable, GfxCtx, Prerender};
|
||||
use geom::{Bounds, Circle, Distance, Line, Pt2D};
|
||||
use map_model::Map;
|
||||
use sim::{DrawPedestrianInput, PedestrianID};
|
||||
@ -12,21 +12,18 @@ pub struct DrawPedestrian {
|
||||
pub id: PedestrianID,
|
||||
circle: Circle,
|
||||
turn_arrow: Option<Line>,
|
||||
preparing_bike: bool,
|
||||
zorder: isize,
|
||||
|
||||
draw_default: Drawable,
|
||||
}
|
||||
|
||||
impl DrawPedestrian {
|
||||
pub fn new_new(
|
||||
pub fn new(
|
||||
input: DrawPedestrianInput,
|
||||
map: &Map,
|
||||
_prerender: &Prerender,
|
||||
_cs: &ColorScheme,
|
||||
prerender: &Prerender,
|
||||
cs: &ColorScheme,
|
||||
) -> DrawPedestrian {
|
||||
DrawPedestrian::new(input, map)
|
||||
}
|
||||
|
||||
pub fn new(input: DrawPedestrianInput, map: &Map) -> DrawPedestrian {
|
||||
let turn_arrow = if let Some(t) = input.waiting_for_turn {
|
||||
// TODO this isn't quite right, but good enough for now
|
||||
let angle = map.get_t(t).angle();
|
||||
@ -36,12 +33,25 @@ impl DrawPedestrian {
|
||||
None
|
||||
};
|
||||
|
||||
let circle = Circle::new(input.pos, RADIUS);
|
||||
|
||||
let draw_default = prerender.upload(vec![(
|
||||
if input.preparing_bike {
|
||||
cs.get_def("pedestrian preparing bike", Color::rgb(255, 0, 144))
|
||||
.shift(input.id.0)
|
||||
} else {
|
||||
cs.get_def("pedestrian", Color::rgb_f(0.2, 0.7, 0.7))
|
||||
.shift(input.id.0)
|
||||
},
|
||||
circle.to_polygon(),
|
||||
)]);
|
||||
|
||||
DrawPedestrian {
|
||||
id: input.id,
|
||||
circle: Circle::new(input.pos, RADIUS),
|
||||
circle,
|
||||
turn_arrow,
|
||||
preparing_bike: input.preparing_bike,
|
||||
zorder: input.on.get_zorder(map),
|
||||
draw_default,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -52,18 +62,11 @@ impl Renderable for DrawPedestrian {
|
||||
}
|
||||
|
||||
fn draw(&self, g: &mut GfxCtx, opts: RenderOptions, ctx: &Ctx) {
|
||||
let color = opts.color.unwrap_or_else(|| {
|
||||
if self.preparing_bike {
|
||||
ctx.cs
|
||||
.get_def("pedestrian preparing bike", Color::rgb(255, 0, 144))
|
||||
.shift(self.id.0)
|
||||
} else {
|
||||
ctx.cs
|
||||
.get_def("pedestrian", Color::rgb_f(0.2, 0.7, 0.7))
|
||||
.shift(self.id.0)
|
||||
}
|
||||
});
|
||||
if let Some(color) = opts.color {
|
||||
g.draw_circle(color, &self.circle);
|
||||
} else {
|
||||
g.redraw(&self.draw_default);
|
||||
}
|
||||
|
||||
// TODO tune color, sizes
|
||||
if let Some(ref a) = self.turn_arrow {
|
||||
|
@ -470,9 +470,7 @@ impl<S: UIState> UI<S> {
|
||||
list.push(new_draw_vehicle(c, map, prerender, &state.cs));
|
||||
}
|
||||
for p in sim.get_draw_peds(*on, map).into_iter() {
|
||||
list.push(Box::new(DrawPedestrian::new_new(
|
||||
p, map, prerender, &state.cs,
|
||||
)));
|
||||
list.push(Box::new(DrawPedestrian::new(p, map, prerender, &state.cs)));
|
||||
}
|
||||
agents.put(tick, *on, list);
|
||||
}
|
||||
|
@ -5,8 +5,6 @@ use crate::{
|
||||
use geom::{Bounds, Circle, Distance, Line, Polygon, Pt2D};
|
||||
use glium::{uniform, Surface};
|
||||
|
||||
const TRIANGLES_PER_CIRCLE: usize = 60;
|
||||
|
||||
type Uniforms<'a> = glium::uniforms::UniformsStorage<
|
||||
'a,
|
||||
[f32; 2],
|
||||
@ -107,11 +105,11 @@ impl<'a> GfxCtx<'a> {
|
||||
(color, &line.make_polygons(thickness)),
|
||||
(
|
||||
color,
|
||||
&Circle::new(line.pt1(), thickness / 2.0).to_polygon(TRIANGLES_PER_CIRCLE),
|
||||
&Circle::new(line.pt1(), thickness / 2.0).to_polygon(),
|
||||
),
|
||||
(
|
||||
color,
|
||||
&Circle::new(line.pt2(), thickness / 2.0).to_polygon(TRIANGLES_PER_CIRCLE),
|
||||
&Circle::new(line.pt2(), thickness / 2.0).to_polygon(),
|
||||
),
|
||||
]);
|
||||
}
|
||||
@ -122,7 +120,7 @@ impl<'a> GfxCtx<'a> {
|
||||
}
|
||||
|
||||
pub fn draw_circle(&mut self, color: Color, circle: &Circle) {
|
||||
self.draw_polygon(color, &circle.to_polygon(TRIANGLES_PER_CIRCLE));
|
||||
self.draw_polygon(color, &circle.to_polygon());
|
||||
}
|
||||
|
||||
pub fn draw_polygon(&mut self, color: Color, poly: &Polygon) {
|
||||
|
@ -2,6 +2,8 @@ use crate::{Angle, Bounds, Distance, Polygon, Pt2D};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use std::fmt;
|
||||
|
||||
const TRIANGLES_PER_CIRCLE: usize = 60;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct Circle {
|
||||
pub center: Pt2D,
|
||||
@ -28,17 +30,17 @@ impl Circle {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_polygon(&self, num_triangles: usize) -> Polygon {
|
||||
pub fn to_polygon(&self) -> Polygon {
|
||||
let mut pts = vec![self.center];
|
||||
let mut indices = Vec::new();
|
||||
for i in 0..num_triangles {
|
||||
for i in 0..TRIANGLES_PER_CIRCLE {
|
||||
pts.push(self.center.project_away(
|
||||
self.radius,
|
||||
Angle::new_degs((i as f64) / (num_triangles as f64) * 360.0),
|
||||
Angle::new_degs((i as f64) / (TRIANGLES_PER_CIRCLE as f64) * 360.0),
|
||||
));
|
||||
indices.push(0);
|
||||
indices.push(i + 1);
|
||||
if i != num_triangles - 1 {
|
||||
if i != TRIANGLES_PER_CIRCLE - 1 {
|
||||
indices.push(i + 2);
|
||||
} else {
|
||||
indices.push(1);
|
||||
|
Loading…
Reference in New Issue
Block a user