PolyParticleEmitter.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 "PolyString.h"
  21. #include "PolyGlobals.h"
  22. #include "PolyEntity.h"
  23. #include "PolyScenePrimitive.h"
  24. #include "PolyScreenMesh.h"
  25. #include "PolyCoreServices.h"
  26. #include "PolyParticle.h"
  27. #include <vector>
  28. using std::vector;
  29. namespace Polycode {
  30. class _PolyExport ParticleEmitter {
  31. public:
  32. ParticleEmitter(String imageFile, Mesh *particleMesh, int particleType, int emitterType, Number lifespan, unsigned int numParticles, Vector3 direction, Vector3 gravity, Vector3 deviation);
  33. virtual ~ParticleEmitter();
  34. void createParticles();
  35. void setRotationSpeed(Number speed);
  36. void setStartingColor(Color c);
  37. void setEndingColor(Color c);
  38. void setParticleBlendingMode(int mode);
  39. void setDepthWrite(bool val);
  40. void setDepthTest(bool val);
  41. void setAlphaTest(bool val);
  42. void enablePerlin(bool val);
  43. void setBillboardMode(bool mode);
  44. void enableEmitter(bool val);
  45. bool emitterEnabled();
  46. void setEmitterRadius(Number rad);
  47. void setStartingScaleModifier(Number mod);
  48. void setEndingScaleModifier(Number mod);
  49. void setEmitRotationVector(Vector3 rotVector);
  50. void setEmitRotationDeviance(Vector3 rotVector);
  51. void setAllAtOnce(bool val);
  52. void Trigger();
  53. void resetParticle(Particle *particle);
  54. void setPerlinModSize(Number size);
  55. void setParticleCount(int count);
  56. virtual void addParticleBody(Entity *particleBody) = 0;
  57. virtual Matrix4 getBaseMatrix() = 0;
  58. Number particleSpeedMod;
  59. Number brightnessDeviation;
  60. void updateEmitter();
  61. static const int CONTINUOUS_EMITTER = 0;
  62. static const int TRIGGERED_EMITTER = 1;
  63. static const int CLOUD_EMITTER = 2;
  64. Vector3 deviation;
  65. Vector3 dirVector;
  66. Vector3 gravVector;
  67. Number lifespan;
  68. bool rotationFollowsPath;
  69. BezierCurve scaleCurve;
  70. BezierCurve colorCurveR;
  71. BezierCurve colorCurveG;
  72. BezierCurve colorCurveB;
  73. BezierCurve colorCurveA;
  74. protected:
  75. bool isScreenEmitter;
  76. Mesh *pMesh;
  77. bool allAtOnce;
  78. int emitterType;
  79. int particleType;
  80. Material *particleMaterial;
  81. Texture *particleTexture;
  82. String textureFile;
  83. bool isEmitterEnabled;
  84. Vector3 emitRotationVector;
  85. Vector3 emitRotationDeviance;
  86. Number emitterRadius;
  87. Number perlinModSize;
  88. Perlin *motionPerlin;
  89. bool perlinEnabled;
  90. Number startingScaleMod;
  91. Number endingScaleMod;
  92. Color startingColor;
  93. Color endingColor;
  94. Number rotationSpeed;
  95. Number numParticles;
  96. vector<Particle*> particles;
  97. Number emitSpeed;
  98. Timer *timer;
  99. };
  100. class _PolyExport SceneParticleEmitter : public SceneEntity, public ParticleEmitter {
  101. public:
  102. SceneParticleEmitter(String imageFile, Mesh *particleMesh, SceneMesh *emitter, Scene *particleParentScene, int particleType, int emitterType, Number lifespan, unsigned int numParticles, Vector3 direction, Vector3 gravity, Vector3 deviation);
  103. ~SceneParticleEmitter();
  104. void addParticleBody(Entity *particleBody);
  105. Matrix4 getBaseMatrix();
  106. void Update();
  107. protected:
  108. SceneMesh *emitterMesh;
  109. Scene *particleParentScene;
  110. };
  111. class _PolyExport ScreenParticleEmitter : public ScreenEntity, public ParticleEmitter {
  112. public:
  113. ScreenParticleEmitter(String imageFile, Mesh *particleMesh, ScreenMesh *emitter, Screen *particleParentScreen, int particleType, int emitterType, Number lifespan, unsigned int numParticles, Vector3 direction, Vector3 gravity, Vector3 deviation);
  114. ~ScreenParticleEmitter();
  115. void addParticleBody(Entity *particleBody);
  116. Matrix4 getBaseMatrix();
  117. void Update();
  118. protected:
  119. ScreenMesh *emitterMesh;
  120. Screen *particleParentScreen;
  121. };
  122. }