ParticleInfo.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // ParticleInfo.cs
  4. //
  5. // Microsoft XNA Community Game Platform
  6. // Copyright (C) Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #endregion
  9. #region Using Statements
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Text;
  13. using Microsoft.Xna.Framework;
  14. using Microsoft.Xna.Framework.Graphics;
  15. #endregion
  16. namespace RobotGameData.ParticleSystem
  17. {
  18. #region VertexData
  19. /// <summary>
  20. /// contains the vertex information of the particle object of mesh type.
  21. /// </summary>
  22. [Serializable]
  23. public class VertexData
  24. {
  25. public bool HasPosition = false;
  26. public bool HasNormal = false;
  27. public bool HasColor = false;
  28. public bool HasTextureCoord = false;
  29. public bool HasIndex = false;
  30. public List<Vector3> Position = null;
  31. public List<Vector3> Normal = null;
  32. public List<Color> Color = null;
  33. public List<Vector2> TextureCoord = null;
  34. public List<short> Index = null;
  35. }
  36. #endregion
  37. /// <summary>
  38. /// contains every information of particle.
  39. /// Based on the information, particle gets updated.
  40. /// </summary>
  41. #region Particle Information
  42. [Serializable]
  43. public class ParticleInfo
  44. {
  45. #region Enum types
  46. [Flags]
  47. public enum ParamStyles
  48. {
  49. None = 0x00000000,
  50. Random = 0x00000001,
  51. Interpolate = 0x00000002,
  52. Clamp = 0x00000004,
  53. Gravity = 0x00000010,
  54. RandomInterpolate = 0x00000020,
  55. }
  56. public enum ParticleObjectType
  57. {
  58. PointSprite = 0,
  59. Sprite = 1,
  60. Billboard = 2,
  61. Scene = 3,
  62. AnchorBillboard = 4,
  63. }
  64. public enum EmitObjectType
  65. {
  66. Cone = 0,
  67. Sphere = 1,
  68. Disk = 2,
  69. RectPlane = 3,
  70. CirclePlane = 4,
  71. }
  72. public enum FuncType
  73. {
  74. None = 0,
  75. Constant = 1,
  76. Sin = 2,
  77. Cos = 3,
  78. Rnd = 4,
  79. Table = 5,
  80. }
  81. #endregion
  82. #region Persistent Member Fields
  83. // Persistent Members
  84. public string Name = String.Empty;
  85. public ParticleObjectType ParticleType = ParticleObjectType.PointSprite;
  86. public VertexData MeshData = null;
  87. public string TextureFileName = String.Empty;
  88. public bool AlphaBlendEnable = true;
  89. public bool DepthBufferEnable = false;
  90. public Blend SourceBlend = Blend.One;
  91. public Blend DestinationBlend = Blend.One;
  92. public BlendFunction BlendFunction = BlendFunction.Add;
  93. public float LifeTime = 0.0f;
  94. public float ObjectLifeTime = 0.0f;
  95. public float MassMin = 0.0f;
  96. public float MassMax = 0.0f;
  97. public int InitialObjectCount = 0;
  98. public int MaxObjectCount = 0;
  99. public int EmitCount = 0;
  100. public bool Volatile = false;
  101. public EmitObjectType EmitType = EmitObjectType.Cone;
  102. public Vector3 EmitPosition = Vector3.Zero;
  103. public Vector3 EmitDirection = Vector3.Forward;
  104. public float EmitAngle = 0.0f;
  105. public float EmitInterval = 0.0f;
  106. public Vector3 UpVector = Vector3.Up;
  107. public uint PositionStyle = 0;
  108. public float PositionUpdateInterval = 0.0f;
  109. public List<FuncType> PositionFunc = null;
  110. public List<float> PositionInit = null;
  111. public List<float> PositionFactor = null;
  112. public List<KeyFrameTable> PositionTable = null;
  113. public float PositionMin = 0.0f;
  114. public float PositionMax = 0.0f;
  115. public float PositionInitialRandomFactor = 1.0f;
  116. public Vector3 PositionRandomFactor = Vector3.One;
  117. public float PositionRandomInterval = 0.0f;
  118. public uint ScaleStyle = 0;
  119. public float ScaleUpdateInterval = 0.0f;
  120. public List<FuncType> ScaleFunc = null;
  121. public List<float> ScaleInit = null;
  122. public List<float> ScaleFactor = null;
  123. public List<KeyFrameTable> ScaleTable = null;
  124. public float ScaleInitialRandomFactor = 1.0f;
  125. public float ScaleMin = 0.0f;
  126. public float ScaleMax = 0.0f;
  127. public Vector3 ScaleMask = Vector3.One;
  128. public float ScaleBillboardFactor = 1.0f;
  129. public uint RotateStyle = 0;
  130. public float RotateUpdateInterval = 0.0f;
  131. public float RotateRandomFactor = 1.0f;
  132. public FuncType RotateFunc = FuncType.None;
  133. public float RotateInit = 0.0f;
  134. public float RotateFactor = 1.0f;
  135. public KeyFrameTable RotateTable = null;
  136. public uint ColorStyle = 0;
  137. public float ColorUpdateInterval = 0.0f;
  138. public FuncType RgbFunc = FuncType.None;
  139. public string RgbInit = String.Empty;
  140. public KeyFrameTable Rtable = null;
  141. public KeyFrameTable Gtable = null;
  142. public KeyFrameTable Btable = null;
  143. public KeyFrameTable Atable = null;
  144. public FuncType AlphaFunc = FuncType.None;
  145. public uint AlphaInit = 255;
  146. #endregion
  147. #region Volatile Member Fields
  148. // Volatile Members
  149. Color eRgbInit = Color.Black;
  150. public const int FuncCount = 2;
  151. #endregion
  152. #region Properties
  153. public Color RgbInitValue
  154. {
  155. get { return eRgbInit; }
  156. }
  157. public bool IsPositionStyle(uint param)
  158. {
  159. return ((PositionStyle & param) > 0);
  160. }
  161. public bool IsPositionStyle(ParamStyles param)
  162. {
  163. return ((PositionStyle & (uint)param) > 0);
  164. }
  165. public bool IsScaleStyle(uint param)
  166. {
  167. return ((ScaleStyle & param) > 0);
  168. }
  169. public bool IsScaleStyle(ParamStyles param)
  170. {
  171. return ((ScaleStyle & (uint)param) > 0);
  172. }
  173. public bool IsRotateStyle(uint param)
  174. {
  175. return ((RotateStyle & param) > 0);
  176. }
  177. public bool IsRotateStyle(ParamStyles param)
  178. {
  179. return ((RotateStyle & (uint)param) > 0);
  180. }
  181. public bool IsColorStyle(uint param)
  182. {
  183. return ((ColorStyle & param) > 0);
  184. }
  185. public bool IsColorStyle(ParamStyles param)
  186. {
  187. return ((ColorStyle & (uint)param) > 0);
  188. }
  189. #endregion
  190. /// <summary>
  191. /// Initialize members
  192. /// </summary>
  193. public void Initialize()
  194. {
  195. // Initialize KeyFrameTable
  196. if (PositionTable != null)
  197. {
  198. for (int i = 0; i < PositionTable.Count; i++)
  199. PositionTable[i].Initialize();
  200. }
  201. if (ScaleTable != null)
  202. {
  203. for (int i = 0; i < ScaleTable.Count; i++)
  204. ScaleTable[i].Initialize();
  205. }
  206. if( RotateTable != null)
  207. RotateTable.Initialize();
  208. if (Rtable != null)
  209. Rtable.Initialize();
  210. if (Gtable != null)
  211. Gtable.Initialize();
  212. if (Btable != null)
  213. Btable.Initialize();
  214. if (Atable != null)
  215. Atable.Initialize();
  216. // Initialize eRgbInit's Color
  217. string[] color = RgbInit.Split(',');
  218. eRgbInit = new Color(byte.Parse(color[0]), // R
  219. byte.Parse(color[1]), // G
  220. byte.Parse(color[2]), // B
  221. byte.Parse(color[3])); // A
  222. }
  223. }
  224. #endregion
  225. }