1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-22 15:06:45 +00:00

Add Bresenham Line to GridMap Drawing

This commit is contained in:
mchlopecki
2025-04-04 20:50:11 -05:00
committed by Chaosus
parent 0fdb93cde6
commit 3ee7bf459a

View File

@@ -30,6 +30,7 @@
#include "grid_map_editor_plugin.h" #include "grid_map_editor_plugin.h"
#include "core/math/geometry_2d.h"
#include "core/os/keyboard.h" #include "core/os/keyboard.h"
#include "editor/editor_main_screen.h" #include "editor/editor_main_screen.h"
#include "editor/editor_node.h" #include "editor/editor_node.h"
@@ -435,26 +436,66 @@ bool GridMapEditor::do_input_action(Camera3D *p_camera, const Point2 &p_point, b
return true; return true;
} }
if (input_action == INPUT_PAINT) { if (input_action == INPUT_PAINT || input_action == INPUT_ERASE) {
SetItem si; LocalVector<Vector3i> cells;
si.position = cursor_gridpos; if (!set_items.is_empty()) {
si.new_value = selected_palette; Vector3i last_si = (--set_items.end())->position;
si.new_orientation = cursor_rot; // Manipulate Vector3i into Point2i by ignoring the edit_axis.
si.old_value = node->get_cell_item(cursor_gridpos); int i = edit_axis == 0 ? 1 : 0;
si.old_orientation = node->get_cell_item_orientation(cursor_gridpos); int j = edit_axis == 2 ? 1 : 2;
set_items.push_back(si); Point2i from_cell = Point2i(last_si[i], last_si[j]);
node->set_cell_item(cursor_gridpos, selected_palette, cursor_rot); Point2i to_cell = Point2i(cursor_gridpos[i], cursor_gridpos[j]);
return true;
} else if (input_action == INPUT_ERASE) { Vector<Point2i> cells_2d = Geometry2D::bresenham_line(from_cell, to_cell);
SetItem si;
si.position = cursor_gridpos; switch (edit_axis) {
si.new_value = -1; case 0:
si.new_orientation = 0; for (const Point2i &cell_2d : cells_2d) {
si.old_value = node->get_cell_item(cursor_gridpos); cells.push_back(Vector3i(edit_floor[0], cell_2d[0], cell_2d[1]));
si.old_orientation = node->get_cell_item_orientation(cursor_gridpos); }
set_items.push_back(si); break;
node->set_cell_item(cursor_gridpos, -1); case 1:
return true; for (const Point2i &cell_2d : cells_2d) {
cells.push_back(Vector3i(cell_2d[0], edit_floor[1], cell_2d[1]));
}
break;
case 2:
for (const Point2i &cell_2d : cells_2d) {
cells.push_back(Vector3i(cell_2d[0], cell_2d[1], edit_floor[2]));
}
break;
default:
break;
}
} else {
cells.push_back(cursor_gridpos);
}
if (input_action == INPUT_PAINT) {
for (const Vector3i &cell_v : cells) {
SetItem si;
si.position = cell_v;
si.new_value = selected_palette;
si.new_orientation = cursor_rot;
si.old_value = node->get_cell_item(cell_v);
si.old_orientation = node->get_cell_item_orientation(cell_v);
set_items.push_back(si);
node->set_cell_item(cell_v, selected_palette, cursor_rot);
}
return true;
} else if (input_action == INPUT_ERASE) {
for (const Vector3i &cell_v : cells) {
SetItem si;
si.position = cell_v;
si.new_value = -1;
si.new_orientation = 0;
si.old_value = node->get_cell_item(cell_v);
si.old_orientation = node->get_cell_item_orientation(cell_v);
set_items.push_back(si);
node->set_cell_item(cell_v, -1);
}
return true;
}
} }
return false; return false;