2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* particles_2d.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
2017-01-01 21:01:57 +00:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2017-04-07 22:11:42 +00:00
|
|
|
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-02-10 01:10:30 +00:00
|
|
|
/* */
|
|
|
|
/* 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"
|
2015-05-24 18:18:52 +00:00
|
|
|
#include "scene/resources/color_ramp.h"
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "scene/resources/texture.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
class Particles2D;
|
|
|
|
class ParticleAttractor2D : public Node2D {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GDCLASS(ParticleAttractor2D, Node2D);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
friend class Particles2D;
|
2014-02-10 01:10:30 +00:00
|
|
|
bool enabled;
|
|
|
|
float radius;
|
|
|
|
float disable_radius;
|
|
|
|
float gravity;
|
|
|
|
float absorption;
|
|
|
|
NodePath path;
|
|
|
|
|
|
|
|
Particles2D *owner;
|
|
|
|
|
|
|
|
void _update_owner();
|
|
|
|
void _owner_exited();
|
2017-03-05 15:44:50 +00:00
|
|
|
void _set_owner(Particles2D *p_owner);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
void _notification(int p_what);
|
|
|
|
static void _bind_methods();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
public:
|
2014-02-10 01:10:30 +00:00
|
|
|
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;
|
|
|
|
|
2016-05-17 21:27:15 +00:00
|
|
|
virtual String get_configuration_warning() const;
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
ParticleAttractor2D();
|
|
|
|
};
|
|
|
|
|
|
|
|
class Particles2D : public Node2D {
|
|
|
|
|
2017-01-03 02:03:46 +00:00
|
|
|
GDCLASS(Particles2D, Node2D);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
public:
|
2014-02-10 01:10:30 +00:00
|
|
|
enum Parameter {
|
|
|
|
PARAM_DIRECTION,
|
|
|
|
PARAM_SPREAD,
|
2016-03-08 23:00:52 +00:00
|
|
|
PARAM_LINEAR_VELOCITY,
|
2014-02-10 01:10:30 +00:00
|
|
|
PARAM_SPIN_VELOCITY,
|
|
|
|
PARAM_ORBIT_VELOCITY,
|
|
|
|
PARAM_GRAVITY_DIRECTION,
|
|
|
|
PARAM_GRAVITY_STRENGTH,
|
|
|
|
PARAM_RADIAL_ACCEL,
|
|
|
|
PARAM_TANGENTIAL_ACCEL,
|
|
|
|
PARAM_DAMPING,
|
2014-09-19 21:39:50 +00:00
|
|
|
PARAM_INITIAL_ANGLE,
|
2014-02-10 01:10:30 +00:00
|
|
|
PARAM_INITIAL_SIZE,
|
|
|
|
PARAM_FINAL_SIZE,
|
|
|
|
PARAM_HUE_VARIATION,
|
2014-11-17 10:46:11 +00:00
|
|
|
PARAM_ANIM_SPEED_SCALE,
|
|
|
|
PARAM_ANIM_INITIAL_POS,
|
2014-02-10 01:10:30 +00:00
|
|
|
PARAM_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
2017-03-05 15:44:50 +00:00
|
|
|
MAX_COLOR_PHASES = 4
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
2017-02-27 09:47:28 +00:00
|
|
|
enum ProcessMode {
|
|
|
|
PROCESS_FIXED,
|
|
|
|
PROCESS_IDLE,
|
|
|
|
};
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
private:
|
|
|
|
float param[PARAM_MAX];
|
|
|
|
float randomness[PARAM_MAX];
|
|
|
|
|
|
|
|
struct Particle {
|
|
|
|
bool active;
|
|
|
|
Point2 pos;
|
|
|
|
Vector2 velocity;
|
|
|
|
float rot;
|
2014-11-17 10:46:11 +00:00
|
|
|
float frame;
|
2017-02-27 21:12:58 +00:00
|
|
|
uint64_t seed;
|
2017-03-05 15:44:50 +00:00
|
|
|
Particle() {
|
|
|
|
active = false;
|
|
|
|
seed = 123465789;
|
|
|
|
rot = 0;
|
|
|
|
frame = 0;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
2014-02-13 21:03:28 +00:00
|
|
|
bool flip_h;
|
|
|
|
bool flip_v;
|
2014-11-17 10:46:11 +00:00
|
|
|
int h_frames;
|
|
|
|
int v_frames;
|
2014-02-10 01:10:30 +00:00
|
|
|
Point2 emissor_offset;
|
|
|
|
Vector2 initial_velocity;
|
|
|
|
Vector2 extents;
|
2017-01-07 21:25:37 +00:00
|
|
|
PoolVector<Vector2> emission_points;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-02-27 09:47:28 +00:00
|
|
|
ProcessMode process_mode;
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
float time;
|
|
|
|
int active_count;
|
|
|
|
|
|
|
|
Ref<Texture> texture;
|
|
|
|
|
2015-05-24 18:18:52 +00:00
|
|
|
//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;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
void _process_particles(float p_delta);
|
2017-03-05 15:44:50 +00:00
|
|
|
friend class ParticleAttractor2D;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Set<ParticleAttractor2D *> attractors;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void _notification(int p_what);
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
|
|
|
void set_emitting(bool p_emitting);
|
|
|
|
bool is_emitting() const;
|
|
|
|
|
2017-02-27 09:47:28 +00:00
|
|
|
void set_process_mode(ProcessMode p_mode);
|
|
|
|
ProcessMode get_process_mode() const;
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
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;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_emission_half_extents(const Vector2 &p_extents);
|
2014-02-10 01:10:30 +00:00
|
|
|
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;
|
|
|
|
|
2014-02-13 21:03:28 +00:00
|
|
|
void set_flip_h(bool p_flip);
|
|
|
|
bool is_flipped_h() const;
|
|
|
|
|
|
|
|
void set_flip_v(bool p_flip);
|
|
|
|
bool is_flipped_v() const;
|
|
|
|
|
2014-11-17 10:46:11 +00:00
|
|
|
void set_h_frames(int p_frames);
|
|
|
|
int get_h_frames() const;
|
|
|
|
|
|
|
|
void set_v_frames(int p_frames);
|
|
|
|
int get_v_frames() const;
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void set_color_phases(int p_phases);
|
|
|
|
int get_color_phases() const;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_color_phase_color(int p_phase, const Color &p_color);
|
2014-02-10 01:10:30 +00:00
|
|
|
Color get_color_phase_color(int p_phase) const;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_color_phase_pos(int p_phase, float p_pos);
|
2014-02-10 01:10:30 +00:00
|
|
|
float get_color_phase_pos(int p_phase) const;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_texture(const Ref<Texture> &p_texture);
|
2014-02-10 01:10:30 +00:00
|
|
|
Ref<Texture> get_texture() const;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_color(const Color &p_color);
|
2015-05-24 18:18:52 +00:00
|
|
|
Color get_color() const;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_color_ramp(const Ref<ColorRamp> &p_texture);
|
2015-05-24 18:18:52 +00:00
|
|
|
Ref<ColorRamp> get_color_ramp() const;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_emissor_offset(const Point2 &p_offset);
|
2014-02-10 01:10:30 +00:00
|
|
|
Point2 get_emissor_offset() const;
|
|
|
|
|
|
|
|
void set_use_local_space(bool p_use);
|
|
|
|
bool is_using_local_space() const;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_initial_velocity(const Vector2 &p_velocity);
|
2014-02-10 01:10:30 +00:00
|
|
|
Vector2 get_initial_velocity() const;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_emission_points(const PoolVector<Vector2> &p_points);
|
2017-01-07 21:25:37 +00:00
|
|
|
PoolVector<Vector2> get_emission_points() const;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
void pre_process(float p_delta);
|
2015-12-29 21:53:45 +00:00
|
|
|
void reset();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Particles2D();
|
|
|
|
};
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
VARIANT_ENUM_CAST(Particles2D::ProcessMode);
|
|
|
|
VARIANT_ENUM_CAST(Particles2D::Parameter);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
#endif // PARTICLES_FRAME_H
|