aboutsummaryrefslogtreecommitdiff
path: root/game/src/Game/GameSession/MapView.gd
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2024-08-01 21:35:11 +0200
committer GitHub <noreply@github.com>2024-08-01 21:35:11 +0200
commit8431914a6971cbacfb20bba13a4113d9ac4d5153 (patch)
tree71c1fa0482ab845b18a577a0d7503e40d49225f2 /game/src/Game/GameSession/MapView.gd
parente2cb2f5bd746d3928b4554252c69943df2ed5a3d (diff)
parent70f3c3cf6f9c1563d95ffb8c25bf8cd2bb7a1ad0 (diff)
Merge pull request #246 from OpenVicProject/search-panel
Search panel + text edit box UI generation
Diffstat (limited to 'game/src/Game/GameSession/MapView.gd')
-rw-r--r--game/src/Game/GameSession/MapView.gd15
1 files changed, 12 insertions, 3 deletions
diff --git a/game/src/Game/GameSession/MapView.gd b/game/src/Game/GameSession/MapView.gd
index bbae02f..171374c 100644
--- a/game/src/Game/GameSession/MapView.gd
+++ b/game/src/Game/GameSession/MapView.gd
@@ -134,18 +134,27 @@ func _map_to_world_coords(pos : Vector2) -> Vector3:
pos = pos * _map_mesh_dims + _map_mesh_corner
return Vector3(pos.x, 0, pos.y)
-func _viewport_to_map_coords(pos_viewport : Vector2) -> Vector2:
+func _viewport_to_world_coords(pos_viewport : Vector2) -> Vector3:
var ray_origin := _camera.project_ray_origin(pos_viewport)
var ray_normal := _camera.project_ray_normal(pos_viewport)
# Plane with normal (0,1,0) facing upwards, at a distance 0 from the origin
var intersection : Variant = Plane(0, 1, 0, 0).intersects_ray(ray_origin, ray_normal)
if typeof(intersection) == TYPE_VECTOR3:
- return _world_to_map_coords(intersection as Vector3)
+ return intersection
else:
# Normals parallel to the xz-plane could cause null intersections,
# but the camera's orientation should prevent such normals
push_error("Invalid intersection: ", intersection)
- return Vector2(0.5, 0.5)
+ return _map_to_world_coords(Vector2(0.5, 0.5))
+
+func _viewport_to_map_coords(pos_viewport : Vector2) -> Vector2:
+ return _world_to_map_coords(_viewport_to_world_coords(pos_viewport))
+
+func look_at_map_position(pos : Vector2) -> void:
+ var viewport_centre : Vector2 = Vector2(0.5, 0.5) * _viewport_dims / GuiScale.get_current_guiscale()
+ var pos_delta : Vector3 = _map_to_world_coords(pos) - _viewport_to_world_coords(viewport_centre)
+ _camera.position.x += pos_delta.x
+ _camera.position.z += pos_delta.z
func zoom_in() -> void:
_zoom_target -= _zoom_target_step