You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-23 15:16:17 +00:00
Add Bresenham Line to GridMap Drawing
This commit is contained in:
@@ -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,27 +436,67 @@ bool GridMapEditor::do_input_action(Camera3D *p_camera, const Point2 &p_point, b
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (input_action == INPUT_PAINT || input_action == INPUT_ERASE) {
|
||||||
|
LocalVector<Vector3i> cells;
|
||||||
|
if (!set_items.is_empty()) {
|
||||||
|
Vector3i last_si = (--set_items.end())->position;
|
||||||
|
// Manipulate Vector3i into Point2i by ignoring the edit_axis.
|
||||||
|
int i = edit_axis == 0 ? 1 : 0;
|
||||||
|
int j = edit_axis == 2 ? 1 : 2;
|
||||||
|
Point2i from_cell = Point2i(last_si[i], last_si[j]);
|
||||||
|
Point2i to_cell = Point2i(cursor_gridpos[i], cursor_gridpos[j]);
|
||||||
|
|
||||||
|
Vector<Point2i> cells_2d = Geometry2D::bresenham_line(from_cell, to_cell);
|
||||||
|
|
||||||
|
switch (edit_axis) {
|
||||||
|
case 0:
|
||||||
|
for (const Point2i &cell_2d : cells_2d) {
|
||||||
|
cells.push_back(Vector3i(edit_floor[0], cell_2d[0], cell_2d[1]));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
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) {
|
if (input_action == INPUT_PAINT) {
|
||||||
|
for (const Vector3i &cell_v : cells) {
|
||||||
SetItem si;
|
SetItem si;
|
||||||
si.position = cursor_gridpos;
|
si.position = cell_v;
|
||||||
si.new_value = selected_palette;
|
si.new_value = selected_palette;
|
||||||
si.new_orientation = cursor_rot;
|
si.new_orientation = cursor_rot;
|
||||||
si.old_value = node->get_cell_item(cursor_gridpos);
|
si.old_value = node->get_cell_item(cell_v);
|
||||||
si.old_orientation = node->get_cell_item_orientation(cursor_gridpos);
|
si.old_orientation = node->get_cell_item_orientation(cell_v);
|
||||||
set_items.push_back(si);
|
set_items.push_back(si);
|
||||||
node->set_cell_item(cursor_gridpos, selected_palette, cursor_rot);
|
node->set_cell_item(cell_v, selected_palette, cursor_rot);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
} else if (input_action == INPUT_ERASE) {
|
} else if (input_action == INPUT_ERASE) {
|
||||||
|
for (const Vector3i &cell_v : cells) {
|
||||||
SetItem si;
|
SetItem si;
|
||||||
si.position = cursor_gridpos;
|
si.position = cell_v;
|
||||||
si.new_value = -1;
|
si.new_value = -1;
|
||||||
si.new_orientation = 0;
|
si.new_orientation = 0;
|
||||||
si.old_value = node->get_cell_item(cursor_gridpos);
|
si.old_value = node->get_cell_item(cell_v);
|
||||||
si.old_orientation = node->get_cell_item_orientation(cursor_gridpos);
|
si.old_orientation = node->get_cell_item_orientation(cell_v);
|
||||||
set_items.push_back(si);
|
set_items.push_back(si);
|
||||||
node->set_cell_item(cursor_gridpos, -1);
|
node->set_cell_item(cell_v, -1);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user