From 0feff493758d49f036c2fbeba8d474c6870a4f81 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Tue, 24 Sep 2019 22:39:54 +0200 Subject: [PATCH] Improve the AudioStreamPlayer3D gizmo This adds more lines to the emission angle cone to give a better feel of depth in the 3D world. --- editor/spatial_editor_gizmos.cpp | 52 +++++++++++++++++--------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/editor/spatial_editor_gizmos.cpp b/editor/spatial_editor_gizmos.cpp index b9f26d666d6..529e884fc92 100644 --- a/editor/spatial_editor_gizmos.cpp +++ b/editor/spatial_editor_gizmos.cpp @@ -1074,7 +1074,8 @@ AudioStreamPlayer3DSpatialGizmoPlugin::AudioStreamPlayer3DSpatialGizmoPlugin() { Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/stream_player_3d", Color(0.4, 0.8, 1)); create_icon_material("stream_player_3d_icon", SpatialEditor::get_singleton()->get_icon("GizmoSpatialSamplePlayer", "EditorIcons")); - create_material("stream_player_3d_material", gizmo_color); + create_material("stream_player_3d_material_primary", gizmo_color); + create_material("stream_player_3d_material_secondary", gizmo_color * Color(1, 1, 1, 0.35)); create_handle_material("handles"); } @@ -1160,50 +1161,53 @@ void AudioStreamPlayer3DSpatialGizmoPlugin::commit_handle(EditorSpatialGizmo *p_ void AudioStreamPlayer3DSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) { - AudioStreamPlayer3D *player = Object::cast_to(p_gizmo->get_spatial_node()); + const AudioStreamPlayer3D *player = Object::cast_to(p_gizmo->get_spatial_node()); p_gizmo->clear(); - Ref icon = get_material("stream_player_3d_icon", p_gizmo); + const Ref icon = get_material("stream_player_3d_icon", p_gizmo); if (player->is_emission_angle_enabled()) { - Ref material = get_material("stream_player_3d_material", p_gizmo); + const float pc = player->get_emission_angle(); + const float ofs = -Math::cos(Math::deg2rad(pc)); + const float radius = Math::sin(Math::deg2rad(pc)); - float pc = player->get_emission_angle(); - - Vector points; - points.resize(208); - - float ofs = -Math::cos(Math::deg2rad(pc)); - float radius = Math::sin(Math::deg2rad(pc)); + Vector points_primary; + points_primary.resize(200); for (int i = 0; i < 100; i++) { - float a = i * 2.0 * Math_PI / 100.0; - float an = (i + 1) * 2.0 * Math_PI / 100.0; + const float a = i * 2.0 * Math_PI / 100.0; + const float an = (i + 1) * 2.0 * Math_PI / 100.0; - Vector3 from(Math::sin(a) * radius, Math::cos(a) * radius, ofs); - Vector3 to(Math::sin(an) * radius, Math::cos(an) * radius, ofs); + const Vector3 from(Math::sin(a) * radius, Math::cos(a) * radius, ofs); + const Vector3 to(Math::sin(an) * radius, Math::cos(an) * radius, ofs); - points.write[i * 2 + 0] = from; - points.write[i * 2 + 1] = to; + points_primary.write[i * 2 + 0] = from; + points_primary.write[i * 2 + 1] = to; } - for (int i = 0; i < 4; i++) { + const Ref material_primary = get_material("stream_player_3d_material_primary", p_gizmo); + p_gizmo->add_lines(points_primary, material_primary); - float a = i * 2.0 * Math_PI / 4.0; + Vector points_secondary; + points_secondary.resize(16); - Vector3 from(Math::sin(a) * radius, Math::cos(a) * radius, ofs); + for (int i = 0; i < 8; i++) { - points.write[200 + i * 2 + 0] = from; - points.write[200 + i * 2 + 1] = Vector3(); + const float a = i * 2.0 * Math_PI / 8.0; + const Vector3 from(Math::sin(a) * radius, Math::cos(a) * radius, ofs); + + points_secondary.write[i * 2 + 0] = from; + points_secondary.write[i * 2 + 1] = Vector3(); } - p_gizmo->add_lines(points, material); + const Ref material_secondary = get_material("stream_player_3d_material_secondary", p_gizmo); + p_gizmo->add_lines(points_secondary, material_secondary); Vector handles; - float ha = Math::deg2rad(player->get_emission_angle()); + const float ha = Math::deg2rad(player->get_emission_angle()); handles.push_back(Vector3(Math::sin(ha), 0, -Math::cos(ha))); p_gizmo->add_handles(handles, get_material("handles")); }