curve.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*************************************************************************/
  2. /* curve.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 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 CURVE_H
  31. #define CURVE_H
  32. #include "resource.h"
  33. #if 0
  34. class Curve2D : public Resource {
  35. OBJ_TYPE(Curve2D,Resource);
  36. struct Point {
  37. Vector2 in;
  38. Vector2 out;
  39. Vector2 pos;
  40. };
  41. Vector<Point> points;
  42. protected:
  43. static void _bind_methods();
  44. void set_points_in(const Vector2Array& p_points_in);
  45. void set_points_out(const Vector2Array& p_points_out);
  46. void set_points_pos(const Vector2Array& p_points_pos);
  47. Vector2Array get_points_in() const;
  48. Vector2Array get_points_out() const;
  49. Vector2Array get_points_pos() const;
  50. public:
  51. int get_point_count() const;
  52. void add_point(const Vector2& p_pos, const Vector2& p_in=Vector2(), const Vector2& p_out=Vector2());
  53. void set_point_pos(int p_index, const Vector2& p_pos);
  54. Vector2 get_point_pos(int p_index) const;
  55. void set_point_in(int p_index, const Vector2& p_in);
  56. Vector2 get_point_in(int p_index) const;
  57. void set_point_out(int p_index, const Vector2& p_out);
  58. Vector2 get_point_out(int p_index) const;
  59. void remove_point(int p_index);
  60. Vector2 interpolate(int p_index, float p_offset) const;
  61. Vector2 interpolatef(real_t p_findex) const;
  62. DVector<Point2> bake(int p_subdivs=10) const;
  63. void advance(real_t p_distance,int &r_index, real_t &r_pos) const;
  64. void get_approx_position_from_offset(real_t p_offset,int &r_index, real_t &r_pos,int p_subdivs=16) const;
  65. Curve2D();
  66. };
  67. #endif
  68. class Curve2D : public Resource {
  69. OBJ_TYPE(Curve2D, Resource);
  70. struct Point {
  71. Vector2 in;
  72. Vector2 out;
  73. Vector2 pos;
  74. };
  75. Vector<Point> points;
  76. struct BakedPoint {
  77. float ofs;
  78. Vector2 point;
  79. };
  80. mutable bool baked_cache_dirty;
  81. mutable Vector2Array baked_point_cache;
  82. mutable float baked_max_ofs;
  83. void _bake() const;
  84. float bake_interval;
  85. void _bake_segment2d(Map<float, Vector2> &r_bake, float p_begin, float p_end, const Vector2 &p_a, const Vector2 &p_out, const Vector2 &p_b, const Vector2 &p_in, int p_depth, int p_max_depth, float p_tol) const;
  86. Dictionary _get_data() const;
  87. void _set_data(const Dictionary &p_data);
  88. protected:
  89. static void _bind_methods();
  90. public:
  91. int get_point_count() const;
  92. void add_point(const Vector2 &p_pos, const Vector2 &p_in = Vector2(), const Vector2 &p_out = Vector2(), int p_atpos = -1);
  93. void set_point_pos(int p_index, const Vector2 &p_pos);
  94. Vector2 get_point_pos(int p_index) const;
  95. void set_point_in(int p_index, const Vector2 &p_in);
  96. Vector2 get_point_in(int p_index) const;
  97. void set_point_out(int p_index, const Vector2 &p_out);
  98. Vector2 get_point_out(int p_index) const;
  99. void remove_point(int p_index);
  100. void clear_points();
  101. Vector2 interpolate(int p_index, float p_offset) const;
  102. Vector2 interpolatef(real_t p_findex) const;
  103. void set_bake_interval(float p_distance);
  104. float get_bake_interval() const;
  105. float get_baked_length() const;
  106. Vector2 interpolate_baked(float p_offset, bool p_cubic = false) const;
  107. Vector2Array get_baked_points() const; //useful for going thru
  108. Vector2Array tesselate(int p_max_stages = 5, float p_tolerance = 4) const; //useful for display
  109. Curve2D();
  110. };
  111. class Curve3D : public Resource {
  112. OBJ_TYPE(Curve3D, Resource);
  113. struct Point {
  114. Vector3 in;
  115. Vector3 out;
  116. Vector3 pos;
  117. float tilt;
  118. Point() { tilt = 0; }
  119. };
  120. Vector<Point> points;
  121. struct BakedPoint {
  122. float ofs;
  123. Vector3 point;
  124. };
  125. mutable bool baked_cache_dirty;
  126. mutable Vector3Array baked_point_cache;
  127. mutable RealArray baked_tilt_cache;
  128. mutable float baked_max_ofs;
  129. void _bake() const;
  130. float bake_interval;
  131. void _bake_segment3d(Map<float, Vector3> &r_bake, float p_begin, float p_end, const Vector3 &p_a, const Vector3 &p_out, const Vector3 &p_b, const Vector3 &p_in, int p_depth, int p_max_depth, float p_tol) const;
  132. Dictionary _get_data() const;
  133. void _set_data(const Dictionary &p_data);
  134. protected:
  135. static void _bind_methods();
  136. public:
  137. int get_point_count() const;
  138. void add_point(const Vector3 &p_pos, const Vector3 &p_in = Vector3(), const Vector3 &p_out = Vector3(), int p_atpos = -1);
  139. void set_point_pos(int p_index, const Vector3 &p_pos);
  140. Vector3 get_point_pos(int p_index) const;
  141. void set_point_tilt(int p_index, float p_tilt);
  142. float get_point_tilt(int p_index) const;
  143. void set_point_in(int p_index, const Vector3 &p_in);
  144. Vector3 get_point_in(int p_index) const;
  145. void set_point_out(int p_index, const Vector3 &p_out);
  146. Vector3 get_point_out(int p_index) const;
  147. void remove_point(int p_index);
  148. void clear_points();
  149. Vector3 interpolate(int p_index, float p_offset) const;
  150. Vector3 interpolatef(real_t p_findex) const;
  151. void set_bake_interval(float p_distance);
  152. float get_bake_interval() const;
  153. float get_baked_length() const;
  154. Vector3 interpolate_baked(float p_offset, bool p_cubic = false) const;
  155. float interpolate_baked_tilt(float p_offset) const;
  156. Vector3Array get_baked_points() const; //useful for going thru
  157. RealArray get_baked_tilts() const; //useful for going thru
  158. Vector3Array tesselate(int p_max_stages = 5, float p_tolerance = 4) const; //useful for display
  159. Curve3D();
  160. };
  161. #endif // CURVE_H