LightWrap++
AC++wrapperfortheLightWave3DSDK
particle_services.h
Go to the documentation of this file.
1 
7 #ifndef PARTICLE_SERVICES_H
8 #define PARTICLE_SERVICES_H
9 
10 #include <lwpp/global.h>
11 
12 #include <lwpp/point3d.h>
13 #include <lwpp/vector3d.h>
14 
15 #include <lwprtcl.h>
16 
17 namespace lwpp
18 {
20 
31  class ParticleServices : protected GlobalBase<LWPSysFuncs>
32  {
33 
34  private:
36  LWPSysID prtsv_id;
37 
39  LWPSBufID posbf_id;
41  LWPSBufID sizbf_id;
43  LWPSBufID sclbf_id;
45  LWPSBufID rotbf_id;
47  LWPSBufID velbf_id;
49  LWPSBufID agebf_id;
51  LWPSBufID frcbf_id;
53  LWPSBufID prsbf_id;
55  LWPSBufID tmpbf_id;
57  LWPSBufID masbf_id;
59  LWPSBufID lnkbf_id;
61  LWPSBufID pidbf_id;
63  LWPSBufID enbbf_id;
65  LWPSBufID rgbabf_id;
67  LWPSBufID cagebf_id;
69  LWPSBufID ragebf_id;
71  LWPSBufID sposbf_id;
73  LWPSBufID ssclbf_id;
75  LWPSBufID srotbf_id;
76 
77  public:
79  ParticleServices( LWPSysID _prtsv_id = 0) : prtsv_id(_prtsv_id) {;}
80 
82  LWPSysID getID() const { return prtsv_id; }
83 
105  LWPSysID create (int flags, int type = LWPST_PRTCL)
106  {
107  prtsv_id = globPtr->create(flags, type);
108 
109  // Get and store all the buffers created
110  // to avoid later calls to getBufferID.
111  // Position
112  if (flags & LWPSB_POS) { posbf_id = getBufferID(LWPSB_POS); }
113  // Size
114  if (flags & LWPSB_SIZ) { sizbf_id = getBufferID(LWPSB_SIZ); }
115  // Scale
116  if (flags & LWPSB_SCL) { sclbf_id = getBufferID(LWPSB_SCL); }
117  // Rotation
118  if (flags & LWPSB_ROT) { rotbf_id = getBufferID(LWPSB_ROT); }
119  // Velocity
120  if (flags & LWPSB_VEL) { velbf_id = getBufferID(LWPSB_VEL); }
121  // Age
122  if (flags & LWPSB_AGE) { agebf_id = getBufferID(LWPSB_AGE); }
123  // Force
124  if (flags & LWPSB_FCE) { frcbf_id = getBufferID(LWPSB_FCE); }
125  // Pressure
126  if (flags & LWPSB_PRS) { prsbf_id = getBufferID(LWPSB_PRS); }
127  // Temperature
128  if (flags & LWPSB_TMP) { tmpbf_id = getBufferID(LWPSB_TMP); }
129  // Mass
130  if (flags & LWPSB_MAS) { masbf_id = getBufferID(LWPSB_MAS); }
131  // Linked Particle
132  // This buffer is created as well if the type is a trail particle system
133  if (flags & LWPSB_TMP || type == LWPST_TRAIL ) { lnkbf_id = getBufferID(LWPSB_TMP); }
134  // Particle ID
135  if (flags & LWPSB_ID) { pidbf_id = getBufferID(LWPSB_ID); }
136  // Enable
137  if (flags & LWPSB_ENB) { enbbf_id = getBufferID(LWPSB_ENB); }
138  // RGBA
139  if (flags & LWPSB_RGBA) { rgbabf_id = getBufferID(LWPSB_RGBA); }
140  // Colision Age
141  if (flags & LWPSB_CAGE) { cagebf_id = getBufferID(LWPSB_CAGE); }
142  // Relative Age
143  if (flags & LWPSB_RAGE) { ragebf_id = getBufferID(LWPSB_RAGE); }
144  // Start Position
145  if (flags & LWPSB_POS0) { sposbf_id = getBufferID(LWPSB_POS0); }
146  // Start Scale
147  if (flags & LWPSB_SCL0) { ssclbf_id = getBufferID(LWPSB_SCL0); }
148  // Start Rotation
149  if (flags & LWPSB_ROT0) { ssclbf_id = srotbf_id = getBufferID(LWPSB_ROT0); }
150 
151  return prtsv_id;
152  }
153 
155  int destroy () { return globPtr->destroy(prtsv_id); }
156 
158  int init (int num_particles) { return globPtr->init(prtsv_id, num_particles); }
159 
161  void cleanup () { globPtr->cleanup(prtsv_id); }
162 
164  void load ( LWLoadState *loadstate ) { globPtr->load(prtsv_id, loadstate); }
165 
167  void save ( LWSaveState *savestate ) { globPtr->save(prtsv_id, savestate); }
168 
170  int getParticleCount () { return globPtr->getPCount(prtsv_id); }
171 
178  void attach (LWItemID lwitid) { globPtr->attach(prtsv_id, lwitid); }
179 
181  void detach (LWItemID lwitid) { globPtr->detach(prtsv_id, lwitid); }
182 
186  LWPSysID * getParticleSystems (LWItemID lwitid) { return globPtr->getPSys(lwitid); }
187 
209  LWPSBufID addBuffer (LWPSBufDesc lwbufdesc) { return globPtr->addBuf(prtsv_id, lwbufdesc); }
210 
215  LWPSBufID getBufferID ( int bufferFlag) { return globPtr->getBufID( prtsv_id, bufferFlag ); }
216 
222  template <typename T>
223  void setBufferData (LWPSBufID buffer_id, T data) { globPtr->setBufData( buffer_id, &data ); }
224 
231  template <typename T>
232  void getBufferData (LWPSBufID buffer_id, T &data) { globPtr->getBufData( buffer_id, &data ); }
233 
235  int addParticle () { return globPtr->addParticle(prtsv_id); }
236 
240  void setParticle (LWPSBufID buffer_id, int index, void *data) { globPtr->setParticle(buffer_id, index, data); }
241 
245  void getParticle (LWPSBufID buffer_id, int index, void *data) { globPtr->getParticle(buffer_id, index, data); }
246 
249  void removeParticle (int index) { globPtr->remParticle(prtsv_id, index); }
250 
251  /* Auxiliary Functions from the wrapper to help to the writing of plugins
252  * This ARE NOT part originally of the LWSDK but make use of it
253  */
254 
259  void getPosition(int index, float *position) { getParticle(posbf_id, index, position); }
260 
264  Point3f getPosition(int index)
265  {
266  float position[3] = { 0, 0, 0 };
267  getPosition(index, position);
268  return Point3f(position);
269  }
270 
275  void setPosition(int index, float *position) { setParticle(posbf_id, index, position); }
276 
281  void setPosition(int index, Point3d &position)
282  {
283  float fposition[3] = { (float) position.x, (float) position.y, (float) position.z };
284  setParticle(posbf_id, index, fposition);
285  }
286 
291  void getSize(int index, float *size) { getParticle(sizbf_id, index, size); }
292 
297  void setSize(int index, float size) { setParticle(sizbf_id, index, &size); }
298 
303  void getScale(int index, float *scale) { getParticle(sclbf_id, index, scale); }
304 
309  void setScale(int index, float scale) { setParticle(sclbf_id, index, &scale); }
310 
315  void getRotation(int index, float *rotation) { getParticle(rotbf_id, index, rotation); }
316 
321  void setRotation(int index, float rotation) { setParticle(rotbf_id, index, &rotation); }
322 
327  void getVelocity(int index, float *velocity) { getParticle(velbf_id, index, velocity); }
328 
333  void setVelocity(int index, float velocity) { setParticle(velbf_id, index, &velocity); }
334 
338  void * getAge(int index)
339  {
340  void *age;
341  getParticle(agebf_id, index, age);
342  return age;
343  }
344 
349  void setAge(int index, float *age) { setParticle(agebf_id, index, age); }
350 
354  void * getForce(int index)
355  {
356  void *force;
357  getParticle(frcbf_id, index, force);
358  return force;
359  }
360 
365  void setForce(int index, float force) { setParticle(frcbf_id, index, &force); }
366 
370  void * getPressure(int index)
371  {
372  void *pressure;
373  getParticle(prsbf_id, index, pressure);
374  return pressure;
375  }
376 
381  void setPressure(int index, float pressure) { setParticle(prsbf_id, index, &pressure); }
382 
386  void * getTemperature(int index)
387  {
388  void *temperature;
389  getParticle(tmpbf_id, index, temperature);
390  return temperature;
391  }
392 
397  void setTemperature(int index, float temperature) { setParticle(tmpbf_id, index, &temperature); }
398 
402  void * getMass(int index)
403  {
404  void *mass;
405  getParticle(masbf_id, index, mass);
406  return mass;
407  }
408 
413  void setMass(int index, float mass) { setParticle(masbf_id, index, &mass); }
414 
418  void * getLink(int index)
419  {
420  void *link;
421  getParticle(lnkbf_id, index, link);
422  return link;
423  }
424 
429  void setLink(int index, int link) { setParticle(lnkbf_id, index, &link); }
430 
434  void * getParticleID(int index)
435  {
436  void *PID;
437  getParticle(pidbf_id, index, PID);
438  return PID;
439  }
440 
445  void setParticleID(int index, int PID) { setParticle(pidbf_id, index, &PID); }
446 
454  char getParticleState(int index)
455  {
456  char state = '0';
457  getParticle(enbbf_id, index, &state);
458  return state;
459  }
460 
465  void setParticleState(int index, char state) { setParticle(enbbf_id, index, &state); }
466 
470  void setParticleDead(int index)
471  {
472  char state = (char) LWPST_DEAD;
473  setParticleState(index, state);
474  }
475 
479  void setParticleAlive(int index)
480  {
481  char state = (char) LWPST_ALIVE;
482  setParticleState(index, state);
483  }
484 
488  void setParticleLimbo(int index)
489  {
490  char state = (char) LWPST_LIMBO;
491  setParticleState(index, state);
492  }
493 
497  bool isDead(int index)
498  {
499  char isdead = getParticleState(index);
500  return ( isdead == LWPST_DEAD) ? true : false ;
501  }
502 
506  bool isAlive(int index)
507  {
508  int isalive = getParticleState(index);
509  return ( isalive == LWPST_ALIVE) ? true : false ;
510  }
511 
515  bool isLimbo(int index)
516  {
517  int islimbo = getParticleState(index);
518  return ( islimbo == LWPST_LIMBO) ? true : false ;
519  }
520 
525  void getRGBA(int index, unsigned char *RGBA)
526  {
527  getParticle(rgbabf_id, index, RGBA);
528  }
529 
534  void setRGBA(int index, unsigned char *RGBA)
535  {
536  setParticle(rgbabf_id, index, RGBA);
537  }
538 
542  void * getCollisionAge(int index)
543  {
544  void *cage;
545  getParticle(cagebf_id, index, cage);
546  return cage;
547  }
548 
553  void setCollisionAge(int index, float cage) { setParticle(cagebf_id, index, &cage); }
554 
558  void * getRelativeAge(int index)
559  {
560  void *rage;
561  getParticle(ragebf_id, index, rage);
562  return rage;
563  }
564 
569  void setRelativeAge(int index, float rage) { setParticle(ragebf_id, index, &rage); }
570 
575  void * getStartPosition(int index, float *sposition) { getParticle(sposbf_id, index, sposition); }
576 
581  void setStartPosition(int index, float sposition) { setParticle(sposbf_id, index, &sposition); }
582 
587  void getStartScale(int index, float *sscale) { getParticle(ssclbf_id, index, sscale); }
588 
593  void setStartScale(int index, float sscale) { setParticle(ssclbf_id, index, &sscale); }
594 
599  void getStartRotation(int index, float *srotation) { getParticle(srotbf_id, index, srotation); }
600 
605  void setStartRotation(int index, float srotation) { setParticle(srotbf_id, index, &srotation); }
606 
607  };
608 } // namespace lwpp
609 #endif // PARTICLE_SERVICES_H