fixed camera rotation fixed

This commit is contained in:
2024-09-17 15:30:35 +03:00
parent 3c99a0b09c
commit c268a4992a
4 changed files with 72 additions and 118 deletions

View File

@@ -13,6 +13,7 @@
#include <scene/scene_string_names.h>
#include "road_lines_editor.h"
#include "world_editor.h"
#include "editor_event.h"
#include "buildings_editor.h"
WorldEditor::WorldEditor()
@@ -48,12 +49,14 @@ WorldEditor::WorldEditor()
InputMap::get_singleton()->add_action("editor_cam3");
if (!InputMap::get_singleton()->has_action("mouse1"))
InputMap::get_singleton()->add_action("mouse1");
event.add_listener(this, &WorldEditor::event_signal_handler);
EditorEvent::get_singleton()->event.add_listener(
this, &WorldEditor::event_signal_handler);
}
WorldEditor::~WorldEditor()
{
event.remove_listener(this, &WorldEditor::event_signal_handler);
EditorEvent::get_singleton()->event.remove_listener(
this, &WorldEditor::event_signal_handler);
if (road_lines_editor) {
memdelete(road_lines_editor);
road_lines_editor = nullptr;
@@ -167,7 +170,7 @@ void WorldEditor::tools_button(const String &button)
goto end;
change[0] = current_mode;
change[1] = modes[button];
event.emit("mode_change_pre", change);
EditorEvent::get_singleton()->event.emit("mode_change_pre", change);
switch (current_mode) {
case MODE_ROAD_LINES:
road_lines_editor->exit();
@@ -193,7 +196,7 @@ void WorldEditor::tools_button(const String &button)
mode_npc();
break;
}
event.emit("mode_change_post", change);
EditorEvent::get_singleton()->event.emit("mode_change_post", change);
current_mode = modes[button];
end:;
}
@@ -277,7 +280,7 @@ StreamWorld *WorldEditor::get_stream_world()
void WorldEditor::world_command_result(const String &what, const Array &data)
{
print_line("what: " + what);
event.emit("result:" + what, data);
EditorEvent::get_singleton()->event.emit("result:" + what, data);
}
void WorldEditor::_notification(int which)
@@ -332,10 +335,10 @@ void WorldEditor::_notification(int which)
Vector2 position =
get_viewport()->get_mouse_position();
args.push_back(position);
event.emit("mouse_drag_off", args);
EditorEvent::get_singleton()->event.emit(
"mouse_drag_off", args);
}
}
Transform cam_xform = cam->get_global_transform();
if (current_camera_mode == 1) {
Vector2 mouse_pos =
get_viewport()->get_mouse_position();
@@ -346,33 +349,6 @@ void WorldEditor::_notification(int which)
motion = mouse_pos - old_mouse_pos;
old_mouse_pos = mouse_pos;
}
bool moved = false;
float h = cam_xform.origin.y;
float xx = Input::get_singleton()->get_axis("left",
"right");
float zz = Input::get_singleton()->get_axis("backward",
"forward");
float hh = Input::get_singleton()->get_axis("action2",
"action");
if (Math::abs(zz) > 0.1f) {
cam_xform.origin.z -= Math::abs(h) * zz * delta;
moved = true;
}
if (Math::abs(xx) > 0.1f) {
cam_xform.origin.x += Math::abs(h) * xx * delta;
moved = true;
}
if (Math::abs(hh) > 0.1f && Math::abs(xx) < 0.1f &&
Math::abs(zz) < 0.1f) {
cam_xform.origin.y += 10.0f * hh * delta;
moved = true;
}
if (moved) {
cam->set_global_transform(cam_xform);
Array move_args;
move_args.push_back(cam_xform);
event.emit("editor_camera_moved", move_args);
}
}
if (!dragging && drag_delay >= 0.0f)
drag_delay -= delta;
@@ -406,13 +382,14 @@ void WorldEditor::_unhandled_input(const Ref<InputEvent> &event)
Array args;
Vector2 position = get_viewport()->get_mouse_position();
args.push_back(position);
this->event.emit("mouse_press", args);
EditorEvent::get_singleton()->event.emit("mouse_press", args);
} else if (Input::get_singleton()->is_action_pressed("mouse1")) {
if (dragging) {
Array args;
Vector2 position = get_viewport()->get_mouse_position();
args.push_back(position);
this->event.emit("mouse_drag", args);
EditorEvent::get_singleton()->event.emit("mouse_drag",
args);
} else {
if (drag_delay < 0.0f && !dragging) {
dragging = true;
@@ -420,7 +397,8 @@ void WorldEditor::_unhandled_input(const Ref<InputEvent> &event)
Vector2 position =
get_viewport()->get_mouse_position();
args.push_back(position);
this->event.emit("mouse_drag_on", args);
EditorEvent::get_singleton()->event.emit(
"mouse_drag_on", args);
}
}
}