Explorar el Código

Fix accuracy issue at high zoom levels in ortho view

This now uses an f64 transformation matrix (instead of f32) to transform
points on the sphere to screen coordinates. Conversion to f32 vertex
positions happens as a last step before uploading to a GPU buffer.
Johannes Hofmann hace 7 años
padre
commit
69a245c187
Se han modificado 2 ficheros con 15 adiciones y 19 borrados
  1. 2
    6
      src/coord.rs
  2. 13
    13
      src/orthografic_view.rs

+ 2
- 6
src/coord.rs Ver fichero

@@ -60,13 +60,9 @@ impl LatLonRad {
60 60
     }
61 61
 
62 62
     /// Convert to 3D Point on unit sphere.
63
-    pub fn to_sphere_point3(&self) -> Point3<f32> {
63
+    pub fn to_sphere_point3(&self) -> Point3<f64> {
64 64
         let p = self.to_sphere_xyz();
65
-        Point3::new(
66
-            p.x as f32,
67
-            p.y as f32,
68
-            p.z as f32,
69
-        )
65
+        Point3::new(p.x, p.y, p.z)
70 66
     }
71 67
 }
72 68
 

+ 13
- 13
src/orthografic_view.rs Ver fichero

@@ -2,7 +2,7 @@ use cgmath::{Matrix3, Point3, Transform, vec3};
2 2
 use coord::{LatLonRad, TextureRect, TileCoord};
3 3
 use map_view::MapView;
4 4
 use std::collections::HashSet;
5
-use std::f32::consts::{PI, FRAC_1_PI};
5
+use std::f64::consts::{PI, FRAC_1_PI};
6 6
 use std::f64;
7 7
 
8 8
 
@@ -159,7 +159,7 @@ impl OrthograficView {
159 159
 
160 160
         let transform = Self::transformation_matrix(map_view);
161 161
 
162
-        let point_on_screen = |p: &Point3<f32>| {
162
+        let point_on_screen = |p: &Point3<_>| {
163 163
             p.x >= -1.0 && p.x <= 1.0 && p.y >= -1.0 && p.y <= 1.0
164 164
         };
165 165
 
@@ -217,22 +217,22 @@ impl OrthograficView {
217 217
         tiles
218 218
     }
219 219
 
220
-    pub fn transformation_matrix(map_view: &MapView) -> Matrix3<f32> {
220
+    pub fn transformation_matrix(map_view: &MapView) -> Matrix3<f64> {
221 221
         let (scale_x, scale_y) = {
222
-            let factor = 2.0f32.powf(map_view.zoom as f32) *
223
-                (FRAC_1_PI * map_view.tile_size as f32);
224
-            (factor / map_view.width as f32, factor / map_view.height as f32)
222
+            let factor = 2.0f64.powf(map_view.zoom) *
223
+                (FRAC_1_PI * map_view.tile_size as f64);
224
+            (factor / map_view.width, factor / map_view.height)
225 225
         };
226 226
 
227
-        let scale_mat: Matrix3<f32> = Matrix3::from_cols(
227
+        let scale_mat: Matrix3<f64> = Matrix3::from_cols(
228 228
             vec3(scale_x, 0.0, 0.0),
229 229
             vec3(0.0, scale_y, 0.0),
230 230
             vec3(0.0, 0.0, 1.0),
231 231
         );
232 232
 
233
-        let rot_mat_x: Matrix3<f32> = {
233
+        let rot_mat_x: Matrix3<f64> = {
234 234
             let center_latlon = map_view.center.to_latlon_rad();
235
-            let alpha = center_latlon.lon as f32 + (PI * 0.5);
235
+            let alpha = center_latlon.lon + (PI * 0.5);
236 236
             let cosa = alpha.cos();
237 237
             let sina = alpha.sin();
238 238
                 Matrix3::from_cols(
@@ -242,9 +242,9 @@ impl OrthograficView {
242 242
             )
243 243
         };
244 244
 
245
-        let rot_mat_y: Matrix3<f32> = {
245
+        let rot_mat_y: Matrix3<f64> = {
246 246
             let center_latlon = map_view.center.to_latlon_rad();
247
-            let alpha = (-center_latlon.lat) as f32;
247
+            let alpha = -center_latlon.lat;
248 248
             let cosa = alpha.cos();
249 249
             let sina = alpha.sin();
250 250
                 Matrix3::from_cols(
@@ -254,8 +254,8 @@ impl OrthograficView {
254 254
             )
255 255
         };
256 256
 
257
-        let transform = Transform::<Point3<f32>>::concat(&rot_mat_y, &rot_mat_x);
258
-        let transform = Transform::<Point3<f32>>::concat(&scale_mat, &transform);
257
+        let transform = Transform::<Point3<f64>>::concat(&rot_mat_y, &rot_mat_x);
258
+        let transform = Transform::<Point3<f64>>::concat(&scale_mat, &transform);
259 259
         transform
260 260
     }
261 261
 }