particles.h
1 /*************************************************************************/
2 /* particles.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 VISUALINSTANCEPARTICLES_H
30 #define VISUALINSTANCEPARTICLES_H
31 
32 #include "scene/3d/visual_instance.h"
33 #include "scene/resources/material.h"
34 #include "scene/main/timer.h"
35 #include "rid.h"
36 
41 class Particles : public GeometryInstance {
42 public:
43 
44  enum Variable {
45  VAR_LIFETIME=VS::PARTICLE_LIFETIME,
46  VAR_SPREAD=VS::PARTICLE_SPREAD,
47  VAR_GRAVITY=VS::PARTICLE_GRAVITY,
48  VAR_LINEAR_VELOCITY=VS::PARTICLE_LINEAR_VELOCITY,
49  VAR_ANGULAR_VELOCITY=VS::PARTICLE_ANGULAR_VELOCITY,
50  VAR_LINEAR_ACCELERATION=VS::PARTICLE_LINEAR_ACCELERATION,
51  VAR_DRAG=VS::PARTICLE_RADIAL_ACCELERATION,
52  VAR_TANGENTIAL_ACCELERATION=VS::PARTICLE_TANGENTIAL_ACCELERATION,
53  VAR_DAMPING=VS::PARTICLE_DAMPING,
54  VAR_INITIAL_SIZE=VS::PARTICLE_INITIAL_SIZE,
55  VAR_FINAL_SIZE=VS::PARTICLE_FINAL_SIZE,
56  VAR_INITIAL_ANGLE=VS::PARTICLE_INITIAL_ANGLE,
57  VAR_HEIGHT=VS::PARTICLE_HEIGHT,
58  VAR_HEIGHT_SPEED_SCALE=VS::PARTICLE_HEIGHT_SPEED_SCALE,
59  VAR_MAX=VS::PARTICLE_VAR_MAX
60  };
61 
62 private:
63  OBJ_TYPE( Particles, GeometryInstance );
64 
65  RID particles;
66 
67  int amount;
68  bool emitting;
69  float emit_timeout;
70  AABB visibility_aabb;
71  Vector3 gravity_normal;
72  Vector3 emission_half_extents;
73  bool using_points;
74  float var[VAR_MAX];
75  float var_random[VAR_MAX];
76  bool height_from_velocity;
77  Vector3 emission_base_velocity;
78  bool local_coordinates;
79 
80  struct ColorPhase {
81 
82  Color color;
83  float pos;
84  };
85 
86  virtual bool _can_gizmo_scale() const;
87  virtual RES _get_gizmo_geometry() const;
88 
89  int color_phase_count;
90 
91  ColorPhase color_phase[4];
92 
93  Ref<Material> material;
94 
95  Timer* timer;
96  void setup_timer();
97 
98 protected:
99 
100  static void _bind_methods();
101 
102 public:
103 
104 
105  AABB get_aabb() const;
106  DVector<Face3> get_faces(uint32_t p_usage_flags) const;
107 
108  void set_amount(int p_amount);
109  int get_amount() const;
110 
111  void set_emitting(bool p_emitting);
112  bool is_emitting() const;
113 
114  void set_visibility_aabb(const AABB& p_aabb);
115  AABB get_visibility_aabb() const;
116 
117  void set_emission_half_extents(const Vector3& p_half_extents);
118  Vector3 get_emission_half_extents() const;
119 
120  void set_emission_base_velocity(const Vector3& p_base_velocity);
121  Vector3 get_emission_base_velocity() const;
122 
123  void set_emission_points(const DVector<Vector3>& p_points);
124  DVector<Vector3> get_emission_points() const;
125 
126  void set_gravity_normal(const Vector3& p_normal);
127  Vector3 get_gravity_normal() const;
128 
129  void set_variable(Variable p_variable,float p_value);
130  float get_variable(Variable p_variable) const;
131 
132  void set_randomness(Variable p_variable,float p_randomness);
133  float get_randomness(Variable p_variable) const;
134 
135  void set_color_phases(int p_phases);
136  int get_color_phases() const;
137 
138  void set_color_phase_pos(int p_phase, float p_pos);
139  float get_color_phase_pos(int p_phase) const;
140 
141  void set_color_phase_color(int p_phase, const Color& p_color);
142  Color get_color_phase_color(int p_phase) const;
143 
144  void set_height_from_velocity(bool p_enable);
145  bool has_height_from_velocity() const;
146 
147  void set_material(const Ref<Material>& p_material);
148  Ref<Material> get_material() const;
149 
150  void set_emit_timeout(float p_timeout);
151  float get_emit_timeout() const;
152 
153  void set_use_local_coordinates(bool p_use);
154  bool is_using_local_coordinates() const;
155 
156  void start_emitting(float p_time);
157 
158 
159  Particles();
160  ~Particles();
161 
162 };
163 
164 VARIANT_ENUM_CAST( Particles::Variable );
165 #endif
Definition: timer.h:34
Definition: aabb.h:43
Definition: color.h:37
Definition: vector3.h:38
Definition: rid.h:47
Definition: particles.h:41
Definition: visual_instance.h:84