diff --git a/world/voxel_world_editor.cpp b/world/voxel_world_editor.cpp index 4d896bb..fd5be40 100644 --- a/world/voxel_world_editor.cpp +++ b/world/voxel_world_editor.cpp @@ -86,9 +86,13 @@ bool VoxelWorldEditor::do_input_action(Camera *p_camera, const Point2 &p_point, //_world->set_voxel(pos, data[]); //Ref chunk = _world->get_or_spawn_chunk_at_world_pos(pos); - int x = (pos.x - _world->get_chunk_size_x()) / _world->get_chunk_size_x() / _world->get_voxel_scale(); - int y = (pos.y - _world->get_chunk_size_y()) / _world->get_chunk_size_y() / _world->get_voxel_scale(); - int z = (pos.z - _world->get_chunk_size_z()) / _world->get_chunk_size_z() / _world->get_voxel_scale(); + float fx = pos.x / _world->get_chunk_size_x() / _world->get_voxel_scale(); + float fy = pos.y / _world->get_chunk_size_y() / _world->get_voxel_scale(); + float fz = pos.z / _world->get_chunk_size_z() / _world->get_voxel_scale(); + + int x = Math::floor(fx); + int y = Math::floor(fy); + int z = Math::floor(fz); Ref chunk = _world->get_chunk(x, y, z); @@ -96,9 +100,9 @@ bool VoxelWorldEditor::do_input_action(Camera *p_camera, const Point2 &p_point, chunk = _world->create_chunk(x, y, z); } - int bx = static_cast((pos.x - _world->get_chunk_size_x()) / _world->get_voxel_scale()) % _world->get_chunk_size_x(); - int by = static_cast((pos.y - _world->get_chunk_size_y()) / _world->get_voxel_scale()) % _world->get_chunk_size_y(); - int bz = static_cast((pos.z - _world->get_chunk_size_z()) / _world->get_voxel_scale()) % _world->get_chunk_size_z(); + int bx = static_cast(Math::round(pos.x / _world->get_voxel_scale())) % _world->get_chunk_size_x(); + int by = static_cast(Math::round(pos.y / _world->get_voxel_scale())) % _world->get_chunk_size_y(); + int bz = static_cast(Math::round(pos.z / _world->get_voxel_scale())) % _world->get_chunk_size_z(); if (bx < 0) bx += _world->get_chunk_size_x();