| 1 | /**************************************************************************/ |
| 2 | /* openxr_haptic_feedback.cpp */ |
| 3 | /**************************************************************************/ |
| 4 | /* This file is part of: */ |
| 5 | /* GODOT ENGINE */ |
| 6 | /* https://godotengine.org */ |
| 7 | /**************************************************************************/ |
| 8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
| 9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
| 10 | /* */ |
| 11 | /* Permission is hereby granted, free of charge, to any person obtaining */ |
| 12 | /* a copy of this software and associated documentation files (the */ |
| 13 | /* "Software"), to deal in the Software without restriction, including */ |
| 14 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
| 15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ |
| 16 | /* permit persons to whom the Software is furnished to do so, subject to */ |
| 17 | /* the following conditions: */ |
| 18 | /* */ |
| 19 | /* The above copyright notice and this permission notice shall be */ |
| 20 | /* included in all copies or substantial portions of the Software. */ |
| 21 | /* */ |
| 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
| 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
| 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
| 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
| 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
| 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
| 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
| 29 | /**************************************************************************/ |
| 30 | |
| 31 | #include "openxr_haptic_feedback.h" |
| 32 | |
| 33 | //////////////////////////////////////////////////////////////////////////// |
| 34 | // OpenXRHapticBase |
| 35 | |
| 36 | void OpenXRHapticBase::_bind_methods() { |
| 37 | } |
| 38 | |
| 39 | //////////////////////////////////////////////////////////////////////////// |
| 40 | // OpenXRHapticVibration |
| 41 | |
| 42 | void OpenXRHapticVibration::_bind_methods() { |
| 43 | ClassDB::bind_method(D_METHOD("set_duration", "duration"), &OpenXRHapticVibration::set_duration); |
| 44 | ClassDB::bind_method(D_METHOD("get_duration"), &OpenXRHapticVibration::get_duration); |
| 45 | ADD_PROPERTY(PropertyInfo(Variant::INT, "duration"), "set_duration", "get_duration"); |
| 46 | |
| 47 | ClassDB::bind_method(D_METHOD("set_frequency", "frequency"), &OpenXRHapticVibration::set_frequency); |
| 48 | ClassDB::bind_method(D_METHOD("get_frequency"), &OpenXRHapticVibration::get_frequency); |
| 49 | ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "frequency"), "set_frequency", "get_frequency"); |
| 50 | |
| 51 | ClassDB::bind_method(D_METHOD("set_amplitude", "amplitude"), &OpenXRHapticVibration::set_amplitude); |
| 52 | ClassDB::bind_method(D_METHOD("get_amplitude"), &OpenXRHapticVibration::get_amplitude); |
| 53 | ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "amplitude", PROPERTY_HINT_RANGE, "0.0,1.0,0.01"), "set_amplitude", "get_amplitude"); |
| 54 | } |
| 55 | |
| 56 | void OpenXRHapticVibration::set_duration(int64_t p_duration) { |
| 57 | haptic_vibration.duration = p_duration; |
| 58 | emit_changed(); |
| 59 | } |
| 60 | |
| 61 | int64_t OpenXRHapticVibration::get_duration() const { |
| 62 | return haptic_vibration.duration; |
| 63 | } |
| 64 | |
| 65 | void OpenXRHapticVibration::set_frequency(float p_frequency) { |
| 66 | haptic_vibration.frequency = p_frequency; |
| 67 | emit_changed(); |
| 68 | } |
| 69 | |
| 70 | float OpenXRHapticVibration::get_frequency() const { |
| 71 | return haptic_vibration.frequency; |
| 72 | } |
| 73 | |
| 74 | void OpenXRHapticVibration::set_amplitude(float p_amplitude) { |
| 75 | haptic_vibration.amplitude = p_amplitude; |
| 76 | emit_changed(); |
| 77 | } |
| 78 | |
| 79 | float OpenXRHapticVibration::get_amplitude() const { |
| 80 | return haptic_vibration.amplitude; |
| 81 | } |
| 82 | |
| 83 | const XrHapticBaseHeader *OpenXRHapticVibration::get_xr_structure() { |
| 84 | return (XrHapticBaseHeader *)&haptic_vibration; |
| 85 | } |
| 86 | |
| 87 | OpenXRHapticVibration::OpenXRHapticVibration() { |
| 88 | haptic_vibration.type = XR_TYPE_HAPTIC_VIBRATION; |
| 89 | haptic_vibration.next = nullptr; |
| 90 | haptic_vibration.duration = -1; |
| 91 | haptic_vibration.frequency = 0.0; |
| 92 | haptic_vibration.amplitude = 1.0; |
| 93 | } |