Skip to content

Commit

Permalink
Tried getting scissoring to work.
Browse files Browse the repository at this point in the history
  • Loading branch information
Yatekii committed Jul 28, 2019
1 parent 69343e2 commit e1db24f
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 12 deletions.
60 changes: 55 additions & 5 deletions src/drawing/painter.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
use nalgebra_glm::{
vec4,
vec2,
};
use crate::drawing::layer_collection::LayerCollection;
use crate::vector_tile::math::Screen;
use wgpu::TextureView;
Expand Down Expand Up @@ -747,15 +751,61 @@ impl Painter {
});
render_pass.set_pipeline(&self.blend_pipeline);
render_pass.set_bind_group(0, &self.bind_group, &[]);
let tile_size = app_state.screen.get_tile_size() as f32;
let vec = vec4(0.0, 0.0, 0.0, 1.0);
let screen_dimensions = vec2(app_state.screen.width as f32, app_state.screen.height as f32) / 2.0;
for feature in layer_collection.iter_features() {
render_pass.set_stencil_reference(feature.id as u32);
for (i, drawable_tile) in self.loaded_tiles.values_mut().enumerate() {
drawable_tile.paint(&mut render_pass, &layer_collection, i as u32, feature.id, false);
println!("start ================================");
for (i, dt) in self.loaded_tiles.values_mut().enumerate() {
let matrix = app_state.screen.tile_to_global_space(
app_state.zoom,
&dt.tile_id
);
let start = (matrix * &vec);
dbg!(start);
let s = vec2({
let x = (start.x * screen_dimensions.x).round();
if x < 0.0 { 0.0 } else { x }
}, {
let y = (start.y * screen_dimensions.y).round();
if y < 0.0 { 0.0 } else { y }
});
dbg!(s);
let matrix = app_state.screen.tile_to_global_space(
app_state.zoom,
&(dt.tile_id + TileId::new(dt.tile_id.z, 1, 1))
);
let end = (matrix * &vec);
dbg!(end);
let e = vec2({
let x = (end.x * screen_dimensions.x).round();
if x < 0.0 { 0.0 } else { x }
}, {
let y = (end.y * screen_dimensions.y).round();
if y < 0.0 { 0.0 } else { y }
});
dbg!(e);

dbg!((
(s.x),
(s.y),
((e.x - s.x)),
((e.y - s.y))
));

render_pass.set_scissor_rect(
s.x as u32,
s.y as u32,
(e.x - s.x) as u32,
(e.y - s.y) as u32
);
dt.paint(&mut render_pass, &layer_collection, i as u32, feature.id, false);
}

for (i, drawable_tile) in self.loaded_tiles.values_mut().enumerate() {
drawable_tile.paint(&mut render_pass, &layer_collection, i as u32, feature.id, true);
}
// for (i, dt) in self.loaded_tiles.values_mut().enumerate() {
// dt.paint(&mut render_pass, &layer_collection, i as u32, feature.id, true);
// }
first = false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ fn main() {
}
},
WindowEvent::CursorMoved { position, .. } => {
let size = app_state.screen.get_tile_size();
let size = app_state.screen.get_tile_size() as f32;
let mut delta = vector((position.x - last_pos.x) as f32, (position.y - last_pos.y) as f32);
let zoom_x = (app_state.screen.width as f32) / size / 2f32.powf(app_state.zoom) / size / 2.0 / 1.3;
let zoom_y = (app_state.screen.height as f32) / size / 2f32.powf(app_state.zoom) / size / 2.0 / 1.3;
Expand Down
12 changes: 6 additions & 6 deletions src/vector_tile/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ impl Screen {
}
}

pub fn get_tile_size(&self) -> f32 {
self.tile_size as f32
pub fn get_tile_size(&self) -> u32 {
self.tile_size
}

pub fn get_tile_boundaries_for_zoom_level(&self, z: f32, scale: u32) -> TileField {
let z = z.min(14.0);
let px_to_world = self.width as f32 / self.get_tile_size() / 2.0 / 2f32.powi(z as i32) / scale as f32;
let py_to_world = self.height as f32 / self.get_tile_size() / 2.0 / 2f32.powi(z as i32) / scale as f32;
let px_to_world = self.width as f32 / self.get_tile_size() as f32 / 2.0 / 2f32.powi(z as i32) / scale as f32;
let py_to_world = self.height as f32 / self.get_tile_size() as f32 / 2.0 / 2f32.powi(z as i32) / scale as f32;

let top_left: TileId = global_to_num_space(&(self.center - vector(px_to_world, py_to_world)), z as u32).into();
let bottom_right: TileId = global_to_num_space(&(self.center + vector(px_to_world, py_to_world)), z as u32).into();
Expand All @@ -103,8 +103,8 @@ impl Screen {
}

pub fn global_to_screen(&self, z: f32) -> glm::TMat4<f32> {
let zoom_x = 2.0f32.powf(z) / (self.width as f32 / 2.0) * self.get_tile_size();
let zoom_y = 2.0f32.powf(z) / (self.height as f32 / 2.0) * self.get_tile_size();
let zoom_x = 2.0f32.powf(z) / (self.width as f32 / 2.0) * self.get_tile_size() as f32;
let zoom_y = 2.0f32.powf(z) / (self.height as f32 / 2.0) * self.get_tile_size() as f32;
let zoom = glm::scaling(&glm::vec3(zoom_x, zoom_y, 1.0));
let position = glm::translation(&glm::vec3(-self.center.x, -self.center.y, 0.0));
zoom * position
Expand Down

0 comments on commit e1db24f

Please sign in to comment.