openxr_haptic_feedback.cpp 4.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. #include "openxr_haptic_feedback.h"
  31. ////////////////////////////////////////////////////////////////////////////
  32. // OpenXRHapticBase
  33. void OpenXRHapticBase::_bind_methods() {
  34. }
  35. ////////////////////////////////////////////////////////////////////////////
  36. // OpenXRHapticVibration
  37. void OpenXRHapticVibration::_bind_methods() {
  38. ClassDB::bind_method(D_METHOD("set_duration", "duration"), &OpenXRHapticVibration::set_duration);
  39. ClassDB::bind_method(D_METHOD("get_duration"), &OpenXRHapticVibration::get_duration);
  40. ADD_PROPERTY(PropertyInfo(Variant::INT, "duration"), "set_duration", "get_duration");
  41. ClassDB::bind_method(D_METHOD("set_frequency", "frequency"), &OpenXRHapticVibration::set_frequency);
  42. ClassDB::bind_method(D_METHOD("get_frequency"), &OpenXRHapticVibration::get_frequency);
  43. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "frequency"), "set_frequency", "get_frequency");
  44. ClassDB::bind_method(D_METHOD("set_amplitude", "amplitude"), &OpenXRHapticVibration::set_amplitude);
  45. ClassDB::bind_method(D_METHOD("get_amplitude"), &OpenXRHapticVibration::get_amplitude);
  46. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "amplitude", PROPERTY_HINT_RANGE, "0.0,1.0,0.01"), "set_amplitude", "get_amplitude");
  47. }
  48. void OpenXRHapticVibration::set_duration(int64_t p_duration) {
  49. haptic_vibration.duration = p_duration;
  50. emit_changed();
  51. }
  52. int64_t OpenXRHapticVibration::get_duration() const {
  53. return haptic_vibration.duration;
  54. }
  55. void OpenXRHapticVibration::set_frequency(float p_frequency) {
  56. haptic_vibration.frequency = p_frequency;
  57. emit_changed();
  58. }
  59. float OpenXRHapticVibration::get_frequency() const {
  60. return haptic_vibration.frequency;
  61. }
  62. void OpenXRHapticVibration::set_amplitude(float p_amplitude) {
  63. haptic_vibration.amplitude = p_amplitude;
  64. emit_changed();
  65. }
  66. float OpenXRHapticVibration::get_amplitude() const {
  67. return haptic_vibration.amplitude;
  68. }
  69. const XrHapticBaseHeader *OpenXRHapticVibration::get_xr_structure() {
  70. return (XrHapticBaseHeader *)&haptic_vibration;
  71. }
  72. OpenXRHapticVibration::OpenXRHapticVibration() {
  73. haptic_vibration.type = XR_TYPE_HAPTIC_VIBRATION;
  74. haptic_vibration.next = nullptr;
  75. haptic_vibration.duration = -1;
  76. haptic_vibration.frequency = 0.0;
  77. haptic_vibration.amplitude = 1.0;
  78. }