curve.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /*************************************************************************/
  2. /* curve.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #ifndef CURVE_H
  30. #define CURVE_H
  31. #include "resource.h"
  32. #if 0
  33. class Curve2D : public Resource {
  34. OBJ_TYPE(Curve2D,Resource);
  35. struct Point {
  36. Vector2 in;
  37. Vector2 out;
  38. Vector2 pos;
  39. };
  40. Vector<Point> points;
  41. protected:
  42. static void _bind_methods();
  43. void set_points_in(const Vector2Array& p_points_in);
  44. void set_points_out(const Vector2Array& p_points_out);
  45. void set_points_pos(const Vector2Array& p_points_pos);
  46. Vector2Array get_points_in() const;
  47. Vector2Array get_points_out() const;
  48. Vector2Array get_points_pos() const;
  49. public:
  50. int get_point_count() const;
  51. void add_point(const Vector2& p_pos, const Vector2& p_in=Vector2(), const Vector2& p_out=Vector2());
  52. void set_point_pos(int p_index, const Vector2& p_pos);
  53. Vector2 get_point_pos(int p_index) const;
  54. void set_point_in(int p_index, const Vector2& p_in);
  55. Vector2 get_point_in(int p_index) const;
  56. void set_point_out(int p_index, const Vector2& p_out);
  57. Vector2 get_point_out(int p_index) const;
  58. void remove_point(int p_index);
  59. Vector2 interpolate(int p_index, float p_offset) const;
  60. Vector2 interpolatef(real_t p_findex) const;
  61. DVector<Point2> bake(int p_subdivs=10) const;
  62. void advance(real_t p_distance,int &r_index, real_t &r_pos) const;
  63. void get_approx_position_from_offset(real_t p_offset,int &r_index, real_t &r_pos,int p_subdivs=16) const;
  64. Curve2D();
  65. };
  66. #endif
  67. class Curve2D : public Resource {
  68. OBJ_TYPE(Curve2D,Resource);
  69. struct Point {
  70. Vector2 in;
  71. Vector2 out;
  72. Vector2 pos;
  73. };
  74. Vector<Point> points;
  75. struct BakedPoint {
  76. float ofs;
  77. Vector2 point;
  78. };
  79. mutable bool baked_cache_dirty;
  80. mutable Vector2Array baked_point_cache;
  81. mutable float baked_max_ofs;
  82. void _bake() const;
  83. float bake_interval;
  84. 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;
  85. Dictionary _get_data() const;
  86. void _set_data(const Dictionary &p_data);
  87. protected:
  88. static void _bind_methods();
  89. public:
  90. int get_point_count() const;
  91. void add_point(const Vector2& p_pos, const Vector2& p_in=Vector2(), const Vector2& p_out=Vector2(),int p_atpos=-1);
  92. void set_point_pos(int p_index, const Vector2& p_pos);
  93. Vector2 get_point_pos(int p_index) const;
  94. void set_point_in(int p_index, const Vector2& p_in);
  95. Vector2 get_point_in(int p_index) const;
  96. void set_point_out(int p_index, const Vector2& p_out);
  97. Vector2 get_point_out(int p_index) const;
  98. void remove_point(int p_index);
  99. Vector2 interpolate(int p_index, float p_offset) const;
  100. Vector2 interpolatef(real_t p_findex) const;
  101. void set_bake_interval(float p_distance);
  102. float get_bake_interval() const;
  103. float get_baked_length() const;
  104. Vector2 interpolate_baked(float p_offset,bool p_cubic=false) const;
  105. Vector2Array get_baked_points() const; //useful for going thru
  106. Vector2Array tesselate(int p_max_stages=5,float p_tolerance=4) const; //useful for display
  107. Curve2D();
  108. };
  109. class Curve3D : public Resource {
  110. OBJ_TYPE(Curve3D,Resource);
  111. struct Point {
  112. Vector3 in;
  113. Vector3 out;
  114. Vector3 pos;
  115. float tilt;
  116. Point() { tilt=0; }
  117. };
  118. Vector<Point> points;
  119. struct BakedPoint {
  120. float ofs;
  121. Vector3 point;
  122. };
  123. mutable bool baked_cache_dirty;
  124. mutable Vector3Array baked_point_cache;
  125. mutable RealArray baked_tilt_cache;
  126. mutable float baked_max_ofs;
  127. void _bake() const;
  128. float bake_interval;
  129. 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;
  130. Dictionary _get_data() const;
  131. void _set_data(const Dictionary &p_data);
  132. protected:
  133. static void _bind_methods();
  134. public:
  135. int get_point_count() const;
  136. void add_point(const Vector3& p_pos, const Vector3& p_in=Vector3(), const Vector3& p_out=Vector3(),int p_atpos=-1);
  137. void set_point_pos(int p_index, const Vector3& p_pos);
  138. Vector3 get_point_pos(int p_index) const;
  139. void set_point_tilt(int p_index, float p_tilt);
  140. float get_point_tilt(int p_index) const;
  141. void set_point_in(int p_index, const Vector3& p_in);
  142. Vector3 get_point_in(int p_index) const;
  143. void set_point_out(int p_index, const Vector3& p_out);
  144. Vector3 get_point_out(int p_index) const;
  145. void remove_point(int p_index);
  146. Vector3 interpolate(int p_index, float p_offset) const;
  147. Vector3 interpolatef(real_t p_findex) const;
  148. void set_bake_interval(float p_distance);
  149. float get_bake_interval() const;
  150. float get_baked_length() const;
  151. Vector3 interpolate_baked(float p_offset,bool p_cubic=false) const;
  152. float interpolate_baked_tilt(float p_offset) const;
  153. Vector3Array get_baked_points() const; //useful for going thru
  154. RealArray get_baked_tilts() const; //useful for going thru
  155. Vector3Array tesselate(int p_max_stages=5,float p_tolerance=4) const; //useful for display
  156. Curve3D();
  157. };
  158. #endif // CURVE_H