Using lines cursor
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include <scene/gui/button.h>
|
||||
#include <scene/gui/line_edit.h>
|
||||
#include <scene/3d/immediate_geometry.h>
|
||||
#include <scene/3d/camera.h>
|
||||
#include <core/io/config_file.h>
|
||||
#include <core/os/file_access.h>
|
||||
#include <core/io/json.h>
|
||||
@@ -214,6 +215,7 @@ static HandleCreateNewLine *new_line_handler = nullptr;
|
||||
RoadLinesEditor::RoadLinesEditor(WorldEditor *editor)
|
||||
: active(false)
|
||||
, editor(editor)
|
||||
, cursor_enabled(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -246,6 +248,13 @@ void RoadLinesEditor::update(float delta)
|
||||
if (!active)
|
||||
activate();
|
||||
// print_line("road_lines_editor");
|
||||
if (!cursor_enabled && get_camera_mode() == 3) {
|
||||
cursor_enabled = true;
|
||||
get_as_node<Spatial>("%line_cursor")->show();
|
||||
} else if (cursor_enabled && get_camera_mode() != 3) {
|
||||
cursor_enabled = false;
|
||||
get_as_node<Spatial>("%line_cursor")->hide();
|
||||
}
|
||||
}
|
||||
|
||||
void RoadLinesEditor::exit()
|
||||
@@ -261,7 +270,45 @@ void RoadLinesEditor::editor_command(const String &command, const Array &args)
|
||||
|
||||
void RoadLinesEditor::editor_event(const String &event, const Array &args)
|
||||
{
|
||||
print_line("event: " + event);
|
||||
print_line("RoadLinesEditor::event: " + event);
|
||||
if (event == "mouse_press") {
|
||||
if (cursor_enabled) {
|
||||
Spatial *cursor = get_as_node<Spatial>("%line_cursor");
|
||||
/*
|
||||
var camera = get_viewport().get_camera()
|
||||
var start = camera.project_ray_origin(position)
|
||||
var normal = camera.project_ray_normal(position)
|
||||
var end = start + normal * camera.get_zfar()
|
||||
var space_state = get_world().direct_space_state
|
||||
var result = space_state.intersect_ray(start, end, [], 1 << 15, false, true)
|
||||
*/
|
||||
Vector2 position = args[0];
|
||||
Camera *cam = editor->get_viewport()->get_camera();
|
||||
Vector3 start = cam->project_ray_origin(position);
|
||||
Vector3 normal = cam->project_ray_normal(position);
|
||||
Vector3 end = start + normal * cam->get_zfar();
|
||||
PhysicsDirectSpaceState *space_state =
|
||||
editor->get_world()->get_direct_space_state();
|
||||
PhysicsDirectSpaceState::RayResult result;
|
||||
Set<RID> exclude;
|
||||
space_state->intersect_ray(start, end, result, exclude,
|
||||
(1 << 15) | (1 << 0), true,
|
||||
true);
|
||||
if (result.rid != RID()) {
|
||||
cursor->set_global_transform(
|
||||
Transform(Basis(), result.position));
|
||||
Array pargs;
|
||||
pargs.push_back(result.position);
|
||||
editor->emit_signal("editor_event",
|
||||
"line_cursor_motion",
|
||||
pargs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
int RoadLinesEditor::get_camera_mode() const
|
||||
{
|
||||
return editor->get_camera_mode();
|
||||
}
|
||||
|
||||
void RoadLinesEditor::update_ui()
|
||||
|
||||
Reference in New Issue
Block a user