Skip to content

Commit

Permalink
Fix near zero precision error
Browse files Browse the repository at this point in the history
  • Loading branch information
TokisanGames committed Sep 3, 2024
1 parent 6191c8d commit 97a7bdb
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/terrain_3d_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,11 +453,9 @@ void Terrain3DStorage::set_pixel(const MapType p_map_type, const Vector3 &p_glob
return;
}
Vector2i global_offset = Vector2i(_region_offsets[region]) * _region_size;
Vector3 descaled_position = p_global_position / _terrain->get_mesh_vertex_spacing();
Vector2i img_pos = Vector2i(
Vector2(descaled_position.x - global_offset.x,
descaled_position.z - global_offset.y)
.floor());
Vector3 descaled_pos = p_global_position / _terrain->get_mesh_vertex_spacing();
Vector2i img_pos = Vector2i(descaled_pos.x - global_offset.x, descaled_pos.z - global_offset.y);
img_pos = img_pos.clamp(Vector2i(), Vector2i(_region_size - 1, _region_size - 1));
Ref<Image> map = get_map_region(p_map_type, region);
map->set_pixelv(img_pos, p_pixel);
}
Expand All @@ -473,11 +471,8 @@ Color Terrain3DStorage::get_pixel(const MapType p_map_type, const Vector3 &p_glo
return COLOR_NAN;
}
Vector2i global_offset = Vector2i(_region_offsets[region]) * _region_size;
Vector3 descaled_position = p_global_position / _terrain->get_mesh_vertex_spacing();
Vector2i img_pos = Vector2i(
Vector2(descaled_position.x - global_offset.x,
descaled_position.z - global_offset.y)
.floor());
Vector3 descaled_pos = p_global_position / _terrain->get_mesh_vertex_spacing();
Vector2i img_pos = Vector2i(descaled_pos.x - global_offset.x, descaled_pos.z - global_offset.y);
img_pos = img_pos.clamp(Vector2i(), Vector2i(_region_size - 1, _region_size - 1));
Ref<Image> map = get_map_region(p_map_type, region);
return map->get_pixelv(img_pos);
Expand Down

0 comments on commit 97a7bdb

Please sign in to comment.