diff options
author | Akshay <[email protected]> | 2021-04-08 13:03:13 +0100 |
---|---|---|
committer | Akshay <[email protected]> | 2021-04-08 13:03:13 +0100 |
commit | 7f054debdf43faa57799a319c4fe24ffcc2ec4b6 (patch) | |
tree | ff574d2f57c92e47387b8285342f77ae81e858ef | |
parent | 3f341d9faa6f777297e593e19bb13737a50cd031 (diff) |
fix iso grid scaling
-rw-r--r-- | src/grid.rs | 32 |
1 files 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 @@ | |||
3 | 3 | ||
4 | use sdl2::{pixels::Color, rect::Point, render::Canvas, video::Window}; | 4 | use sdl2::{pixels::Color, rect::Point, render::Canvas, video::Window}; |
5 | 5 | ||
6 | use crate::{ | 6 | use crate::{consts::colors::*, rect}; |
7 | consts::{colors::*, ANGLE}, | ||
8 | rect, | ||
9 | }; | ||
10 | 7 | ||
11 | #[derive(Debug, Copy, Clone)] | 8 | #[derive(Debug, Copy, Clone)] |
12 | pub enum GridKind { | 9 | pub enum GridKind { |
@@ -83,22 +80,23 @@ impl Grid { | |||
83 | canvas.draw_lines(&horizontals[..]).unwrap(); | 80 | canvas.draw_lines(&horizontals[..]).unwrap(); |
84 | } | 81 | } |
85 | GridKind::Isometric => { | 82 | GridKind::Isometric => { |
86 | // tan 26.525 ~= 0.5 | ||
87 | canvas.set_clip_rect(Some(rect!(x, y, width * cs, height * cs))); | 83 | canvas.set_clip_rect(Some(rect!(x, y, width * cs, height * cs))); |
88 | for i in (0..2 * height + width).step_by(4) { | 84 | for i in (0..2 * height + width).step_by(4) { |
89 | let begin = Point::from(((i * cs) as i32, 0i32)); | 85 | let begin = ((i * cs) as i32, 0i32); |
90 | let end = Point::from((0i32, ((i * cs) as f64 * 0.5).floor() as i32)); | 86 | let end = (0i32, (i * cs) as i32 / 2); |
91 | canvas.draw_line(*start + begin, *start + end).unwrap(); | 87 | canvas |
92 | } | 88 | .draw_line(*start + begin.into(), *start + end.into()) |
93 | for j in (0..height + width / 2).step_by(2) { | 89 | .unwrap(); |
94 | let idx = (j as i32 - (width as i32 / 2)) * cs as i32; | 90 | |
95 | let begin = Point::from((-100i32, idx)); | 91 | let begin_m = ((i as i32 - 2 * height as i32) * cs as i32, 0i32); |
96 | let end = Point::from(( | 92 | let end_m = ( |
97 | (width * cs) as i32, | 93 | (width * cs) as i32, |
98 | (idx as f64 + (width * cs) as f64 * ANGLE.to_radians().tan()).floor() | 94 | ((width + 2 * height - i) * cs) as i32 / 2, |
99 | as i32, | 95 | ); |
100 | )); | 96 | |
101 | canvas.draw_line(*start + begin, *start + end).unwrap(); | 97 | canvas |
98 | .draw_line(*start + begin_m.into(), *start + end_m.into()) | ||
99 | .unwrap(); | ||
102 | } | 100 | } |
103 | canvas.set_clip_rect(None); | 101 | canvas.set_clip_rect(None); |
104 | } | 102 | } |