mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-25 07:25:47 +03:00
batching sidewalk lines. fix the very silly batching bug
This commit is contained in:
parent
9ac0674e62
commit
a065c63ad7
@ -143,21 +143,20 @@ fn calculate_sidewalk_lines(lane: &Lane) -> Marking {
|
||||
|
||||
let length = lane.length();
|
||||
|
||||
let mut lines = Vec::new();
|
||||
let mut draw = Vec::new();
|
||||
// Start away from the intersections
|
||||
let mut dist_along = tile_every;
|
||||
while dist_along < length - tile_every {
|
||||
let (pt, angle) = lane.dist_along(dist_along);
|
||||
// Reuse perp_line. Project away an arbitrary amount
|
||||
let pt2 = pt.project_away(1.0, angle);
|
||||
lines.push(perp_line(Line::new(pt, pt2), LANE_THICKNESS));
|
||||
draw.push(perp_line(Line::new(pt, pt2), LANE_THICKNESS).make_polygons(0.25));
|
||||
dist_along += tile_every;
|
||||
}
|
||||
|
||||
Box::new(move |g, cs| {
|
||||
for line in &lines {
|
||||
g.draw_line(cs.get_def("sidewalk lines", Color::grey(0.7)), 0.25, line);
|
||||
}
|
||||
let color = cs.get_def("sidewalk lines", Color::grey(0.7));
|
||||
g.draw_polygon_batch(draw.iter().map(|poly| (color, poly)).collect())
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -102,7 +102,7 @@ impl<'a> GfxCtx<'a> {
|
||||
// Use graphics::Line internally for now, but make it easy to switch to something else by
|
||||
// picking this API now.
|
||||
pub fn draw_line(&mut self, color: Color, thickness: f64, line: &Line) {
|
||||
self.draw_polygon(color, &line.to_polyline().make_polygons(thickness));
|
||||
self.draw_polygon(color, &line.make_polygons(thickness));
|
||||
}
|
||||
|
||||
pub fn draw_rounded_line(&mut self, color: Color, thickness: f64, line: &Line) {
|
||||
@ -110,7 +110,7 @@ impl<'a> GfxCtx<'a> {
|
||||
self.draw_circle(color, &Circle::new(line.pt1(), thickness / 2.0));
|
||||
self.draw_circle(color, &Circle::new(line.pt2(), thickness / 2.0));
|
||||
/*self.draw_polygon_batch(vec![
|
||||
(color, &line.to_polyline().make_polygons(thickness)),
|
||||
(color, &line.make_polygons(thickness)),
|
||||
(
|
||||
color,
|
||||
&Circle::new(line.pt1(), thickness / 2.0).to_polygon(TRIANGLES_PER_CIRCLE),
|
||||
@ -168,6 +168,7 @@ impl<'a> GfxCtx<'a> {
|
||||
let mut indices: Vec<u32> = Vec::new();
|
||||
|
||||
for (color, poly) in list {
|
||||
let idx_offset = vertices.len();
|
||||
let (pts, raw_indices) = poly.raw_for_rendering();
|
||||
for pt in pts {
|
||||
vertices.push(Vertex {
|
||||
@ -175,9 +176,8 @@ impl<'a> GfxCtx<'a> {
|
||||
color: color.0,
|
||||
});
|
||||
}
|
||||
let offset = indices.len();
|
||||
for idx in raw_indices {
|
||||
indices.push((offset + *idx) as u32);
|
||||
indices.push((idx_offset + *idx) as u32);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::{line_intersection, Angle, PolyLine, Pt2D, EPSILON_DIST};
|
||||
use crate::{line_intersection, Angle, PolyLine, Polygon, Pt2D, EPSILON_DIST};
|
||||
use dimensioned::si;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use std::fmt;
|
||||
@ -30,6 +30,10 @@ impl Line {
|
||||
PolyLine::new(self.points())
|
||||
}
|
||||
|
||||
pub fn make_polygons(&self, thickness: f64) -> Polygon {
|
||||
self.to_polyline().make_polygons(thickness)
|
||||
}
|
||||
|
||||
// TODO valid to do euclidean distance on world-space points that're formed from
|
||||
// Haversine?
|
||||
pub fn length(&self) -> si::Meter<f64> {
|
||||
|
Loading…
Reference in New Issue
Block a user