switch to new polygons for cars. seems to work.

This commit is contained in:
Dustin Carlino 2018-06-25 13:51:54 -07:00
parent 7c747ea9ee
commit 94e8f7a4bf
4 changed files with 22 additions and 7 deletions

View File

@ -100,6 +100,7 @@ wait slow down even more -- before any of this change, lanes on adjacent roads s
- CLEANUP: bldg front path should happen upfront, not in render
- figure out why new polygons dont work for roads
- rm old thick line
- rm old lane center lines, switch to pts

View File

@ -114,12 +114,12 @@ pub fn thick_line_from_angle(
line_length: f64,
pt: &Pt2D,
angle: angles::Radian<f64>,
) -> Vec<Vec2d> {
) -> Vec<Vec<Vec2d>> {
let pt2 = Pt2D::new(
pt.x() + line_length * angle.value_unsafe.cos(),
pt.y() + line_length * angle.value_unsafe.sin(),
);
thick_line(&ThickLine::Centered(thickness), &pt, &pt2)
polyline::polygons_for_polyline(&vec![*pt, pt2], thickness)
}
pub fn shift_line_perpendicularly_in_driving_direction(

View File

@ -26,12 +26,19 @@ pub fn polygons_for_polyline(center_pts: &Vec<Pt2D>, width: f64) -> Vec<Vec<Vec2
let mut result: Vec<Vec<Pt2D>> = Vec::new();
for high_idx in 1..center_pts.len() {
// Duplicate first point, since that's what graphics layer expects
result.push(vec![
side1[high_idx],
side1[high_idx - 1],
side2[high_idx - 1],
side1[high_idx],
]);
result.push(vec![
side2[high_idx],
side2[high_idx - 1],
side1[high_idx],
side2[high_idx],
]);
result.push(vec![side2[high_idx], side2[high_idx - 1], side1[high_idx]]);
}
result
.iter()

View File

@ -27,7 +27,7 @@ const CAR_LENGTH: f64 = 4.5;
// TODO move this out
pub struct DrawCar {
pub id: CarID,
quad: Vec<Vec2d>,
polygons: Vec<Vec<Vec2d>>,
front: Pt2D,
// TODO ideally, draw the turn icon inside the car quad. how can we do that easily?
turn_arrow: Option<[f64; 4]>,
@ -42,7 +42,7 @@ impl DrawCar {
turn_arrow: None,
// TODO the rounded corners from graphics::Line::new_round look kind of cool though
// add PI because we want to find the back of the car relative to the front
quad: geometry::thick_line_from_angle(
polygons: geometry::thick_line_from_angle(
CAR_WIDTH,
CAR_LENGTH,
front,
@ -53,7 +53,9 @@ impl DrawCar {
pub fn draw(&self, g: &mut GfxCtx, color: graphics::types::Color) {
let poly = graphics::Polygon::new(color);
poly.draw(&self.quad, &g.ctx.draw_state, g.ctx.transform, g.gfx);
for p in &self.polygons {
poly.draw(p, &g.ctx.draw_state, g.ctx.transform, g.gfx);
}
// TODO tune color, sizes
if let Some(a) = self.turn_arrow {
let turn_line = graphics::Line::new_round([0.0, 1.0, 1.0, 1.0], 0.25);
@ -62,7 +64,12 @@ impl DrawCar {
}
pub fn contains_pt(&self, x: f64, y: f64) -> bool {
geometry::point_in_polygon(x, y, &self.quad)
for p in &self.polygons {
if geometry::point_in_polygon(x, y, p) {
return true;
}
}
false
}
}