particles.h 5.3 KB

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