2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* particles_2d.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
2017-01-01 22:01:57 +01:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2014-02-10 02:10:30 +01: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"
|
|
|
|
#include "scene/resources/texture.h"
|
2015-05-24 20:18:52 +02:00
|
|
|
#include "scene/resources/color_ramp.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
class Particles2D;
|
|
|
|
class ParticleAttractor2D : public Node2D {
|
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
GDCLASS(ParticleAttractor2D,Node2D);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2016-05-17 23:27:15 +02:00
|
|
|
virtual String get_configuration_warning() const;
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
ParticleAttractor2D();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Particles2D : public Node2D {
|
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
GDCLASS(Particles2D, Node2D);
|
2014-02-10 02:10:30 +01:00
|
|
|
public:
|
|
|
|
|
|
|
|
enum Parameter {
|
|
|
|
PARAM_DIRECTION,
|
|
|
|
PARAM_SPREAD,
|
2016-03-09 00:00:52 +01:00
|
|
|
PARAM_LINEAR_VELOCITY,
|
2014-02-10 02:10:30 +01:00
|
|
|
PARAM_SPIN_VELOCITY,
|
|
|
|
PARAM_ORBIT_VELOCITY,
|
|
|
|
PARAM_GRAVITY_DIRECTION,
|
|
|
|
PARAM_GRAVITY_STRENGTH,
|
|
|
|
PARAM_RADIAL_ACCEL,
|
|
|
|
PARAM_TANGENTIAL_ACCEL,
|
|
|
|
PARAM_DAMPING,
|
2014-09-19 23:39:50 +02:00
|
|
|
PARAM_INITIAL_ANGLE,
|
2014-02-10 02:10:30 +01:00
|
|
|
PARAM_INITIAL_SIZE,
|
|
|
|
PARAM_FINAL_SIZE,
|
|
|
|
PARAM_HUE_VARIATION,
|
2014-11-17 11:46:11 +01:00
|
|
|
PARAM_ANIM_SPEED_SCALE,
|
|
|
|
PARAM_ANIM_INITIAL_POS,
|
2014-02-10 02:10:30 +01:00
|
|
|
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;
|
2014-11-17 11:46:11 +01:00
|
|
|
float frame;
|
2014-02-10 02:10:30 +01:00
|
|
|
uint32_t seed;
|
2014-11-17 11:46:11 +01:00
|
|
|
Particle() { active=false; seed=123465789; rot=0; frame=0;}
|
2014-02-10 02:10:30 +01: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 22:03:28 +01:00
|
|
|
bool flip_h;
|
|
|
|
bool flip_v;
|
2014-11-17 11:46:11 +01:00
|
|
|
int h_frames;
|
|
|
|
int v_frames;
|
2014-02-10 02:10:30 +01:00
|
|
|
Point2 emissor_offset;
|
|
|
|
Vector2 initial_velocity;
|
|
|
|
Vector2 extents;
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Vector2> emission_points;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
float time;
|
|
|
|
int active_count;
|
|
|
|
|
|
|
|
Ref<Texture> texture;
|
|
|
|
|
2015-05-24 20:18:52 +02: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 02:10:30 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2014-02-13 22:03:28 +01: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 11:46:11 +01: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 02:10:30 +01:00
|
|
|
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;
|
|
|
|
|
2015-05-24 20:18:52 +02:00
|
|
|
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;
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
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;
|
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
void set_emission_points(const PoolVector<Vector2>& p_points);
|
|
|
|
PoolVector<Vector2> get_emission_points() const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
void pre_process(float p_delta);
|
2015-12-29 22:53:45 +01:00
|
|
|
void reset();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Particles2D();
|
|
|
|
};
|
|
|
|
|
|
|
|
VARIANT_ENUM_CAST( Particles2D::Parameter );
|
|
|
|
|
|
|
|
#endif // PARTICLES_FRAME_H
|