From 7f054debdf43faa57799a319c4fe24ffcc2ec4b6 Mon Sep 17 00:00:00 2001 From: Akshay Date: Thu, 8 Apr 2021 17:33:13 +0530 Subject: fix iso grid scaling --- src/grid.rs | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/src/grid.rs b/src/grid.rs index 38efaba..029a196 100644 --- a/src/grid.rs +++ b/src/grid.rs @@ -3,10 +3,7 @@ use sdl2::{pixels::Color, rect::Point, render::Canvas, video::Window}; -use crate::{ - consts::{colors::*, ANGLE}, - rect, -}; +use crate::{consts::colors::*, rect}; #[derive(Debug, Copy, Clone)] pub enum GridKind { @@ -83,22 +80,23 @@ impl Grid { canvas.draw_lines(&horizontals[..]).unwrap(); } GridKind::Isometric => { - // tan 26.525 ~= 0.5 canvas.set_clip_rect(Some(rect!(x, y, width * cs, height * cs))); for i in (0..2 * height + width).step_by(4) { - let begin = Point::from(((i * cs) as i32, 0i32)); - let end = Point::from((0i32, ((i * cs) as f64 * 0.5).floor() as i32)); - canvas.draw_line(*start + begin, *start + end).unwrap(); - } - for j in (0..height + width / 2).step_by(2) { - let idx = (j as i32 - (width as i32 / 2)) * cs as i32; - let begin = Point::from((-100i32, idx)); - let end = Point::from(( + let begin = ((i * cs) as i32, 0i32); + let end = (0i32, (i * cs) as i32 / 2); + canvas + .draw_line(*start + begin.into(), *start + end.into()) + .unwrap(); + + let begin_m = ((i as i32 - 2 * height as i32) * cs as i32, 0i32); + let end_m = ( (width * cs) as i32, - (idx as f64 + (width * cs) as f64 * ANGLE.to_radians().tan()).floor() - as i32, - )); - canvas.draw_line(*start + begin, *start + end).unwrap(); + ((width + 2 * height - i) * cs) as i32 / 2, + ); + + canvas + .draw_line(*start + begin_m.into(), *start + end_m.into()) + .unwrap(); } canvas.set_clip_rect(None); } -- cgit v1.2.3