Now can move camera in line editor mode, closes #2
This commit is contained in:
@@ -12,6 +12,7 @@
|
|||||||
#include <core/io/config_file.h>
|
#include <core/io/config_file.h>
|
||||||
#include <core/os/file_access.h>
|
#include <core/os/file_access.h>
|
||||||
#include <core/os/dir_access.h>
|
#include <core/os/dir_access.h>
|
||||||
|
#include <core/os/input.h>
|
||||||
#include <core/os/time.h>
|
#include <core/os/time.h>
|
||||||
#include <core/io/json.h>
|
#include <core/io/json.h>
|
||||||
#include <modules/regex/regex.h>
|
#include <modules/regex/regex.h>
|
||||||
@@ -464,6 +465,7 @@ RoadLinesEditor::RoadLinesEditor(WorldEditor *editor)
|
|||||||
, editor(editor)
|
, editor(editor)
|
||||||
, cursor_enabled(false)
|
, cursor_enabled(false)
|
||||||
, filter_text("")
|
, filter_text("")
|
||||||
|
, camera_moved(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -638,6 +640,22 @@ void RoadLinesEditor::update(float delta)
|
|||||||
cursor_enabled = false;
|
cursor_enabled = false;
|
||||||
get_as_node<Spatial>(cursor_name)->hide();
|
get_as_node<Spatial>(cursor_name)->hide();
|
||||||
}
|
}
|
||||||
|
if (camera_moved) {
|
||||||
|
Camera *cam = editor->get_viewport()->get_camera();
|
||||||
|
assert(cam);
|
||||||
|
camera_moved = false;
|
||||||
|
Transform cam_xform = cam->get_global_transform();
|
||||||
|
float h = cam_xform.origin.y;
|
||||||
|
cam_xform.origin.z += Math::abs(h) * camera_motion.z * delta;
|
||||||
|
cam_xform.origin.x += Math::abs(h) * camera_motion.x * delta;
|
||||||
|
cam_xform.origin.y += camera_motion.y * delta;
|
||||||
|
camera_motion = Vector3();
|
||||||
|
cam->set_global_transform(cam_xform);
|
||||||
|
Array move_args;
|
||||||
|
move_args.push_back(cam_xform);
|
||||||
|
editor->emit_signal("editor_event", "editor_camera_moved",
|
||||||
|
move_args);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RoadLinesEditor::exit()
|
void RoadLinesEditor::exit()
|
||||||
@@ -901,6 +919,31 @@ void RoadLinesEditor::remove_road_meshes()
|
|||||||
Array args;
|
Array args;
|
||||||
editor->editor_command("remove_road_meshes", args);
|
editor->editor_command("remove_road_meshes", args);
|
||||||
}
|
}
|
||||||
|
void RoadLinesEditor::handle_input()
|
||||||
|
{
|
||||||
|
if (editor->get_camera_mode() != 3)
|
||||||
|
return;
|
||||||
|
bool moved = false;
|
||||||
|
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) {
|
||||||
|
camera_motion.z -= zz;
|
||||||
|
moved = true;
|
||||||
|
}
|
||||||
|
if (Math::abs(xx) > 0.1f) {
|
||||||
|
camera_motion.x += xx;
|
||||||
|
moved = true;
|
||||||
|
}
|
||||||
|
if (Math::abs(hh) > 0.1f && Math::abs(xx) < 0.1f &&
|
||||||
|
Math::abs(zz) < 0.1f) {
|
||||||
|
camera_motion.y += 10.0f * hh;
|
||||||
|
moved = true;
|
||||||
|
}
|
||||||
|
if (moved)
|
||||||
|
camera_moved = true;
|
||||||
|
}
|
||||||
void RoadLinesEditor::place_zebras()
|
void RoadLinesEditor::place_zebras()
|
||||||
{
|
{
|
||||||
editor->remove_buildings_by_prefix("zebra");
|
editor->remove_buildings_by_prefix("zebra");
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ class RoadLinesEditor {
|
|||||||
bool cursor_enabled;
|
bool cursor_enabled;
|
||||||
String filter_text;
|
String filter_text;
|
||||||
Ref<RegEx> re;
|
Ref<RegEx> re;
|
||||||
|
bool camera_moved;
|
||||||
|
Vector3 camera_motion;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RoadLinesEditor(WorldEditor *editor);
|
RoadLinesEditor(WorldEditor *editor);
|
||||||
@@ -46,6 +48,7 @@ public:
|
|||||||
void place_generated_objects();
|
void place_generated_objects();
|
||||||
void rebuild_roads();
|
void rebuild_roads();
|
||||||
void remove_road_meshes();
|
void remove_road_meshes();
|
||||||
|
void handle_input();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void activate();
|
void activate();
|
||||||
|
|||||||
@@ -434,6 +434,8 @@ void WorldEditor::_unhandled_input(const Ref<InputEvent> &event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (current_mode == MODE_ROAD_LINES)
|
||||||
|
road_lines_editor->handle_input();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldEditor::world_exited()
|
void WorldEditor::world_exited()
|
||||||
|
|||||||
Reference in New Issue
Block a user