00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00021
00022
00023 #ifndef H_SPK_MODEL
00024 #define H_SPK_MODEL
00025
00026 #include "Core/SPK_DEF.h"
00027 #include "Core/SPK_Registerable.h"
00028 #include "Core/SPK_Interpolator.h"
00029
00030
00031 namespace SPK
00032 {
00039 enum ModelParamFlag
00040 {
00041 FLAG_NONE = 0,
00042 FLAG_RED = 1 << PARAM_RED,
00043 FLAG_GREEN = 1 << PARAM_GREEN,
00044 FLAG_BLUE = 1 << PARAM_BLUE,
00045 FLAG_ALPHA = 1 << PARAM_ALPHA,
00046 FLAG_SIZE = 1 << PARAM_SIZE,
00047 FLAG_MASS = 1 << PARAM_MASS,
00048 FLAG_ANGLE = 1 << PARAM_ANGLE,
00049 FLAG_TEXTURE_INDEX = 1 << PARAM_TEXTURE_INDEX,
00050 FLAG_ROTATION_SPEED = 1 << PARAM_ROTATION_SPEED,
00051 FLAG_CUSTOM_0 = 1 << PARAM_CUSTOM_0,
00052 FLAG_CUSTOM_1 = 1 << PARAM_CUSTOM_1,
00053 FLAG_CUSTOM_2 = 1 << PARAM_CUSTOM_2,
00054 };
00055
00095 class SPK_PREFIX Model : public Registerable
00096 {
00097 friend class Particle;
00098
00099 SPK_IMPLEMENT_REGISTERABLE(Model)
00100
00101 public :
00102
00104
00106
00124 Model(int enableFlag = FLAG_RED | FLAG_GREEN | FLAG_BLUE,int mutableFlag = FLAG_NONE,int randomFlag = FLAG_NONE,int interpolatedFlag = FLAG_NONE);
00125
00130 Model(const Model& model);
00131
00141 static Model* create(int enableFlag = FLAG_RED | FLAG_GREEN | FLAG_BLUE,int mutableFlag = FLAG_NONE,int randomFlag = FLAG_NONE,int interpolatedFlag = FLAG_NONE);
00142
00144
00146
00148 ~Model();
00149
00151
00153
00163 void setLifeTime(float lifeTimeMin,float lifeTimeMax);
00164
00174 void setImmortal(bool immortal);
00175
00189 bool setParam(ModelParam type,float startMin,float startMax,float endMin,float endMax);
00190
00205 bool setParam(ModelParam type,float value0,float value1);
00206
00220 bool setParam(ModelParam type,float value);
00221
00223
00225
00230 float getLifeTimeMin() const;
00231
00236 float getLifeTimeMax() const;
00237
00242 bool isImmortal() const;
00243
00249 int isEnabled(ModelParam type) const;
00250
00256 int isMutable(ModelParam type) const;
00257
00263 int isRandom(ModelParam type) const;
00264
00271 int isInterpolated(ModelParam type) const;
00272
00313 float getParamValue(ModelParam type,size_t index) const;
00314
00329 unsigned int getNbValues(ModelParam type) const;
00330
00336 size_t getNbEnabled() const;
00337
00343 size_t getNbMutable() const;
00344
00345
00351 size_t getNRandom() const;
00352
00359 Interpolator* getInterpolator(ModelParam param);
00360
00366 size_t getNbInterpolated() const;
00367
00377 size_t getSizeOfParticleCurrentArray() const;
00378
00388 size_t getSizeOfParticleExtendedArray() const;
00389
00398 size_t getSizeOfModelArray() const;
00399
00409 size_t getParameterOffset(ModelParam param) const;
00410
00417 static float getDefaultValue(ModelParam param);
00418
00419 private :
00420
00421
00422 static const size_t NB_PARAMS = 12;
00423
00424 static const float DEFAULT_VALUES[NB_PARAMS];
00425
00426
00427
00428
00429
00430
00431
00432 float* params;
00433 size_t paramsSize;
00434
00435
00436 size_t nbEnableParams;
00437 int* enableParams;
00438
00439
00440 size_t nbMutableParams;
00441 int* mutableParams;
00442
00443
00444 size_t nbInterpolatedParams;
00445 int* interpolatedParams;
00446
00447
00448 size_t nbRandomParams;
00449
00450
00451 Interpolator* interpolators[NB_PARAMS];
00452
00453
00454 int enableFlag;
00455 int mutableFlag;
00456 int randomFlag;
00457 int interpolatedFlag;
00458
00459 int particleEnableIndices[NB_PARAMS];
00460 int particleMutableIndices[NB_PARAMS];
00461 int indices[NB_PARAMS];
00462
00463 float lifeTimeMin;
00464 float lifeTimeMax;
00465 bool immortal;
00466
00467 void initParamArrays(const Model& model);
00468 };
00469
00470
00471 inline Model* Model::create(int enableFlag,int mutableFlag,int randomFlag,int interpolatedFlag)
00472 {
00473 Model* obj = new Model(enableFlag,mutableFlag,randomFlag,interpolatedFlag);
00474 registerObject(obj);
00475 return obj;
00476 }
00477
00478 inline void Model::setLifeTime(float lifeTimeMin,float lifeTimeMax)
00479 {
00480 this->lifeTimeMin = lifeTimeMin;
00481 this->lifeTimeMax = lifeTimeMax;
00482 }
00483
00484 inline void Model::setImmortal(bool immortal)
00485 {
00486 this->immortal = immortal;
00487 }
00488
00489 inline float Model::getLifeTimeMin() const
00490 {
00491 return lifeTimeMin;
00492 }
00493
00494 inline float Model::getLifeTimeMax() const
00495 {
00496 return lifeTimeMax;
00497 }
00498
00499 inline bool Model::isImmortal() const
00500 {
00501 return immortal;
00502 }
00503
00504 inline int Model::isEnabled(ModelParam type) const
00505 {
00506 return enableFlag & (1 << type);
00507 }
00508
00509 inline int Model::isMutable(ModelParam type) const
00510 {
00511 return mutableFlag & (1 << type);
00512 }
00513
00514 inline int Model::isRandom(ModelParam type) const
00515 {
00516 return randomFlag & (1 << type);
00517 }
00518
00519 inline int Model::isInterpolated(ModelParam type) const
00520 {
00521 return interpolatedFlag & (1 << type);
00522 }
00523
00524 inline size_t Model::getNbEnabled() const
00525 {
00526 return nbEnableParams;
00527 }
00528
00529 inline size_t Model::getNbMutable() const
00530 {
00531 return nbMutableParams;
00532 }
00533
00534 inline size_t Model::getNRandom() const
00535 {
00536 return nbRandomParams;
00537 }
00538
00539 inline Interpolator* Model::getInterpolator(ModelParam param)
00540 {
00541 return interpolators[param];
00542 }
00543
00544 inline size_t Model::getNbInterpolated() const
00545 {
00546 return nbInterpolatedParams;
00547 }
00548
00549 inline size_t Model::getSizeOfParticleCurrentArray() const
00550 {
00551 return nbEnableParams;
00552 }
00553
00554 inline size_t Model::getSizeOfParticleExtendedArray() const
00555 {
00556 return nbMutableParams + (nbInterpolatedParams << 1) + nbInterpolatedParams;
00557 }
00558
00559 inline size_t Model::getSizeOfModelArray() const
00560 {
00561 return paramsSize;
00562 }
00563
00564 inline size_t Model::getParameterOffset(ModelParam param) const
00565 {
00566 return static_cast<size_t>(particleEnableIndices[param]);
00567 }
00568 }
00569
00570 #endif