|
|
@@ -2,10 +2,11 @@ use ::std::ffi::CStr;
|
|
2
|
2
|
use buffer::{Buffer, DrawMode};
|
|
3
|
3
|
use cgmath::{Matrix3, Point2, Transform, vec2, vec3};
|
|
4
|
4
|
use context::Context;
|
|
5
|
|
-use coord::{MapCoord, ScreenRect};
|
|
|
5
|
+use coord::{MapCoord, ScreenCoord, ScreenRect};
|
|
6
|
6
|
use image;
|
|
7
|
7
|
use map_view::MapView;
|
|
8
|
8
|
use mercator_view::MercatorView;
|
|
|
9
|
+use orthografic_view::OrthograficView;
|
|
9
|
10
|
use program::Program;
|
|
10
|
11
|
use texture::Texture;
|
|
11
|
12
|
use vertex_attrib::VertexAttribParams;
|
|
|
@@ -161,4 +162,92 @@ impl MarkerLayer {
|
|
161
|
162
|
self.buffer.set_data(cx, &vertex_data, vertex_data.len() / 4);
|
|
162
|
163
|
self.buffer.draw(cx, &self.program, DrawMode::Triangles);
|
|
163
|
164
|
}
|
|
|
165
|
+
|
|
|
166
|
+
|
|
|
167
|
+ pub fn draw_ortho(
|
|
|
168
|
+ &mut self,
|
|
|
169
|
+ cx: &mut Context,
|
|
|
170
|
+ map_view: &MapView,
|
|
|
171
|
+ dpi_factor: f64,
|
|
|
172
|
+ ) {
|
|
|
173
|
+ let mut vertex_data: Vec<f32> = vec![];
|
|
|
174
|
+
|
|
|
175
|
+ let marker_size = vec2::<f64>(40.0, 50.0) * dpi_factor;
|
|
|
176
|
+ let marker_offset = vec2::<f64>(-20.0, -50.0) * dpi_factor;
|
|
|
177
|
+
|
|
|
178
|
+ let scale_x = 2.0 / map_view.width as f32;
|
|
|
179
|
+ let scale_y = -2.0 / map_view.height as f32;
|
|
|
180
|
+
|
|
|
181
|
+ let tex_mat: Matrix3<f32> = Matrix3::from_cols(
|
|
|
182
|
+ vec3(marker_size.x as f32, 0.0, 0.0),
|
|
|
183
|
+ vec3(0.0, marker_size.y as f32, 0.0),
|
|
|
184
|
+ vec3(marker_offset.x as f32, marker_offset.y as f32, 1.0),
|
|
|
185
|
+ );
|
|
|
186
|
+
|
|
|
187
|
+ let screen_mat: Matrix3<f32> = Matrix3::from_cols(
|
|
|
188
|
+ vec3(scale_x, 0.0, 0.0),
|
|
|
189
|
+ vec3(0.0, scale_y, 0.0),
|
|
|
190
|
+ vec3(-1.0, 1.0, 1.0),
|
|
|
191
|
+ );
|
|
|
192
|
+
|
|
|
193
|
+ let t1 = Point2::new(0.0f32, 0.0);
|
|
|
194
|
+ let t2 = Point2::new(1.0f32, 0.0);
|
|
|
195
|
+ let t3 = Point2::new(1.0f32, 1.0);
|
|
|
196
|
+ let t4 = Point2::new(0.0f32, 1.0);
|
|
|
197
|
+
|
|
|
198
|
+ let visible_rect = ScreenRect {
|
|
|
199
|
+ x: -(marker_offset.x + marker_size.x),
|
|
|
200
|
+ y: -(marker_offset.y + marker_size.y),
|
|
|
201
|
+ width: map_view.width + marker_size.x,
|
|
|
202
|
+ height: map_view.height + marker_size.y,
|
|
|
203
|
+ };
|
|
|
204
|
+
|
|
|
205
|
+ let transform = OrthograficView::transformation_matrix(map_view);
|
|
|
206
|
+
|
|
|
207
|
+ for map_pos in &self.positions {
|
|
|
208
|
+ let screen_pos = {
|
|
|
209
|
+ let norm_pos = transform.transform_point(map_pos.to_latlon_rad().to_sphere_point3());
|
|
|
210
|
+
|
|
|
211
|
+ if norm_pos.z > 0.0 {
|
|
|
212
|
+ continue;
|
|
|
213
|
+ }
|
|
|
214
|
+
|
|
|
215
|
+ ScreenCoord::new(
|
|
|
216
|
+ (norm_pos.x + 1.0) * (0.5 * map_view.width),
|
|
|
217
|
+ (-norm_pos.y + 1.0) * (0.5 * map_view.height),
|
|
|
218
|
+ )
|
|
|
219
|
+ };
|
|
|
220
|
+
|
|
|
221
|
+ if !screen_pos.is_inside(&visible_rect) {
|
|
|
222
|
+ continue;
|
|
|
223
|
+ }
|
|
|
224
|
+ let trans_mat: Matrix3<f32> = Matrix3::from_cols(
|
|
|
225
|
+ vec3(0.0, 0.0, 0.0),
|
|
|
226
|
+ vec3(0.0, 0.0, 0.0),
|
|
|
227
|
+ vec3(screen_pos.x as f32, screen_pos.y as f32, 0.0),
|
|
|
228
|
+ );
|
|
|
229
|
+ let mat: Matrix3<f32> = screen_mat * (tex_mat + trans_mat);
|
|
|
230
|
+
|
|
|
231
|
+ let p1: Point2<f32> = mat.transform_point(t1);
|
|
|
232
|
+ let p2: Point2<f32> = mat.transform_point(t2);
|
|
|
233
|
+ let p3: Point2<f32> = mat.transform_point(t3);
|
|
|
234
|
+ let p4: Point2<f32> = mat.transform_point(t4);
|
|
|
235
|
+
|
|
|
236
|
+ vertex_data.extend::<&[f32; 2]>(p1.as_ref());
|
|
|
237
|
+ vertex_data.extend::<&[f32; 2]>(t1.as_ref());
|
|
|
238
|
+ vertex_data.extend::<&[f32; 2]>(p2.as_ref());
|
|
|
239
|
+ vertex_data.extend::<&[f32; 2]>(t2.as_ref());
|
|
|
240
|
+ vertex_data.extend::<&[f32; 2]>(p3.as_ref());
|
|
|
241
|
+ vertex_data.extend::<&[f32; 2]>(t3.as_ref());
|
|
|
242
|
+ vertex_data.extend::<&[f32; 2]>(p1.as_ref());
|
|
|
243
|
+ vertex_data.extend::<&[f32; 2]>(t1.as_ref());
|
|
|
244
|
+ vertex_data.extend::<&[f32; 2]>(p3.as_ref());
|
|
|
245
|
+ vertex_data.extend::<&[f32; 2]>(t3.as_ref());
|
|
|
246
|
+ vertex_data.extend::<&[f32; 2]>(p4.as_ref());
|
|
|
247
|
+ vertex_data.extend::<&[f32; 2]>(t4.as_ref());
|
|
|
248
|
+ }
|
|
|
249
|
+
|
|
|
250
|
+ self.buffer.set_data(cx, &vertex_data, vertex_data.len() / 4);
|
|
|
251
|
+ self.buffer.draw(cx, &self.program, DrawMode::Triangles);
|
|
|
252
|
+ }
|
|
164
|
253
|
}
|