path.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*************************************************************************/
  2. /* path.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
  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. #ifndef PATH_H
  31. #define PATH_H
  32. #include "scene/3d/spatial.h"
  33. #include "scene/resources/curve.h"
  34. class Path : public Spatial {
  35. GDCLASS(Path, Spatial);
  36. Ref<Curve3D> curve;
  37. void _curve_changed();
  38. protected:
  39. void _notification(int p_what);
  40. static void _bind_methods();
  41. public:
  42. void set_curve(const Ref<Curve3D> &p_curve);
  43. Ref<Curve3D> get_curve() const;
  44. Path();
  45. };
  46. class PathFollow : public Spatial {
  47. GDCLASS(PathFollow, Spatial);
  48. public:
  49. enum RotationMode {
  50. ROTATION_NONE,
  51. ROTATION_Y,
  52. ROTATION_XY,
  53. ROTATION_XYZ
  54. };
  55. private:
  56. Path *path;
  57. real_t delta_offset; // change in offset since last _update_transform
  58. real_t offset;
  59. real_t h_offset;
  60. real_t v_offset;
  61. bool cubic;
  62. bool loop;
  63. RotationMode rotation_mode;
  64. void _update_transform();
  65. protected:
  66. virtual void _validate_property(PropertyInfo &property) const;
  67. void _notification(int p_what);
  68. static void _bind_methods();
  69. public:
  70. void set_offset(float p_offset);
  71. float get_offset() const;
  72. void set_h_offset(float p_h_offset);
  73. float get_h_offset() const;
  74. void set_v_offset(float p_v_offset);
  75. float get_v_offset() const;
  76. void set_unit_offset(float p_unit_offset);
  77. float get_unit_offset() const;
  78. void set_loop(bool p_loop);
  79. bool has_loop() const;
  80. void set_rotation_mode(RotationMode p_rotation_mode);
  81. RotationMode get_rotation_mode() const;
  82. void set_cubic_interpolation(bool p_enable);
  83. bool get_cubic_interpolation() const;
  84. String get_configuration_warning() const;
  85. PathFollow();
  86. };
  87. VARIANT_ENUM_CAST(PathFollow::RotationMode);
  88. class OrientedPathFollow : public Spatial {
  89. GDCLASS(OrientedPathFollow, Spatial);
  90. private:
  91. Path *path;
  92. real_t delta_offset; // change in offset since last _update_transform
  93. real_t offset;
  94. real_t h_offset;
  95. real_t v_offset;
  96. bool cubic;
  97. bool loop;
  98. void _update_transform();
  99. protected:
  100. virtual void _validate_property(PropertyInfo &property) const;
  101. void _notification(int p_what);
  102. static void _bind_methods();
  103. public:
  104. void set_offset(float p_offset);
  105. float get_offset() const;
  106. void set_h_offset(float p_h_offset);
  107. float get_h_offset() const;
  108. void set_v_offset(float p_v_offset);
  109. float get_v_offset() const;
  110. void set_unit_offset(float p_unit_offset);
  111. float get_unit_offset() const;
  112. void set_loop(bool p_loop);
  113. bool has_loop() const;
  114. void set_cubic_interpolation(bool p_enable);
  115. bool get_cubic_interpolation() const;
  116. String get_configuration_warning() const;
  117. OrientedPathFollow();
  118. };
  119. #endif // PATH_H