From 694190a354c1634caaff5cbd7357de345a334c01 Mon Sep 17 00:00:00 2001 From: Micky Date: Sat, 20 Aug 2022 18:39:05 +0200 Subject: Rename TileMap/GridMap.`world_to_map` and opposite to `local_to_map` For both TileMap and GridMap: - `world_to_map` -> `local_to_map` - `map_to_world` -> `map_to_local` Also changes any mention of "world" in this context to "local" to avoid future confusion. Finally, updates the docs of both methods for consistency. In particular, adding a note on how to convert the returned values from local to global coordinates and vice versa. --- modules/gltf/gltf_document.cpp | 2 +- modules/gridmap/doc_classes/GridMap.xml | 21 ++++++++++----------- modules/gridmap/grid_map.cpp | 12 ++++++------ modules/gridmap/grid_map.h | 4 ++-- 4 files changed, 19 insertions(+), 20 deletions(-) (limited to 'modules') diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp index 61af58bda7..6cb398b5f8 100644 --- a/modules/gltf/gltf_document.cpp +++ b/modules/gltf/gltf_document.cpp @@ -5271,7 +5271,7 @@ void GLTFDocument::_convert_grid_map_to_gltf(GridMap *p_grid_map, GLTFNodeIndex cell_xform.basis.scale(Vector3(p_grid_map->get_cell_scale(), p_grid_map->get_cell_scale(), p_grid_map->get_cell_scale())); - cell_xform.set_origin(p_grid_map->map_to_world( + cell_xform.set_origin(p_grid_map->map_to_local( Vector3(cell_location.x, cell_location.y, cell_location.z))); Ref gltf_mesh; gltf_mesh.instantiate(); diff --git a/modules/gridmap/doc_classes/GridMap.xml b/modules/gridmap/doc_classes/GridMap.xml index 6717f23057..5548006834 100644 --- a/modules/gridmap/doc_classes/GridMap.xml +++ b/modules/gridmap/doc_classes/GridMap.xml @@ -84,7 +84,7 @@ - Returns an array of [Transform3D] and [Mesh] references corresponding to the non-empty cells in the grid. The transforms are specified in world space. + Returns an array of [Transform3D] and [Mesh] references corresponding to the non-empty cells in the grid. The transforms are specified in local space. @@ -114,6 +114,13 @@ Returns an array of all cells with the given item index specified in [code]item[/code]. + + + + + Returns the map coordinates of the cell containing the given [param local_position]. If [param local_position] is in global coordinates, consider using [method Node3D.to_local] before passing it to this method. See also [method map_to_local]. + + @@ -121,11 +128,11 @@ - + - Returns the position of a grid cell in the GridMap's local coordinate space. + Returns the position of a grid cell in the GridMap's local coordinate space. To convert the returned value into global coordinates, use [method Node3D.to_global]. See also [method map_to_local]. @@ -169,14 +176,6 @@ Based on [code]value[/code], enables or disables the specified layer in the [member navigation_layers] bitmask, given a [code]layer_number[/code] between 1 and 32. - - - - - Returns the coordinates of the grid cell containing the given point. - [code]pos[/code] should be in the GridMap's local coordinate space. - - diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp index 8486e2c58b..ac0755cf68 100644 --- a/modules/gridmap/grid_map.cpp +++ b/modules/gridmap/grid_map.cpp @@ -497,18 +497,18 @@ int GridMap::get_orthogonal_index_from_basis(const Basis &p_basis) const { return 0; } -Vector3i GridMap::world_to_map(const Vector3 &p_world_position) const { +Vector3i GridMap::local_to_map(const Vector3 &p_world_position) const { Vector3 map_position = (p_world_position / cell_size).floor(); return Vector3i(map_position); } -Vector3 GridMap::map_to_world(const Vector3i &p_map_position) const { +Vector3 GridMap::map_to_local(const Vector3i &p_map_position) const { Vector3 offset = _get_offset(); - Vector3 world_pos( + Vector3 local_position( p_map_position.x * cell_size.x + offset.x, p_map_position.y * cell_size.y + offset.y, p_map_position.z * cell_size.z + offset.z); - return world_pos; + return local_position; } void GridMap::_octant_transform(const OctantKey &p_key) { @@ -1047,8 +1047,8 @@ void GridMap::_bind_methods() { ClassDB::bind_method(D_METHOD("get_basis_with_orthogonal_index", "index"), &GridMap::get_basis_with_orthogonal_index); ClassDB::bind_method(D_METHOD("get_orthogonal_index_from_basis", "basis"), &GridMap::get_orthogonal_index_from_basis); - ClassDB::bind_method(D_METHOD("world_to_map", "world_position"), &GridMap::world_to_map); - ClassDB::bind_method(D_METHOD("map_to_world", "map_position"), &GridMap::map_to_world); + ClassDB::bind_method(D_METHOD("local_to_map", "local_position"), &GridMap::local_to_map); + ClassDB::bind_method(D_METHOD("map_to_local", "map_position"), &GridMap::map_to_local); ClassDB::bind_method(D_METHOD("_update_octants_callback"), &GridMap::_update_octants_callback); ClassDB::bind_method(D_METHOD("resource_changed", "resource"), &GridMap::resource_changed); diff --git a/modules/gridmap/grid_map.h b/modules/gridmap/grid_map.h index f83ce68b09..4a4e970fd3 100644 --- a/modules/gridmap/grid_map.h +++ b/modules/gridmap/grid_map.h @@ -276,8 +276,8 @@ public: Basis get_basis_with_orthogonal_index(int p_index) const; int get_orthogonal_index_from_basis(const Basis &p_basis) const; - Vector3i world_to_map(const Vector3 &p_world_position) const; - Vector3 map_to_world(const Vector3i &p_map_position) const; + Vector3i local_to_map(const Vector3 &p_local_position) const; + Vector3 map_to_local(const Vector3i &p_map_position) const; void set_cell_scale(float p_scale); float get_cell_scale() const; -- cgit v1.2.3