diff options
Diffstat (limited to 'scene')
-rw-r--r-- | scene/2d/audio_stream_player_2d.cpp | 36 | ||||
-rw-r--r-- | scene/2d/audio_stream_player_2d.h | 3 | ||||
-rw-r--r-- | scene/3d/audio_stream_player_3d.cpp | 31 | ||||
-rw-r--r-- | scene/3d/audio_stream_player_3d.h | 3 | ||||
-rw-r--r-- | scene/audio/audio_player.cpp | 30 | ||||
-rw-r--r-- | scene/audio/audio_player.h | 2 | ||||
-rw-r--r-- | scene/gui/color_picker.cpp | 3 | ||||
-rw-r--r-- | scene/gui/color_picker.h | 2 | ||||
-rw-r--r-- | scene/gui/popup_menu.cpp | 25 | ||||
-rw-r--r-- | scene/gui/popup_menu.h | 3 | ||||
-rw-r--r-- | scene/gui/slider.cpp | 25 | ||||
-rw-r--r-- | scene/gui/slider.h | 4 | ||||
-rw-r--r-- | scene/register_scene_types.cpp | 2 | ||||
-rw-r--r-- | scene/resources/cylinder_shape.cpp | 116 | ||||
-rw-r--r-- | scene/resources/cylinder_shape.h | 57 |
15 files changed, 287 insertions, 55 deletions
diff --git a/scene/2d/audio_stream_player_2d.cpp b/scene/2d/audio_stream_player_2d.cpp index b6dfc666b0..507499a324 100644 --- a/scene/2d/audio_stream_player_2d.cpp +++ b/scene/2d/audio_stream_player_2d.cpp @@ -37,7 +37,7 @@ void AudioStreamPlayer2D::_mix_audio() { if (!stream_playback.is_valid() || !active || - (stream_paused && stream_paused_fade <= 0.f)) { + (stream_paused && !stream_paused_fade_out)) { return; } @@ -50,11 +50,13 @@ void AudioStreamPlayer2D::_mix_audio() { AudioFrame *buffer = mix_buffer.ptrw(); int buffer_size = mix_buffer.size(); - // Mix if we're not paused or we're fading out - if (!stream_paused || stream_paused_fade > 0.f) { - stream_playback->mix(buffer, pitch_scale, buffer_size); + if (stream_paused_fade_out) { + // Short fadeout ramp + buffer_size = MIN(buffer_size, 128); } + stream_playback->mix(buffer, pitch_scale, buffer_size); + //write all outputs for (int i = 0; i < output_count; i++) { @@ -82,15 +84,10 @@ void AudioStreamPlayer2D::_mix_audio() { } //mix! - AudioFrame vol_inc = (current.vol - prev_outputs[i].vol) / float(buffer_size); - AudioFrame vol = current.vol; - - if (stream_paused) { - vol = vol * stream_paused_fade; - if (stream_paused_fade > 0.f) { - stream_paused_fade -= 0.1f; - } - } + AudioFrame target_volume = stream_paused_fade_out ? AudioFrame(0.f, 0.f) : current.vol; + AudioFrame vol_prev = stream_paused_fade_in ? AudioFrame(0.f, 0.f) : prev_outputs[i].vol; + AudioFrame vol_inc = (target_volume - vol_prev) / float(buffer_size); + AudioFrame vol = stream_paused_fade_in ? AudioFrame(0.f, 0.f) : current.vol; int cc = AudioServer::get_singleton()->get_channel_count(); @@ -131,6 +128,8 @@ void AudioStreamPlayer2D::_mix_audio() { } output_ready = false; + stream_paused_fade_in = false; + stream_paused_fade_out = false; } void AudioStreamPlayer2D::_notification(int p_what) { @@ -305,6 +304,11 @@ float AudioStreamPlayer2D::get_pitch_scale() const { void AudioStreamPlayer2D::play(float p_from_pos) { + if (!is_playing()) { + // Reset the prev_output_count if the stream is stopped + prev_output_count = 0; + } + if (stream_playback.is_valid()) { setplay = p_from_pos; output_ready = false; @@ -439,7 +443,8 @@ void AudioStreamPlayer2D::set_stream_paused(bool p_pause) { if (p_pause != stream_paused) { stream_paused = p_pause; - stream_paused_fade = stream_paused ? 1.f : 0.f; + stream_paused_fade_in = p_pause ? false : true; + stream_paused_fade_out = p_pause ? true : false; } } @@ -518,7 +523,8 @@ AudioStreamPlayer2D::AudioStreamPlayer2D() { output_ready = false; area_mask = 1; stream_paused = false; - stream_paused_fade = 0.f; + stream_paused_fade_in = false; + stream_paused_fade_out = false; AudioServer::get_singleton()->connect("bus_layout_changed", this, "_bus_layout_changed"); } diff --git a/scene/2d/audio_stream_player_2d.h b/scene/2d/audio_stream_player_2d.h index b508de3171..e68e6eeca5 100644 --- a/scene/2d/audio_stream_player_2d.h +++ b/scene/2d/audio_stream_player_2d.h @@ -71,9 +71,10 @@ private: float volume_db; float pitch_scale; - float stream_paused_fade; bool autoplay; bool stream_paused; + bool stream_paused_fade_in; + bool stream_paused_fade_out; StringName bus; void _mix_audio(); diff --git a/scene/3d/audio_stream_player_3d.cpp b/scene/3d/audio_stream_player_3d.cpp index 35c52a26c9..d46231a677 100644 --- a/scene/3d/audio_stream_player_3d.cpp +++ b/scene/3d/audio_stream_player_3d.cpp @@ -36,7 +36,7 @@ void AudioStreamPlayer3D::_mix_audio() { if (!stream_playback.is_valid() || !active || - (stream_paused && stream_paused_fade <= 0.f)) { + (stream_paused && !stream_paused_fade_out)) { return; } @@ -51,9 +51,13 @@ void AudioStreamPlayer3D::_mix_audio() { AudioFrame *buffer = mix_buffer.ptrw(); int buffer_size = mix_buffer.size(); + if (stream_paused_fade_out) { + // Short fadeout ramp + buffer_size = MIN(buffer_size, 128); + } + // Mix if we're not paused or we're fading out - if ((output_count > 0 || out_of_range_mode == OUT_OF_RANGE_MIX) && - (!stream_paused || stream_paused_fade > 0.f)) { + if ((output_count > 0 || out_of_range_mode == OUT_OF_RANGE_MIX)) { float output_pitch_scale = 0.0; if (output_count) { @@ -103,15 +107,10 @@ void AudioStreamPlayer3D::_mix_audio() { int buffers = AudioServer::get_singleton()->get_channel_count(); for (int k = 0; k < buffers; k++) { - AudioFrame vol_inc = (current.vol[k] - prev_outputs[i].vol[k]) / float(buffer_size); - AudioFrame vol = current.vol[k]; - - if (stream_paused) { - vol = vol * stream_paused_fade; - if (stream_paused_fade > 0.f) { - stream_paused_fade -= 0.1f; - } - } + AudioFrame target_volume = stream_paused_fade_out ? AudioFrame(0.f, 0.f) : current.vol[k]; + AudioFrame vol_prev = stream_paused_fade_in ? AudioFrame(0.f, 0.f) : prev_outputs[i].vol[k]; + AudioFrame vol_inc = (target_volume - vol_prev) / float(buffer_size); + AudioFrame vol = stream_paused_fade_in ? AudioFrame(0.f, 0.f) : current.vol[k]; AudioFrame *target = AudioServer::get_singleton()->thread_get_channel_mix_buffer(current.bus_index, k); @@ -193,6 +192,8 @@ void AudioStreamPlayer3D::_mix_audio() { } output_ready = false; + stream_paused_fade_in = false; + stream_paused_fade_out = false; } float AudioStreamPlayer3D::_get_attenuation_db(float p_distance) const { @@ -846,7 +847,8 @@ void AudioStreamPlayer3D::set_stream_paused(bool p_pause) { if (p_pause != stream_paused) { stream_paused = p_pause; - stream_paused_fade = stream_paused ? 1.f : 0.f; + stream_paused_fade_in = stream_paused ? false : true; + stream_paused_fade_out = stream_paused ? true : false; } } @@ -984,7 +986,8 @@ AudioStreamPlayer3D::AudioStreamPlayer3D() { out_of_range_mode = OUT_OF_RANGE_MIX; doppler_tracking = DOPPLER_TRACKING_DISABLED; stream_paused = false; - stream_paused_fade = 0.f; + stream_paused_fade_in = false; + stream_paused_fade_out = false; velocity_tracker.instance(); AudioServer::get_singleton()->connect("bus_layout_changed", this, "_bus_layout_changed"); diff --git a/scene/3d/audio_stream_player_3d.h b/scene/3d/audio_stream_player_3d.h index cab1ff121a..14413d0702 100644 --- a/scene/3d/audio_stream_player_3d.h +++ b/scene/3d/audio_stream_player_3d.h @@ -107,9 +107,10 @@ private: float unit_size; float max_db; float pitch_scale; - float stream_paused_fade; bool autoplay; bool stream_paused; + bool stream_paused_fade_in; + bool stream_paused_fade_out; StringName bus; void _mix_audio(); diff --git a/scene/audio/audio_player.cpp b/scene/audio/audio_player.cpp index 40ec04e479..863b278b62 100644 --- a/scene/audio/audio_player.cpp +++ b/scene/audio/audio_player.cpp @@ -41,30 +41,22 @@ void AudioStreamPlayer::_mix_internal(bool p_fadeout) { int buffer_size = mix_buffer.size(); if (p_fadeout) { - buffer_size = MIN(buffer_size, 16); //short fadeout ramp + // Short fadeout ramp + buffer_size = MIN(buffer_size, 128); } - // Mix if we're not paused or we're fading out - if (!stream_paused || stream_paused_fade > 0.f) { - stream_playback->mix(buffer, pitch_scale, buffer_size); - } + stream_playback->mix(buffer, pitch_scale, buffer_size); //multiply volume interpolating to avoid clicks if this changes float target_volume = p_fadeout ? -80.0 : volume_db; float vol = Math::db2linear(mix_volume_db); float vol_inc = (Math::db2linear(target_volume) - vol) / float(buffer_size); - if (stream_paused) { - vol = vol * stream_paused_fade; - if (stream_paused_fade > 0.f) { - stream_paused_fade -= 0.1f; - } - } - for (int i = 0; i < buffer_size; i++) { buffer[i] *= vol; vol += vol_inc; } + //set volume for next mix mix_volume_db = target_volume; @@ -99,8 +91,14 @@ void AudioStreamPlayer::_mix_internal(bool p_fadeout) { void AudioStreamPlayer::_mix_audio() { - if (!stream_playback.is_valid() || !active || - (stream_paused && stream_paused_fade <= 0.f)) { + if (!stream_playback.is_valid() || !active) + return; + + if (stream_paused) { + if (stream_paused_fade) { + _mix_internal(true); + stream_paused_fade = false; + } return; } @@ -295,7 +293,7 @@ void AudioStreamPlayer::set_stream_paused(bool p_pause) { if (p_pause != stream_paused) { stream_paused = p_pause; - stream_paused_fade = stream_paused ? 1.f : 0.f; + stream_paused_fade = p_pause ? true : false; } } @@ -385,7 +383,7 @@ AudioStreamPlayer::AudioStreamPlayer() { setseek = -1; active = false; stream_paused = false; - stream_paused_fade = 0.f; + stream_paused_fade = false; mix_target = MIX_TARGET_STEREO; AudioServer::get_singleton()->connect("bus_layout_changed", this, "_bus_layout_changed"); diff --git a/scene/audio/audio_player.h b/scene/audio/audio_player.h index c42f191589..591c00ed18 100644 --- a/scene/audio/audio_player.h +++ b/scene/audio/audio_player.h @@ -56,9 +56,9 @@ private: float mix_volume_db; float pitch_scale; float volume_db; - float stream_paused_fade; bool autoplay; bool stream_paused; + bool stream_paused_fade; StringName bus; MixTarget mix_target; diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index f8c188d33d..8e232c6f46 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -743,8 +743,9 @@ ColorPicker *ColorPickerButton::get_picker() { return picker; } -PopupPanel *ColorPickerButton::get_popup() const { +PopupPanel *ColorPickerButton::get_popup() { + _update_picker(); return popup; } diff --git a/scene/gui/color_picker.h b/scene/gui/color_picker.h index c8d8e1aa8a..0166da7118 100644 --- a/scene/gui/color_picker.h +++ b/scene/gui/color_picker.h @@ -144,7 +144,7 @@ public: bool is_editing_alpha() const; ColorPicker *get_picker(); - PopupPanel *get_popup() const; + PopupPanel *get_popup(); ColorPickerButton(); }; diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index 18e609c798..f5890fa2ee 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -398,6 +398,15 @@ void PopupMenu::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_ENTER_TREE: { + + PopupMenu *pm = Object::cast_to<PopupMenu>(get_parent()); + if (pm) { + // Inherit submenu's popup delay time from parent menu + float pm_delay = pm->get_submenu_popup_delay(); + set_submenu_popup_delay(pm_delay); + } + } break; case NOTIFICATION_TRANSLATION_CHANGED: { for (int i = 0; i < items.size(); i++) { @@ -1201,6 +1210,19 @@ bool PopupMenu::is_hide_on_multistate_item_selection() const { return hide_on_multistate_item_selection; } +void PopupMenu::set_submenu_popup_delay(float p_time) { + + if (p_time <= 0) + p_time = 0.01; + + submenu_timer->set_wait_time(p_time); +} + +float PopupMenu::get_submenu_popup_delay() const { + + return submenu_timer->get_wait_time(); +} + String PopupMenu::get_tooltip(const Point2 &p_pos) const { int over = _get_mouse_over(p_pos); @@ -1303,12 +1325,15 @@ void PopupMenu::_bind_methods() { ClassDB::bind_method(D_METHOD("set_hide_on_state_item_selection", "enable"), &PopupMenu::set_hide_on_multistate_item_selection); ClassDB::bind_method(D_METHOD("is_hide_on_state_item_selection"), &PopupMenu::is_hide_on_multistate_item_selection); + ClassDB::bind_method(D_METHOD("set_submenu_popup_delay", "seconds"), &PopupMenu::set_submenu_popup_delay); + ClassDB::bind_method(D_METHOD("get_submenu_popup_delay"), &PopupMenu::get_submenu_popup_delay); ClassDB::bind_method(D_METHOD("_submenu_timeout"), &PopupMenu::_submenu_timeout); ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "items", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_items", "_get_items"); ADD_PROPERTYNO(PropertyInfo(Variant::BOOL, "hide_on_item_selection"), "set_hide_on_item_selection", "is_hide_on_item_selection"); ADD_PROPERTYNO(PropertyInfo(Variant::BOOL, "hide_on_checkable_item_selection"), "set_hide_on_checkable_item_selection", "is_hide_on_checkable_item_selection"); ADD_PROPERTYNO(PropertyInfo(Variant::BOOL, "hide_on_state_item_selection"), "set_hide_on_state_item_selection", "is_hide_on_state_item_selection"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "submenu_popup_delay"), "set_submenu_popup_delay", "get_submenu_popup_delay"); ADD_SIGNAL(MethodInfo("id_pressed", PropertyInfo(Variant::INT, "ID"))); ADD_SIGNAL(MethodInfo("id_focused", PropertyInfo(Variant::INT, "ID"))); diff --git a/scene/gui/popup_menu.h b/scene/gui/popup_menu.h index d3ee9be1c0..44f02a9d3d 100644 --- a/scene/gui/popup_menu.h +++ b/scene/gui/popup_menu.h @@ -202,6 +202,9 @@ public: void set_hide_on_multistate_item_selection(bool p_enabled); bool is_hide_on_multistate_item_selection() const; + void set_submenu_popup_delay(float p_time); + float get_submenu_popup_delay() const; + virtual void popup(const Rect2 &p_bounds = Rect2()); PopupMenu(); diff --git a/scene/gui/slider.cpp b/scene/gui/slider.cpp index 46215c9277..b820e2eafd 100644 --- a/scene/gui/slider.cpp +++ b/scene/gui/slider.cpp @@ -65,11 +65,12 @@ void Slider::_gui_input(Ref<InputEvent> p_event) { } else { grab.active = false; } - } else if (mb->is_pressed() && mb->get_button_index() == BUTTON_WHEEL_UP) { - - set_value(get_value() + get_step()); - } else if (mb->is_pressed() && mb->get_button_index() == BUTTON_WHEEL_DOWN) { - set_value(get_value() - get_step()); + } else if (scrollable) { + if (mb->is_pressed() && mb->get_button_index() == BUTTON_WHEEL_UP) { + set_value(get_value() + get_step()); + } else if (mb->is_pressed() && mb->get_button_index() == BUTTON_WHEEL_DOWN) { + set_value(get_value() - get_step()); + } } } @@ -247,6 +248,16 @@ bool Slider::is_editable() const { return editable; } +void Slider::set_scrollable(bool p_scrollable) { + + scrollable = p_scrollable; +} + +bool Slider::is_scrollable() const { + + return scrollable; +} + void Slider::_bind_methods() { ClassDB::bind_method(D_METHOD("_gui_input"), &Slider::_gui_input); @@ -258,8 +269,11 @@ void Slider::_bind_methods() { ClassDB::bind_method(D_METHOD("set_editable", "editable"), &Slider::set_editable); ClassDB::bind_method(D_METHOD("is_editable"), &Slider::is_editable); + ClassDB::bind_method(D_METHOD("set_scrollable", "scrollable"), &Slider::set_scrollable); + ClassDB::bind_method(D_METHOD("is_scrollable"), &Slider::is_scrollable); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editable"), "set_editable", "is_editable"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "scrollable"), "set_scrollable", "is_scrollable"); ADD_PROPERTY(PropertyInfo(Variant::INT, "tick_count", PROPERTY_HINT_RANGE, "0,4096,1"), "set_ticks", "get_ticks"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "ticks_on_borders"), "set_ticks_on_borders", "get_ticks_on_borders"); ADD_PROPERTY(PropertyInfo(Variant::INT, "focus_mode", PROPERTY_HINT_ENUM, "None,Click,All"), "set_focus_mode", "get_focus_mode"); @@ -272,5 +286,6 @@ Slider::Slider(Orientation p_orientation) { ticks = 0; custom_step = -1; editable = true; + scrollable = true; set_focus_mode(FOCUS_ALL); } diff --git a/scene/gui/slider.h b/scene/gui/slider.h index e77a0b7423..4d02348159 100644 --- a/scene/gui/slider.h +++ b/scene/gui/slider.h @@ -48,6 +48,7 @@ class Slider : public Range { Orientation orientation; float custom_step; bool editable; + bool scrollable; protected: void _gui_input(Ref<InputEvent> p_event); @@ -70,6 +71,9 @@ public: void set_editable(bool p_editable); bool is_editable() const; + void set_scrollable(bool p_scrollable); + bool is_scrollable() const; + Slider(Orientation p_orientation = VERTICAL); }; diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp index f42c1e0982..a0bac09442 100644 --- a/scene/register_scene_types.cpp +++ b/scene/register_scene_types.cpp @@ -135,6 +135,7 @@ #include "scene/resources/concave_polygon_shape_2d.h" #include "scene/resources/convex_polygon_shape.h" #include "scene/resources/convex_polygon_shape_2d.h" +#include "scene/resources/cylinder_shape.h" #include "scene/resources/default_theme/default_theme.h" #include "scene/resources/dynamic_font.h" #include "scene/resources/dynamic_font_stb.h" @@ -541,6 +542,7 @@ void register_scene_types() { ClassDB::register_class<SphereShape>(); ClassDB::register_class<BoxShape>(); ClassDB::register_class<CapsuleShape>(); + ClassDB::register_class<CylinderShape>(); ClassDB::register_class<PlaneShape>(); ClassDB::register_class<ConvexPolygonShape>(); ClassDB::register_class<ConcavePolygonShape>(); diff --git a/scene/resources/cylinder_shape.cpp b/scene/resources/cylinder_shape.cpp new file mode 100644 index 0000000000..f760462d49 --- /dev/null +++ b/scene/resources/cylinder_shape.cpp @@ -0,0 +1,116 @@ +/*************************************************************************/ +/* cylinder_shape.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "cylinder_shape.h" +#include "servers/physics_server.h" + +Vector<Vector3> CylinderShape::_gen_debug_mesh_lines() { + + float radius = get_radius(); + float height = get_height(); + + Vector<Vector3> points; + + Vector3 d(0, height * 0.5, 0); + for (int i = 0; i < 360; i++) { + + float ra = Math::deg2rad((float)i); + float rb = Math::deg2rad((float)i + 1); + Point2 a = Vector2(Math::sin(ra), Math::cos(ra)) * radius; + Point2 b = Vector2(Math::sin(rb), Math::cos(rb)) * radius; + + points.push_back(Vector3(a.x, 0, a.y) + d); + points.push_back(Vector3(b.x, 0, b.y) + d); + + points.push_back(Vector3(a.x, 0, a.y) - d); + points.push_back(Vector3(b.x, 0, b.y) - d); + + if (i % 90 == 0) { + + points.push_back(Vector3(a.x, 0, a.y) + d); + points.push_back(Vector3(a.x, 0, a.y) - d); + } + } + + return points; +} + +void CylinderShape::_update_shape() { + + Dictionary d; + d["radius"] = radius; + d["height"] = height; + PhysicsServer::get_singleton()->shape_set_data(get_shape(), d); +} + +void CylinderShape::set_radius(float p_radius) { + + radius = p_radius; + _update_shape(); + notify_change_to_owners(); + _change_notify("radius"); +} + +float CylinderShape::get_radius() const { + + return radius; +} + +void CylinderShape::set_height(float p_height) { + + height = p_height; + _update_shape(); + notify_change_to_owners(); + _change_notify("height"); +} + +float CylinderShape::get_height() const { + + return height; +} + +void CylinderShape::_bind_methods() { + + ClassDB::bind_method(D_METHOD("set_radius", "radius"), &CylinderShape::set_radius); + ClassDB::bind_method(D_METHOD("get_radius"), &CylinderShape::get_radius); + ClassDB::bind_method(D_METHOD("set_height", "height"), &CylinderShape::set_height); + ClassDB::bind_method(D_METHOD("get_height"), &CylinderShape::get_height); + + ADD_PROPERTY(PropertyInfo(Variant::REAL, "radius", PROPERTY_HINT_RANGE, "0.01,4096,0.01"), "set_radius", "get_radius"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "height", PROPERTY_HINT_RANGE, "0.01,4096,0.01"), "set_height", "get_height"); +} + +CylinderShape::CylinderShape() : + Shape(PhysicsServer::get_singleton()->shape_create(PhysicsServer::SHAPE_CYLINDER)) { + + radius = 1.0; + height = 2.0; + _update_shape(); +} diff --git a/scene/resources/cylinder_shape.h b/scene/resources/cylinder_shape.h new file mode 100644 index 0000000000..f510758e91 --- /dev/null +++ b/scene/resources/cylinder_shape.h @@ -0,0 +1,57 @@ +/*************************************************************************/ +/* cylinder_shape.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef CYLINDER_SHAPE_H +#define CYLINDER_SHAPE_H + +#include "scene/resources/shape.h" + +class CylinderShape : public Shape { + + GDCLASS(CylinderShape, Shape); + float radius; + float height; + +protected: + static void _bind_methods(); + virtual void _update_shape(); + + virtual Vector<Vector3> _gen_debug_mesh_lines(); + +public: + void set_radius(float p_radius); + float get_radius() const; + void set_height(float p_height); + float get_height() const; + + CylinderShape(); +}; + +#endif // CYLINDER_SHAPE_H |