curve.h
1 /*************************************************************************/
2 /* curve.h */
3 /*************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* http://www.godotengine.org */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2016 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 
32 #include "resource.h"
33 #if 0
34 class Curve2D : public Resource {
35 
36  OBJ_TYPE(Curve2D,Resource);
37 
38  struct Point {
39 
40  Vector2 in;
41  Vector2 out;
42  Vector2 pos;
43  };
44 
45 
46  Vector<Point> points;
47 
48 protected:
49 
50  static void _bind_methods();
51 
52  void set_points_in(const Vector2Array& p_points_in);
53  void set_points_out(const Vector2Array& p_points_out);
54  void set_points_pos(const Vector2Array& p_points_pos);
55 
56  Vector2Array get_points_in() const;
57  Vector2Array get_points_out() const;
58  Vector2Array get_points_pos() const;
59 
60 public:
61 
62 
63  int get_point_count() const;
64  void add_point(const Vector2& p_pos, const Vector2& p_in=Vector2(), const Vector2& p_out=Vector2());
65  void set_point_pos(int p_index, const Vector2& p_pos);
66  Vector2 get_point_pos(int p_index) const;
67  void set_point_in(int p_index, const Vector2& p_in);
68  Vector2 get_point_in(int p_index) const;
69  void set_point_out(int p_index, const Vector2& p_out);
70  Vector2 get_point_out(int p_index) const;
71  void remove_point(int p_index);
72 
73  Vector2 interpolate(int p_index, float p_offset) const;
74  Vector2 interpolatef(real_t p_findex) const;
75  DVector<Point2> bake(int p_subdivs=10) const;
76  void advance(real_t p_distance,int &r_index, real_t &r_pos) const;
77  void get_approx_position_from_offset(real_t p_offset,int &r_index, real_t &r_pos,int p_subdivs=16) const;
78 
79  Curve2D();
80 };
81 
82 #endif
83 
84 
85 class Curve2D : public Resource {
86 
87  OBJ_TYPE(Curve2D,Resource);
88 
89  struct Point {
90 
91  Vector2 in;
92  Vector2 out;
93  Vector2 pos;
94  };
95 
96 
97  Vector<Point> points;
98 
99  struct BakedPoint {
100 
101  float ofs;
102  Vector2 point;
103  };
104 
105  mutable bool baked_cache_dirty;
106  mutable Vector2Array baked_point_cache;
107  mutable float baked_max_ofs;
108 
109 
110  void _bake() const;
111 
112  float bake_interval;
113 
114  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;
115  Dictionary _get_data() const;
116  void _set_data(const Dictionary &p_data);
117 
118 protected:
119 
120  static void _bind_methods();
121 
122 
123 
124 public:
125 
126 
127  int get_point_count() const;
128  void add_point(const Vector2& p_pos, const Vector2& p_in=Vector2(), const Vector2& p_out=Vector2(),int p_atpos=-1);
129  void set_point_pos(int p_index, const Vector2& p_pos);
130  Vector2 get_point_pos(int p_index) const;
131  void set_point_in(int p_index, const Vector2& p_in);
132  Vector2 get_point_in(int p_index) const;
133  void set_point_out(int p_index, const Vector2& p_out);
134  Vector2 get_point_out(int p_index) const;
135  void remove_point(int p_index);
136 
137  Vector2 interpolate(int p_index, float p_offset) const;
138  Vector2 interpolatef(real_t p_findex) const;
139 
140 
141  void set_bake_interval(float p_distance);
142  float get_bake_interval() const;
143 
144 
145  float get_baked_length() const;
146  Vector2 interpolate_baked(float p_offset,bool p_cubic=false) const;
147  Vector2Array get_baked_points() const; //useful for going thru
148 
149  Vector2Array tesselate(int p_max_stages=5,float p_tolerance=4) const; //useful for display
150 
151 
152  Curve2D();
153 };
154 
155 
156 
157 class Curve3D : public Resource {
158 
159  OBJ_TYPE(Curve3D,Resource);
160 
161  struct Point {
162 
163  Vector3 in;
164  Vector3 out;
165  Vector3 pos;
166  float tilt;
167 
168  Point() { tilt=0; }
169  };
170 
171 
172  Vector<Point> points;
173 
174  struct BakedPoint {
175 
176  float ofs;
177  Vector3 point;
178  };
179 
180  mutable bool baked_cache_dirty;
181  mutable Vector3Array baked_point_cache;
182  mutable RealArray baked_tilt_cache;
183  mutable float baked_max_ofs;
184 
185 
186  void _bake() const;
187 
188  float bake_interval;
189 
190  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;
191  Dictionary _get_data() const;
192  void _set_data(const Dictionary &p_data);
193 
194 protected:
195 
196  static void _bind_methods();
197 
198 
199 
200 public:
201 
202 
203  int get_point_count() const;
204  void add_point(const Vector3& p_pos, const Vector3& p_in=Vector3(), const Vector3& p_out=Vector3(),int p_atpos=-1);
205  void set_point_pos(int p_index, const Vector3& p_pos);
206  Vector3 get_point_pos(int p_index) const;
207  void set_point_tilt(int p_index, float p_tilt);
208  float get_point_tilt(int p_index) const;
209  void set_point_in(int p_index, const Vector3& p_in);
210  Vector3 get_point_in(int p_index) const;
211  void set_point_out(int p_index, const Vector3& p_out);
212  Vector3 get_point_out(int p_index) const;
213  void remove_point(int p_index);
214 
215  Vector3 interpolate(int p_index, float p_offset) const;
216  Vector3 interpolatef(real_t p_findex) const;
217 
218 
219  void set_bake_interval(float p_distance);
220  float get_bake_interval() const;
221 
222 
223  float get_baked_length() const;
224  Vector3 interpolate_baked(float p_offset,bool p_cubic=false) const;
225  float interpolate_baked_tilt(float p_offset) const;
226  Vector3Array get_baked_points() const; //useful for going thru
227  RealArray get_baked_tilts() const; //useful for going thru
228 
229  Vector3Array tesselate(int p_max_stages=5,float p_tolerance=4) const; //useful for display
230 
231 
232  Curve3D();
233 };
234 
235 #endif // CURVE_H
Definition: curve.h:85
Definition: curve.h:157
Definition: vector3.h:38
Definition: resource.h:89
Definition: map.h:41
Definition: dictionary.h:42
Definition: math_2d.h:65