ParticleCloud.hpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. //==========================================================================//
  2. // File: gosFX_ParticleCloud.hpp //
  3. // Contents: Base ParticleCloud Particle //
  4. //---------------------------------------------------------------------------//
  5. // Copyright (C) Microsoft Corporation. All rights reserved. //
  6. //===========================================================================//
  7. //
  8. #pragma once
  9. #include "gosFX.hpp"
  10. #include "Effect.hpp"
  11. namespace gosFX
  12. {
  13. //############################################################################
  14. //######################## ParticleCloud__Specification #############################
  15. //############################################################################
  16. class ParticleCloud__Specification:
  17. public Effect__Specification
  18. {
  19. //----------------------------------------------------------------------
  20. // Constructors/Destructors
  21. //
  22. protected:
  23. ParticleCloud__Specification(
  24. Stuff::RegisteredClass::ClassID class_id,
  25. Stuff::MemoryStream *stream,
  26. int gfx_version
  27. );
  28. public:
  29. ParticleCloud__Specification(Stuff::RegisteredClass::ClassID class_id);
  30. void
  31. Copy(ParticleCloud__Specification *spec);
  32. void
  33. Save(Stuff::MemoryStream *stream);
  34. void
  35. BuildDefaults();
  36. bool
  37. IsDataValid(bool fix_data=false);
  38. //-------------------------------------------------------------------------
  39. // FCurves
  40. //
  41. public:
  42. ConstantCurve
  43. m_startingPopulation;
  44. ComplexCurve
  45. m_particlesPerSecond;
  46. LinearCurve
  47. m_emitterSizeX,
  48. m_emitterSizeY,
  49. m_emitterSizeZ;
  50. ConstantCurve
  51. m_minimumDeviation;
  52. SplineCurve
  53. m_maximumDeviation;
  54. SeededCurveOf<ComplexCurve, ComplexCurve,Curve::e_ComplexComplexType>
  55. m_startingSpeed;
  56. SeededCurveOf<ComplexCurve, SplineCurve,Curve::e_ComplexSplineType>
  57. m_pLifeSpan;
  58. SeededCurveOf<ConstantCurve, LinearCurve,Curve::e_ConstantLinearType>
  59. m_pEtherVelocityX,
  60. m_pEtherVelocityY,
  61. m_pEtherVelocityZ;
  62. SeededCurveOf<SplineCurve, LinearCurve,Curve::e_SplineLinearType>
  63. m_pAccelerationX,
  64. m_pAccelerationY,
  65. m_pAccelerationZ;
  66. SeededCurveOf<ComplexCurve, ComplexCurve,Curve::e_ComplexComplexType>
  67. m_pDrag;
  68. SeededCurveOf<ComplexCurve, LinearCurve,Curve::e_ComplexLinearType>
  69. m_pRed,
  70. m_pGreen,
  71. m_pBlue,
  72. m_pAlpha;
  73. //----------------------------------------------------------------------
  74. // Data
  75. //
  76. public:
  77. int
  78. m_maxParticleCount,
  79. m_totalParticleSize,
  80. m_particleClassSize;
  81. };
  82. //############################################################################
  83. //######################## ParticleCloud__Particle #############################
  84. //############################################################################
  85. class ParticleCloud__Particle
  86. {
  87. public:
  88. Stuff::Vector3D
  89. m_localLinearVelocity,
  90. m_worldLinearVelocity;
  91. Stuff::Scalar
  92. m_seed,
  93. m_age,
  94. m_ageRate;
  95. void
  96. TestInstance() const
  97. {}
  98. };
  99. //############################################################################
  100. //############################## ParticleCloud #############################
  101. //############################################################################
  102. class _declspec(novtable) ParticleCloud:
  103. public Effect
  104. {
  105. public:
  106. static void
  107. InitializeClass();
  108. static void
  109. TerminateClass();
  110. static ClassData
  111. *DefaultData;
  112. typedef ParticleCloud__Specification Specification;
  113. typedef ParticleCloud__Particle Particle;
  114. protected:
  115. int
  116. m_activeParticleCount;
  117. Stuff::Scalar
  118. m_birthAccumulator;
  119. Stuff::DynamicArrayOf<char>
  120. m_data;
  121. ParticleCloud(
  122. ClassData *class_data,
  123. Specification *spec,
  124. unsigned flags
  125. );
  126. //----------------------------------------------------------------------------
  127. // Class Data Support
  128. //
  129. public:
  130. Specification*
  131. GetSpecification()
  132. {
  133. Check_Object(this);
  134. return
  135. Cast_Object(Specification*, m_specification);
  136. }
  137. Particle*
  138. GetParticle(unsigned index)
  139. {
  140. Check_Object(this); Check_Object(GetSpecification());
  141. return
  142. Cast_Pointer(
  143. Particle*,
  144. &m_data[index*GetSpecification()->m_particleClassSize]
  145. );
  146. }
  147. //----------------------------------------------------------------------------
  148. // Testing
  149. //
  150. public:
  151. void
  152. TestInstance() const;
  153. //----------------------------------------------------------------------------
  154. // API
  155. //
  156. protected:
  157. bool
  158. Execute(ExecuteInfo *info);
  159. virtual bool
  160. AnimateParticle(
  161. unsigned index,
  162. const Stuff::LinearMatrix4D *world_to_new_local,
  163. Stuff::Time till
  164. )=0;
  165. virtual void
  166. CreateNewParticle(
  167. unsigned index,
  168. Stuff::Point3D *translation
  169. );
  170. virtual void
  171. DestroyParticle(unsigned index);
  172. void
  173. ComputeNewLinearVelocity(
  174. Particle *particle,
  175. Stuff::Scalar time_slice
  176. );
  177. public:
  178. void
  179. Start(ExecuteInfo *info);
  180. void
  181. Kill();
  182. bool
  183. HasFinished();
  184. };
  185. }