1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//! # Geographic entity positioning system
//!
//! Keeps user-spawned Bevy entities pinned to their geographic
//! coordinates as the map camera pans, zooms, and rotates.
//!
//! ## Usage
//!
//! Attach [`MapEntity`] + [`GeoTransform`] to any Bevy entity:
//!
//! ```rust,ignore
//! commands.spawn((
//! MapEntity,
//! GeoTransform::from_lat_lon(48.8566, 2.3522), // Paris
//! Transform::default(),
//! Visibility::default(),
//! // ... mesh, sprite, etc.
//! ));
//! ```
//!
//! Each frame this system rewrites `Transform.translation` so the
//! entity stays at the correct screen position. User-supplied
//! rotation and scale on the `Transform` are **preserved** -- only
//! the translation is overwritten.
//!
//! ## Coordinate pipeline
//!
//! ```text
//! GeoCoord (lat/lon/alt)
//! |
//! | WebMercator::project()
//! v
//! WorldCoord (x, y, z) -- metres, absolute
//! |
//! | subtract camera_origin
//! v
//! camera-relative (f32) -- small values, no jitter
//! ```
//!
//! The camera-relative model is shared by all sync systems (tiles,
//! terrain, vectors, models). See the
//! [camera_sync](super::camera_sync) module docs for the full
//! explanation.
//!
//! ## Altitude modes
//!
//! | [`GeoAltitudeMode`] | Z value |
//! |----------------------|---------|
//! | `ClampToGround` | terrain elevation (or 0 when unavailable) |
//! | `RelativeToGround` | terrain elevation + `GeoCoord.alt` |
//! | `Absolute` | `GeoCoord.alt` directly |
//!
//! Terrain elevation is queried via
//! [`MapState::elevation_at`](rustial_engine::MapState::elevation_at).
//! When terrain is disabled or the tile covering the coordinate has
//! not loaded yet, the query returns `None` and the system falls back
//! to ground = 0 m.
//!
//! ## Scheduling
//!
//! Registered in [`Update`](bevy::prelude::Update) so it runs after
//! the camera and engine state have been synchronised in `PreUpdate`.
use crate;
use crateMapStateResource;
use *;
/// Reposition every [`MapEntity`] to camera-relative coordinates each
/// frame.
///
/// Iterates all entities carrying both [`MapEntity`] and
/// [`GeoTransform`], projects the geographic coordinate to Web
/// Mercator world space, subtracts the camera origin to get an f32
/// camera-relative position, and resolves the Z component according
/// to the entity's [`GeoAltitudeMode`].
///
/// Only `Transform.translation` is written -- rotation and scale set
/// by the user (or other systems) are left untouched.