JNR
fxParticleSystem.h
1 /*
2 
3 Jump'n'Run Engine
4 http://www.atanaslaskov.com/jnr/
5 
6 BSD LICENSE
7 Copyright (c) 2007-2013, Atanas Laskov
8 All rights reserved.
9 
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions are met:
12 1. Redistributions of source code must retain the above copyright notice,
13 this list of conditions and the following disclaimer.
14 2. Redistributions in binary form must reproduce the above copyright notice,
15 this list of conditions and the following disclaimer in the documentation
16 and/or other materials provided with the distribution.
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL ATANAS LASKOV BE LIABLE FOR ANY
21 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 */
29 
30 //
31 // @class fxParticleSystem
32 // @brief Particle Effects Class
33 //
34 // Copyright (C) 2007-2013 Atanas Laskov, <latanas@gmail.com>
35 //
36 #ifndef M_FX_SPRAY_H
37 #define M_FX_SPRAY_H
38 
39 // @class fxParticleSystem_params
40 // @brief Particle effect parameters, used by fxParticleSystem
41 //
42 class fxParticleSystem_params: public laLoadableObj{
43 public:
44 
45  //Angle
46  double ang;
47  double ang_var;
48 
49  //Generation
50  M_BOOL gen_loop;
51  double gen_maxcnt;
52  double gen_percent;
53  double gen_htime;
54  laPoint3 gen_emitter_sz;
55  M_BOOL gen_linearEmitter;
56 
57  //Particle
58  char p_texture[128];
59  laColor p_rgb;
60  double p_alpha_filter;
61  double p_size;
62  double p_speed;
63  double p_mass;
64  double p_ttl;
65 
66  //Particle varation
67  double pv_size;
68  double pv_speed;
69  double pv_mass;
70  double pv_ttl;
71  double pv_ramble;
72 
73  fxParticleSystem_params();
74  virtual void load(class laFileParser *fp);
75 
76 };
77 
78 // The properties of a signle particle
79 // NOTE: Position and size and colour are stored separately form this class
80 // in order to simplify rendering
81 //
82 class fxParticleSystem_particle{
83 public:
84  // Misc parameters
85  //
86  M_BOOL bValid, bCreatedOnce;
87  laPoint3 velocity;
88 
89  double dTTL_Total, dTTL; // Time to live
90 
91  fxParticleSystem_particle(){
92  bValid = bCreatedOnce = M_FALSE;
93  }
94 };
95 
96 class fxParticleSystem: public laPoint3
97 {
98 protected:
99 
100  // Particle properties
101  //
102  fxParticleSystem_particle *_particles;
103  laPoint3 *_arParticlePos;
104  double *_arParticleSize;
105  laColor *_arParticleColors;
106  unsigned _nCnt, _nValidParticles;
107 
108  static laPoint2 *_arParticleUV;
109  static unsigned _nCntMax;
110 
111  //Calculated from _param[1]en_percent
112  unsigned _nSimGenCnt;
113 
114  //Internal generation timing
115  //
116  double _nGenCnt;
117  M_BOOL _bHold;
118  double _dHoldLeft;
119 
120  //Movement and generation enable status
121  //
122  M_BOOL _bEnabled;
123  M_BOOL _bGenEnabled;
124 
125  static double _dParticleDensity;
126 
127 public:
128  fxParticleSystem_params parameters;
129  laTexture texSprite;
130  laLine3 lnEmitter;
131 
132 public:
133  fxParticleSystem(void);
134  virtual ~fxParticleSystem(void);
135 
136  // Create/destroy particle system
137  //
138  void create(fxParticleSystem_params &p);
139  void destroy();
140 
141  // Control
142  //
143  void enable(M_BOOL en=M_TRUE){ _bEnabled=en; }
144  void enableGeneration(M_BOOL en=M_TRUE){ _bGenEnabled=en; }
145  void reset();
146  void ctlRewind(unsigned nframes=1000, double fps=30);
147 
148  static void ctlParticleDensity(double d){ _dParticleDensity=d; };
149 
150  // Positioning
151  //
152  inline void position( const laPoint3 &pt ) {
153  x( pt.x() ); y( pt.y() ); z( pt.z() );
154  //lnEmitter.origin = *this;
155  }
156 
157  //void anchor(laStaticModel* pModel, unsigned nVertexIndex);
158 
159  // Draw
160  void draw(laRenderer *r);
161 
162  // Animate
163  void animate(laTimer &t);
164 
165  // This method is part of the laLoadableObj interface
166  virtual void load(class laFileParser *fp);
167 
168  // Copy style ( colour and texture)
169  // but not the behaviour of particles
170  //
171  void copyStyle(fxParticleSystem* pSource);
172 };
173 
174 #endif //#ifndef M_FX_SPRAY_H
3D line segment
Definition: laLine3.h:40
2D Point
Definition: laPoint_novec.h:41
Interface for loadable objects.
Definition: laLoadableObj.h:43
2D Texture
Definition: laTexture.h:45
Virtual interface for the Engine graphics renderer.
Definition: laRenderer.h:98
File Parser.
Definition: laFileParser.h:41