00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "ParticleSysComponent.h"
00018 #include "../../core/GameManager.h"
00019
00020
00021
00022
00023 ParticleSysComponent::ParticleSysComponent(Entity *parent, const vector3df &rotation,
00024 const vector3df &scale)
00025 : SceneComponent(parent, true)
00026 {
00027
00028 ISceneManager *pSceneMgr = GameManager::Instance()->getSceneManager();
00029
00030
00031 mParticleSystemSN = pSceneMgr->addParticleSystemSceneNode(true, 0, parent->getID(),
00032 parent->getPosition(), rotation,
00033 scale);
00034 mSceneNode = mParticleSystemSN;
00035
00036
00037 mTriSelector = NULL;
00038 mMetaSelector = pSceneMgr->createMetaTriangleSelector();
00039 }
00040
00041
00042 ParticleSysComponent::~ParticleSysComponent()
00043 {
00044 mParticleSystemSN->remove();
00045 mSceneNode = NULL;
00046 }
00047
00048
00049 ParticleSysComponent* ParticleSysComponent::refFactory(Entity *parent, const vector3df &rotation,
00050 const vector3df &scale)
00051 {
00052 return new ParticleSysComponent(parent, rotation, scale);
00053 }
00054
00055
00056 IParticleSystemSceneNode* ParticleSysComponent::getParticleSystemSceneNode()
00057 {
00058 return mParticleSystemSN;
00059 }
00060
00061
00062 void ParticleSysComponent::addAffector(IParticleAffector *affector)
00063 {
00064 mParticleSystemSN->addAffector(affector);
00065 }
00066
00067
00068 void ParticleSysComponent::addAttractionAffector(const vector3df &point, f32 speed, bool attract,
00069 bool affectX, bool affectY, bool affectZ)
00070 {
00071 IParticleAffector *affector = mParticleSystemSN->createAttractionAffector(point, speed, attract,
00072 affectX, affectY, affectZ);
00073 mParticleSystemSN->addAffector(affector);
00074 affector->drop();
00075 }
00076
00077
00078 void ParticleSysComponent::addFadeOutParticleAffector(const SColor &targetColor,
00079 u32 timeNeededToFadeOut)
00080 {
00081 IParticleAffector *affector = mParticleSystemSN->createFadeOutParticleAffector(targetColor,
00082 timeNeededToFadeOut);
00083 mParticleSystemSN->addAffector(affector);
00084 affector->drop();
00085 }
00086
00087
00088 void ParticleSysComponent::addGravityAffector(const vector3df &gravity, u32 timeForceLost)
00089 {
00090 IParticleAffector *affector = mParticleSystemSN->createGravityAffector(gravity, timeForceLost);
00091 mParticleSystemSN->addAffector(affector);
00092 affector->drop();
00093 }
00094
00095
00096 void ParticleSysComponent::addRotationAffector(const vector3df &speed, const vector3df &pivotPoint)
00097 {
00098 IParticleAffector *affector = mParticleSystemSN->createRotationAffector(speed, pivotPoint);
00099 mParticleSystemSN->addAffector(affector);
00100 affector->drop();
00101 }
00102
00103
00104 void ParticleSysComponent::addScaleParticleAffector(const dimension2df &scaleTo)
00105 {
00106 IParticleAffector *affector = mParticleSystemSN->createScaleParticleAffector(scaleTo);
00107 mParticleSystemSN->addAffector(affector);
00108 affector->drop();
00109 }
00110
00111
00112 void ParticleSysComponent::removeAffectors()
00113 {
00114 mParticleSystemSN->removeAllAffectors();
00115 }
00116
00117
00118 IParticleEmitter* ParticleSysComponent::getEmitter()
00119 {
00120 return mParticleSystemSN->getEmitter();
00121 }
00122
00123
00124 void ParticleSysComponent::setAnimatedMeshSceneNodeEmitter(const std::string &fileName,
00125 bool useNormalDirection,
00126 const vector3df &direction,
00127 f32 normalDirectionModifier,
00128 bool everyMeshVertex,
00129 u32 minParticlesPerSecond,
00130 u32 maxParticlesPerSecond,
00131 const SColor &minStartColor,
00132 const SColor &maxStartColor,
00133 u32 lifeTimeMin, u32 lifeTimeMax,
00134 s32 maxAngleDegrees,
00135 const dimension2df &minStartSize,
00136 const dimension2df &maxStartSize)
00137 {
00138 ISceneManager *pSceneMgr = GameManager::Instance()->getSceneManager();
00139
00140 IAnimatedMeshSceneNode *node = pSceneMgr->addAnimatedMeshSceneNode(pSceneMgr->getMesh(
00141 fileName.c_str()), 0, pParent->getID());
00142 if(node)
00143 {
00144 IParticleEmitter *emitter = mParticleSystemSN->createAnimatedMeshSceneNodeEmitter(node,
00145 useNormalDirection,
00146 direction, normalDirectionModifier, -1, everyMeshVertex,
00147 minParticlesPerSecond, maxParticlesPerSecond, minStartColor,
00148 maxStartColor, lifeTimeMin, lifeTimeMax, maxAngleDegrees,
00149 minStartSize, maxStartSize);
00150 mParticleSystemSN->setEmitter(emitter);
00151 emitter->drop();
00152 }
00153 }
00154
00155
00156 void ParticleSysComponent::setAnimatedMeshSceneNodeEmitter(IAnimatedMeshSceneNode *node,
00157 bool useNormalDirection,
00158 const vector3df &direction,
00159 f32 normalDirectionModifier,
00160 bool everyMeshVertex,
00161 u32 minParticlesPerSecond,
00162 u32 maxParticlesPerSecond,
00163 const SColor &minStartColor,
00164 const SColor &maxStartColor,
00165 u32 lifeTimeMin, u32 lifeTimeMax,
00166 s32 maxAngleDegrees,
00167 const dimension2df &minStartSize,
00168 const dimension2df &maxStartSize)
00169 {
00170 IParticleEmitter *emitter = mParticleSystemSN->createAnimatedMeshSceneNodeEmitter(node,
00171 useNormalDirection, direction, normalDirectionModifier, -1,
00172 everyMeshVertex, minParticlesPerSecond, maxParticlesPerSecond,
00173 minStartColor, maxStartColor, lifeTimeMin, lifeTimeMax,
00174 maxAngleDegrees, minStartSize, maxStartSize);
00175 mParticleSystemSN->setEmitter(emitter);
00176 emitter->drop();
00177 }
00178
00179
00180 void ParticleSysComponent::setBoxEmitter(const aabbox3df &box, const vector3df &direction,
00181 u32 minParticlesPerSecond, u32 maxParticlesPerSecond,
00182 const SColor &minStartColor, const SColor &maxStartColor,
00183 u32 lifeTimeMin, u32 lifeTimeMax, s32 maxAngleDegrees,
00184 const dimension2df &minStartSize,
00185 const dimension2df &maxStartSize)
00186 {
00187 IParticleEmitter *emitter = mParticleSystemSN->createBoxEmitter(box, direction,
00188 minParticlesPerSecond, maxParticlesPerSecond, minStartColor,
00189 maxStartColor, lifeTimeMin, lifeTimeMax, maxAngleDegrees,
00190 minStartSize, maxStartSize);
00191 mParticleSystemSN->setEmitter(emitter);
00192 emitter->drop();
00193 }
00194
00195
00196 void ParticleSysComponent::setCylinderEmitter(const vector3df ¢er, f32 radius,
00197 const vector3df &normal, f32 length,
00198 bool outlineOnly, const vector3df &direction,
00199 u32 minParticlesPerSecond, u32 maxParticlesPerSecond,
00200 const SColor &minStartColor,
00201 const SColor &maxStartColor,
00202 u32 lifeTimeMin, u32 lifeTimeMax, s32 maxAngleDegrees,
00203 const dimension2df &minStartSize,
00204 const dimension2df &maxStartSize)
00205 {
00206 IParticleEmitter *emitter = mParticleSystemSN->createCylinderEmitter(center, radius, normal,
00207 length, outlineOnly, direction, minParticlesPerSecond,
00208 maxParticlesPerSecond, minStartColor, maxStartColor, lifeTimeMin,
00209 lifeTimeMax, maxAngleDegrees, minStartSize, maxStartSize);
00210 mParticleSystemSN->setEmitter(emitter);
00211 emitter->drop();
00212 }
00213
00214
00215 void ParticleSysComponent::setEmitter(IParticleEmitter *emitter)
00216 {
00217 mParticleSystemSN->setEmitter(emitter);
00218 }
00219
00220
00221 void ParticleSysComponent::setMeshEmitter(const std::string &fileName, bool useNormalDirection,
00222 const vector3df &direction, f32 normalDirectionModifier,
00223 bool everyMeshVertex, u32 minParticlesPerSecond,
00224 u32 maxParticlesPerSecond, const SColor &minStartColor,
00225 const SColor &maxStartColor, u32 lifeTimeMin,
00226 u32 lifeTimeMax, s32 maxAngleDegrees,
00227 const dimension2df &minStartSize,
00228 const dimension2df &maxStartSize)
00229 {
00230 IMesh *mesh = GameManager::Instance()->getSceneManager()->getMesh(fileName.c_str());
00231
00232 if(mesh)
00233 {
00234 IParticleEmitter *emitter = mParticleSystemSN->createMeshEmitter(mesh, useNormalDirection,
00235 direction, normalDirectionModifier, -1, everyMeshVertex,
00236 minParticlesPerSecond, maxParticlesPerSecond,
00237 minStartColor, maxStartColor, lifeTimeMin, lifeTimeMax,
00238 maxAngleDegrees, minStartSize, maxStartSize);
00239 mParticleSystemSN->setEmitter(emitter);
00240 emitter->drop();
00241 }
00242 }
00243
00244
00245 void ParticleSysComponent::setMeshEmitter(IMesh *mesh, bool useNormalDirection,
00246 const vector3df &direction,
00247 f32 normalDirectionModifier, bool everyMeshVertex,
00248 u32 minParticlesPerSecond, u32 maxParticlesPerSecond,
00249 const SColor &minStartColor, const SColor &maxStartColor,
00250 u32 lifeTimeMin, u32 lifeTimeMax, s32 maxAngleDegrees,
00251 const dimension2df &minStartSize,
00252 const dimension2df &maxStartSize)
00253 {
00254 IParticleEmitter *emitter = mParticleSystemSN->createMeshEmitter(mesh, useNormalDirection,
00255 direction, normalDirectionModifier, -1, everyMeshVertex,
00256 minParticlesPerSecond, maxParticlesPerSecond,
00257 minStartColor, maxStartColor, lifeTimeMin, lifeTimeMax,
00258 maxAngleDegrees, minStartSize, maxStartSize);
00259 mParticleSystemSN->setEmitter(emitter);
00260 emitter->drop();
00261 }
00262
00263
00264 void ParticleSysComponent::setPointEmitter(const vector3df &direction,
00265 u32 minParticlesPerSecond, u32 maxParticlesPerSecond,
00266 const SColor &minStartColor, const SColor &maxStartColor,
00267 u32 lifeTimeMin, u32 lifeTimeMax, s32 maxAngleDegrees,
00268 const dimension2df &minStartSize,
00269 const dimension2df &maxStartSize)
00270 {
00271 IParticleEmitter *emitter = mParticleSystemSN->createPointEmitter(direction,
00272 minParticlesPerSecond, maxParticlesPerSecond, minStartColor,
00273 maxStartColor, lifeTimeMin, lifeTimeMax, maxAngleDegrees,
00274 minStartSize, maxStartSize);
00275 mParticleSystemSN->setEmitter(emitter);
00276 emitter->drop();
00277 }
00278
00279
00280 void ParticleSysComponent::setRingEmitter(const vector3df ¢er, f32 radius,
00281 f32 ringThickness, const vector3df &direction,
00282 u32 minParticlesPerSecond, u32 maxParticlesPerSecond,
00283 const SColor &minStartColor, const SColor &maxStartColor,
00284 u32 lifeTimeMin, u32 lifeTimeMax, s32 maxAngleDegrees,
00285 const dimension2df &minStartSize,
00286 const dimension2df &maxStartSize)
00287 {
00288 IParticleEmitter *emitter = mParticleSystemSN->createRingEmitter(center, radius, ringThickness,
00289 direction, minParticlesPerSecond, maxParticlesPerSecond,
00290 minStartColor, maxStartColor, lifeTimeMin, lifeTimeMax,
00291 maxAngleDegrees, minStartSize, maxStartSize);
00292 mParticleSystemSN->setEmitter(emitter);
00293 emitter->drop();
00294 }
00295
00296
00297 void ParticleSysComponent::setSphereEmitter(const vector3df ¢er, f32 radius,
00298 const vector3df &direction,
00299 u32 minParticlesPerSecond, u32 maxParticlesPerSecond,
00300 const SColor &minStartColor,
00301 const SColor &maxStartColor,
00302 u32 lifeTimeMin, u32 lifeTimeMax, s32 maxAngleDegrees,
00303 const dimension2df &minStartSize,
00304 const dimension2df &maxStartSize)
00305 {
00306 IParticleEmitter *emitter = mParticleSystemSN->createSphereEmitter(center, radius, direction,
00307 minParticlesPerSecond, maxParticlesPerSecond, minStartColor,
00308 maxStartColor, lifeTimeMin, lifeTimeMax, maxAngleDegrees,
00309 minStartSize, maxStartSize);
00310 mParticleSystemSN->setEmitter(emitter);
00311 emitter->drop();
00312 }
00313
00314
00315 void ParticleSysComponent::setParticlesAreGlobal(bool value)
00316 {
00317 mParticleSystemSN->setParticlesAreGlobal(value);
00318 }
00319
00320
00321 void ParticleSysComponent::setParticleSize(const dimension2df &size)
00322 {
00323 mParticleSystemSN->setParticleSize(size);
00324 }
00325
00326
00327
00328 void bindParticleSysComponent(asIScriptEngine *engine)
00329 {
00330
00331 int r;
00332
00333
00334 r = engine->RegisterObjectType("ParticleSysComponent", sizeof(ParticleSysComponent), asOBJ_REF); assert(r >= 0);
00335
00336
00337 bindSceneComponentBase<ParticleSysComponent>(engine, "ParticleSysComponent");
00338
00339
00340 r = engine->RegisterObjectBehaviour("ParticleSysComponent", asBEHAVE_FACTORY, "ParticleSysComponent@ f(Entity @, " \
00341 "const vector3df &in, const vector3df &in)",
00342 asFUNCTIONPR(ParticleSysComponent::refFactory, (Entity*, const vector3df&,
00343 const vector3df&), ParticleSysComponent*), asCALL_CDECL); assert(r >= 0);
00344
00345
00346 r = engine->RegisterObjectMethod("ParticleSysComponent", "void addAttractionAffector(const vector3df &in, f32, " \
00347 "bool, bool, bool, bool)", asMETHOD(ParticleSysComponent, addAttractionAffector),
00348 asCALL_THISCALL); assert(r >= 0);
00349 r = engine->RegisterObjectMethod("ParticleSysComponent", "void addFadeOutParticleAffector(const SColor &in, u32)",
00350 asMETHOD(ParticleSysComponent, addFadeOutParticleAffector), asCALL_THISCALL); assert(r >= 0);
00351 r = engine->RegisterObjectMethod("ParticleSysComponent", "void addGravityAffector(const vector3df &in, u32)",
00352 asMETHOD(ParticleSysComponent, addGravityAffector), asCALL_THISCALL); assert(r >= 0);
00353 r = engine->RegisterObjectMethod("ParticleSysComponent", "void addRotationAffector(const vector3df &in, const vector3df &in)",
00354 asMETHOD(ParticleSysComponent, addRotationAffector), asCALL_THISCALL); assert(r >= 0);
00355 r = engine->RegisterObjectMethod("ParticleSysComponent", "void addScaleParticleAffector(const dimension2df &in)",
00356 asMETHOD(ParticleSysComponent, addScaleParticleAffector), asCALL_THISCALL); assert(r >= 0);
00357 r = engine->RegisterObjectMethod("ParticleSysComponent", "void removeAffectors()",
00358 asMETHOD(ParticleSysComponent, removeAffectors), asCALL_THISCALL); assert(r >= 0);
00359
00360 r = engine->RegisterObjectMethod("ParticleSysComponent", "void setAnimatedMeshSceneNodeEmitter(const string &, " \
00361 "bool, const vector3df &in, f32, bool, u32, u32, const SColor &in, " \
00362 "const SColor &in, u32, u32, s32, const dimension2df &in, const dimension2df &in)",
00363 asMETHODPR(ParticleSysComponent, setAnimatedMeshSceneNodeEmitter,
00364 (const std::string&, bool, const vector3df&, f32, bool, u32, u32,
00365 const SColor&, const SColor&, u32, u32, s32,const dimension2df&,
00366 const dimension2df &), void), asCALL_THISCALL); assert(r >= 0);
00367 r = engine->RegisterObjectMethod("ParticleSysComponent", "void setBoxEmitter(const aabbox3df &in, const vector3df &in, " \
00368 "u32, u32, const SColor &in, const SColor &in, u32, u32, s32, " \
00369 "const dimension2df &in, const dimension2df &in)",
00370 asMETHOD(ParticleSysComponent, setBoxEmitter), asCALL_THISCALL); assert(r >= 0);
00371 r = engine->RegisterObjectMethod("ParticleSysComponent", "void setCylinderEmitter(const vector3df &in, f32, " \
00372 "const vector3df &in, f32, bool, const vector3df &in, u32, u32, " \
00373 "const SColor &in, const SColor &in, u32, u32, s32, const dimension2df &in, " \
00374 "const dimension2df &in)", asMETHOD(ParticleSysComponent, setCylinderEmitter),
00375 asCALL_THISCALL); assert(r >= 0);
00376 r = engine->RegisterObjectMethod("ParticleSysComponent", "void setMeshEmitter(const string&, bool, " \
00377 "const vector3df &in, f32, bool, u32, u32, const SColor &in, const SColor &in, " \
00378 "u32, u32, s32, const dimension2df &in, const dimension2df &in)",
00379 asMETHODPR(ParticleSysComponent, setMeshEmitter, (const std::string&, bool,
00380 const vector3df&, f32, bool, u32, u32, const SColor&, const SColor&, u32, u32, s32,
00381 const dimension2df&, const dimension2df&), void), asCALL_THISCALL); assert(r >= 0);
00382 r = engine->RegisterObjectMethod("ParticleSysComponent", "void setPointEmitter(const vector3df &in, u32, u32, " \
00383 "const SColor &in, const SColor &in, u32, u32, s32, const dimension2df &in, " \
00384 "const dimension2df &in)", asMETHOD(ParticleSysComponent, setPointEmitter),
00385 asCALL_THISCALL); assert(r >= 0);
00386 r = engine->RegisterObjectMethod("ParticleSysComponent", "void setRingEmitter(const vector3df &in, f32, f32, " \
00387 "const vector3df &in, u32, u32, const SColor &in, const SColor &in, " \
00388 "u32, u32, s32, const dimension2df &in, const dimension2df &in)",
00389 asMETHOD(ParticleSysComponent, setRingEmitter), asCALL_THISCALL); assert(r >= 0);
00390 r = engine->RegisterObjectMethod("ParticleSysComponent", "void setSphereEmitter(const vector3df &in, f32, " \
00391 "const vector3df &in, u32, u32, const SColor &in, const SColor &in, " \
00392 "u32, u32, s32, const dimension2df &in, const dimension2df &in)",
00393 asMETHOD(ParticleSysComponent, setSphereEmitter), asCALL_THISCALL); assert(r >= 0);
00394
00395 r = engine->RegisterObjectMethod("ParticleSysComponent", "void setParticlesAreGlobal()",
00396 asMETHOD(ParticleSysComponent, setParticlesAreGlobal), asCALL_THISCALL); assert(r >= 0);
00397 r = engine->RegisterObjectMethod("ParticleSysComponent", "void setParticlesAreGlobal(bool)",
00398 asMETHOD(ParticleSysComponent, setParticlesAreGlobal), asCALL_THISCALL); assert(r >= 0);
00399 r = engine->RegisterObjectMethod("ParticleSysComponent", "void setParticleSize(const dimension2df &in)",
00400 asMETHOD(ParticleSysComponent, setParticleSize), asCALL_THISCALL); assert(r >= 0);
00401 }
00402
00403