particle.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  23. // Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
  24. // Copyright (C) 2015 Faust Logic, Inc.
  25. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  26. #ifndef _PARTICLE_H_
  27. #define _PARTICLE_H_
  28. #ifndef _GAMEBASE_H_
  29. #include "T3D/gameBase/gameBase.h"
  30. #endif
  31. #ifndef _GFXTEXTUREHANDLE_H_
  32. #include "gfx/gfxTextureHandle.h"
  33. #endif
  34. #define MaxParticleSize 50.0
  35. struct Particle;
  36. //*****************************************************************************
  37. // Particle Data
  38. //*****************************************************************************
  39. class ParticleData : public SimDataBlock
  40. {
  41. typedef SimDataBlock Parent;
  42. public:
  43. enum PDConst
  44. {
  45. // This increase the keyframes from 4 to 8. Especially useful for premult-alpha blended particles
  46. // for which 4 keyframes is often not enough.
  47. PDC_NUM_KEYS = 8,
  48. };
  49. F32 dragCoefficient;
  50. F32 windCoefficient;
  51. F32 gravityCoefficient;
  52. F32 inheritedVelFactor;
  53. F32 constantAcceleration;
  54. S32 lifetimeMS;
  55. S32 lifetimeVarianceMS;
  56. F32 spinSpeed; // degrees per second
  57. F32 spinRandomMin;
  58. F32 spinRandomMax;
  59. bool useInvAlpha;
  60. bool animateTexture;
  61. U32 numFrames;
  62. U32 framesPerSec;
  63. LinearColorF colors[ PDC_NUM_KEYS ];
  64. F32 sizes[ PDC_NUM_KEYS ];
  65. F32 times[ PDC_NUM_KEYS ];
  66. Point2F* animTexUVs;
  67. Point2F texCoords[4]; // default: {{0.0,0.0}, {0.0,1.0}, {1.0,1.0}, {1.0,0.0}}
  68. Point2I animTexTiling;
  69. StringTableEntry animTexFramesString;
  70. Vector<U8> animTexFrames;
  71. StringTableEntry textureName;
  72. GFXTexHandle textureHandle;
  73. static bool protectedSetSizes( void *object, const char *index, const char *data );
  74. static bool protectedSetTimes( void *object, const char *index, const char *data );
  75. public:
  76. ParticleData();
  77. ~ParticleData();
  78. // move this procedure to Particle
  79. void initializeParticle(Particle*, const Point3F&);
  80. void packData(BitStream* stream);
  81. void unpackData(BitStream* stream);
  82. bool onAdd();
  83. bool preload(bool server, String &errorStr);
  84. DECLARE_CONOBJECT(ParticleData);
  85. static void initPersistFields();
  86. bool reload(char errorBuffer[256]);
  87. public:
  88. /*C*/ ParticleData(const ParticleData&, bool = false);
  89. virtual void onPerformSubstitutions();
  90. virtual bool allowSubstitutions() const { return true; }
  91. protected:
  92. F32 spinBias;
  93. bool randomizeSpinDir;
  94. StringTableEntry textureExtName;
  95. public:
  96. GFXTexHandle textureExtHandle;
  97. bool constrain_pos;
  98. F32 start_angle;
  99. F32 angle_variance;
  100. F32 sizeBias;
  101. public:
  102. bool loadParameters();
  103. bool reload(String &errorStr);
  104. };
  105. //*****************************************************************************
  106. // Particle
  107. //
  108. // This structure should be as small as possible.
  109. //*****************************************************************************
  110. struct Particle
  111. {
  112. Point3F pos; // current instantaneous position
  113. Point3F vel; // " " velocity
  114. Point3F acc; // Constant acceleration
  115. Point3F orientDir; // direction particle should go if using oriented particles
  116. U32 totalLifetime; // Total ms that this instance should be "live"
  117. ParticleData* dataBlock; // datablock that contains global parameters for
  118. // this instance
  119. U32 currentAge;
  120. // are these necessary to store here? - they are interpolated in real time
  121. LinearColorF color;
  122. F32 size;
  123. F32 spinSpeed;
  124. Particle * next;
  125. Point3F pos_local;
  126. F32 t_last;
  127. Point3F radial_v; // radial vector for concentric effects
  128. // note -- for non-oriented particles, we use orientDir.x to store the billboard start angle.
  129. };
  130. #endif // _PARTICLE_H_