1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
|
/*************************************************************************/
/* particles_2d.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#ifndef PARTICLES_FRAME_H
#define PARTICLES_FRAME_H
#include "scene/2d/node_2d.h"
#include "scene/resources/texture.h"
#include "scene/resources/color_ramp.h"
class Particles2D;
class ParticleAttractor2D : public Node2D {
OBJ_TYPE(ParticleAttractor2D,Node2D);
friend class Particles2D;
bool enabled;
float radius;
float disable_radius;
float gravity;
float absorption;
NodePath path;
Particles2D *owner;
void _update_owner();
void _owner_exited();
void _set_owner(Particles2D* p_owner);
void _notification(int p_what);
static void _bind_methods();
public:
void set_enabled(bool p_enabled);
bool is_enabled() const;
void set_radius(float p_radius);
float get_radius() const;
void set_disable_radius(float p_disable_radius);
float get_disable_radius() const;
void set_gravity(float p_gravity);
float get_gravity() const;
void set_absorption(float p_absorption);
float get_absorption() const;
void set_particles_path(NodePath p_path);
NodePath get_particles_path() const;
virtual String get_configuration_warning() const;
ParticleAttractor2D();
};
class Particles2D : public Node2D {
OBJ_TYPE(Particles2D, Node2D);
public:
enum Parameter {
PARAM_DIRECTION,
PARAM_SPREAD,
PARAM_LINEAR_VELOCITY,
PARAM_SPIN_VELOCITY,
PARAM_ORBIT_VELOCITY,
PARAM_GRAVITY_DIRECTION,
PARAM_GRAVITY_STRENGTH,
PARAM_RADIAL_ACCEL,
PARAM_TANGENTIAL_ACCEL,
PARAM_DAMPING,
PARAM_INITIAL_ANGLE,
PARAM_INITIAL_SIZE,
PARAM_FINAL_SIZE,
PARAM_HUE_VARIATION,
PARAM_ANIM_SPEED_SCALE,
PARAM_ANIM_INITIAL_POS,
PARAM_MAX
};
enum {
MAX_COLOR_PHASES=4
};
private:
float param[PARAM_MAX];
float randomness[PARAM_MAX];
struct Particle {
bool active;
Point2 pos;
Vector2 velocity;
float rot;
float frame;
uint32_t seed;
Particle() { active=false; seed=123465789; rot=0; frame=0;}
};
Vector<Particle> particles;
struct AttractorCache {
Vector2 pos;
ParticleAttractor2D *attractor;
};
Vector<AttractorCache> attractor_cache;
float explosiveness;
float preprocess;
float lifetime;
bool emitting;
bool local_space;
float emit_timeout;
float time_to_live;
float time_scale;
bool flip_h;
bool flip_v;
int h_frames;
int v_frames;
Point2 emissor_offset;
Vector2 initial_velocity;
Vector2 extents;
DVector<Vector2> emission_points;
float time;
int active_count;
Ref<Texture> texture;
//If no color ramp is set then default color is used. Created as simple alternative to color_ramp.
Color default_color;
Ref<ColorRamp> color_ramp;
void testee(int a, int b, int c, int d, int e);
void _process_particles(float p_delta);
friend class ParticleAttractor2D;
Set<ParticleAttractor2D*> attractors;
protected:
void _notification(int p_what);
static void _bind_methods();
public:
void set_emitting(bool p_emitting);
bool is_emitting() const;
void set_amount(int p_amount);
int get_amount() const;
void set_lifetime(float p_lifetime);
float get_lifetime() const;
void set_time_scale(float p_time_scale);
float get_time_scale() const;
void set_pre_process_time(float p_pre_process_time);
float get_pre_process_time() const;
void set_emit_timeout(float p_timeout);
float get_emit_timeout() const;
void set_emission_half_extents(const Vector2& p_extents);
Vector2 get_emission_half_extents() const;
void set_param(Parameter p_param, float p_value);
float get_param(Parameter p_param) const;
void set_randomness(Parameter p_randomness, float p_value);
float get_randomness(Parameter p_randomness) const;
void set_explosiveness(float p_value);
float get_explosiveness() const;
void set_flip_h(bool p_flip);
bool is_flipped_h() const;
void set_flip_v(bool p_flip);
bool is_flipped_v() const;
void set_h_frames(int p_frames);
int get_h_frames() const;
void set_v_frames(int p_frames);
int get_v_frames() const;
void set_color_phases(int p_phases);
int get_color_phases() const;
void set_color_phase_color(int p_phase,const Color& p_color);
Color get_color_phase_color(int p_phase) const;
void set_color_phase_pos(int p_phase,float p_pos);
float get_color_phase_pos(int p_phase) const;
void set_texture(const Ref<Texture>& p_texture);
Ref<Texture> get_texture() const;
void set_color(const Color& p_color);
Color get_color() const;
void set_color_ramp(const Ref<ColorRamp>& p_texture);
Ref<ColorRamp> get_color_ramp() const;
void set_emissor_offset(const Point2& p_offset);
Point2 get_emissor_offset() const;
void set_use_local_space(bool p_use);
bool is_using_local_space() const;
void set_initial_velocity(const Vector2& p_velocity);
Vector2 get_initial_velocity() const;
void set_emission_points(const DVector<Vector2>& p_points);
DVector<Vector2> get_emission_points() const;
void pre_process(float p_delta);
void reset();
Particles2D();
};
VARIANT_ENUM_CAST( Particles2D::Parameter );
#endif // PARTICLES_FRAME_H
|