2
0

PolyParticleEmitter.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. Copyright (C) 2011 by Ivan Safrin
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #pragma once
  20. #include "PolyGlobals.h"
  21. #include "PolySceneMesh.h"
  22. #include "PolyCore.h"
  23. #include "PolyPerlin.h"
  24. #include "PolyBezierCurve.h"
  25. namespace Polycode {
  26. class SceneParticle {
  27. public:
  28. Number lifetime;
  29. Vector3 position;
  30. Vector3 velocity;
  31. Vector3 perlinPos;
  32. Vector3 rotation;
  33. Number brightnessDeviation;
  34. Number scale;
  35. Color color;
  36. };
  37. class SceneParticleEmitter : public SceneMesh {
  38. public:
  39. SceneParticleEmitter(unsigned int particleCount, Number lifetime, Number speed);
  40. virtual ~SceneParticleEmitter();
  41. void setParticleCount(unsigned int newParticleCount);
  42. unsigned int getParticleCount() const;
  43. void setParticleLifetime(Number lifetime);
  44. Number getParticleLifetime() const;
  45. void setDirectionDeviation(const Vector3 &newDeviation);
  46. Vector3 getDirectionDeviation() const;
  47. void setEmitterSize(const Vector3 &newSize);
  48. Vector3 getEmitterSize() const;
  49. void setGravity(const Vector3 &newGravity);
  50. Vector3 getGravity() const;
  51. void Update();
  52. void Render();
  53. void updateParticles();
  54. void rebuildParticles();
  55. void setUseFloorPlane(bool val);
  56. void setFloorPlaneOffset(Number floorPlaneOffset);
  57. void setFloorDamping(Number floorDamping);
  58. void setParticlesInWorldSpace(bool val);
  59. bool getParticlesInWorldSpace() const;
  60. void setPerlinEnabled(bool val);
  61. bool getPerlinEnabled() const;
  62. Number getParticleSpeed() const;
  63. void setParticleSpeed(Number speed);
  64. void setPerlinValue(const Vector3 &perlinValue);
  65. Vector3 getPerlinValue() const;
  66. void setParticleType(unsigned int particleType);
  67. unsigned int getParticleType() const;
  68. void setParticleSize(Number particleSize);
  69. Number getParticleSize() const;
  70. void setParticleRotationSpeed(const Vector3 &rotationSpeed);
  71. Vector3 getParticleRotationSpeed() const;
  72. void setParticleDirection(const Vector3 &direction);
  73. Vector3 getParticleDirection() const;
  74. void setLoopParticles(bool val);
  75. bool getLoopParticles() const;
  76. static const int PARTICLE_TYPE_POINT = 0;
  77. static const int PARTICLE_TYPE_QUAD = 1;
  78. bool useScaleCurve;
  79. /**
  80. * Bezier curve that controls the scale of the particles.
  81. */
  82. BezierCurve scaleCurve;
  83. bool useColorCurves;
  84. /**
  85. * Bezier curve that controls the red component of particles' color.
  86. */
  87. BezierCurve colorCurveR;
  88. /**
  89. * Bezier curve that controls the green component of particles' color.
  90. */
  91. BezierCurve colorCurveG;
  92. /**
  93. * Bezier curve that controls the blue component of particles' color.
  94. */
  95. BezierCurve colorCurveB;
  96. /**
  97. * Bezier curve that controls the alpha component of particles' color.
  98. */
  99. BezierCurve colorCurveA;
  100. virtual Entity *Clone(bool deepClone, bool ignoreEditorOnly) const;
  101. virtual void applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) const;
  102. protected:
  103. void resetParticle(unsigned int index);
  104. Core *core;
  105. unsigned int particleCount;
  106. std::vector<SceneParticle> particles;
  107. Number particleSpeed;
  108. Number lifetime;
  109. Number timeStep;
  110. Number cyclesLeftOver;
  111. Vector3 directionVector;
  112. Vector3 directionDeviation;
  113. Vector3 emitterSize;
  114. Vector3 gravity;
  115. Matrix4 systemTrasnformMatrix;
  116. bool useFloorPlane;
  117. bool particlesInWorldSpace;
  118. bool perlinEnabled;
  119. Vector3 perlinValue;
  120. Perlin *motionPerlin;
  121. Number particleSize;
  122. Vector3 particleRotationSpeed;
  123. Number floorPlaneOffset;
  124. Number floorDamping;
  125. bool loopParticles;
  126. unsigned int particleType;
  127. Quaternion q;
  128. };
  129. }