00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00036
00037 #include "SO3SCOL.h"
00038
00039
00040 #include "../SO3SceneGraph/SO3ParticleSystem.h"
00041
00042
00043 #include "../SO3SceneGraph/SO3Scene.h"
00044
00055 int SO3ParticleSystemCreateFromTemplate(mmachine m)
00056 {
00057 #ifdef SO3_DEBUG
00058 MMechostr(MSKDEBUG, "SO3ParticleSystemCreateFromTemplate\n");
00059 #endif
00060
00061 int temp = MMpull(m);
00062 int name = MMpull(m);
00063 int s = MMget(m, 0);
00064 if((s==NIL)||(temp==NIL)||(name==NIL))
00065 {
00066 MMset(m, 0, NIL);
00067 return 0;
00068 }
00069
00070 SScene* scene = (SScene*) MMfetch(m, MTOP(s), 0);
00071 if(scene==NULL)
00072 {
00073 MMset(m, 0, NIL);
00074 return 0;
00075 }
00076
00077 std::string tmpParticleSystemName(MMstartstr(m, MTOP(name)));
00078 std::string tmpParticleSystemtTemplate(MMstartstr(m, MTOP(temp)));
00079 SParticleSystem* particlesystem = 0;
00080
00081 try
00082 {
00083 particlesystem = scene->CreateParticleSystem(tmpParticleSystemName, tmpParticleSystemtTemplate);
00084 }
00085 catch(Ogre::Exception& e)
00086 {
00087 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
00088 MMset(m, 0, NIL);
00089 return 0;
00090 }
00091
00092
00093 MMpull(m);
00094 return createObject(m, particlesystem, scene);
00095 }
00096
00097
00106 int SO3ParticleSystemGetTemplate(mmachine m)
00107 {
00108 #ifdef SO3_DEBUG
00109 MMechostr(MSKDEBUG, "SO3ParticleSystemGetTemplate\n");
00110 #endif
00111
00112 int ps = MMpull(m);
00113 if(ps==NIL)
00114 {
00115 MMpush(m, NIL);
00116 return 0;
00117 }
00118
00119 SNode* node = (SNode*) MMfetch(m, MTOP(ps), 0);
00120 if(node==0)
00121 {
00122 MMpush(m, NIL);
00123 return 0;
00124 }
00125
00126 if(node->GetNodeType() != SNode::PARTICLE_SYSTEM_TYPE_ID)
00127 {
00128 MMpush(m, NIL);
00129 return 0;
00130 }
00131
00132 SParticleSystem* particlesystem = static_cast<SParticleSystem*> (node);
00133 if(particlesystem==0)
00134 {
00135 MMpush(m, NIL);
00136 return 0;
00137 }
00138
00139 return Mpushstrbloc(m, (char*)(particlesystem->GetParticleTemplateName().c_str()));
00140 }
00141
00142
00152 int SO3ParticleSystemSetEnable(mmachine m)
00153 {
00154 #ifdef SO3_DEBUG
00155 MMechostr(MSKDEBUG, "SO3ParticleSystemSetEnable\n");
00156 #endif
00157
00158 int b = MTOI(MMpull(m));
00159 int ps = MMget(m, 0);
00160 if((ps==NIL)||(b==NIL))
00161 {
00162 MMset(m, 0, NIL);
00163 return 0;
00164 }
00165
00166 SNode* node = (SNode*) MMfetch(m, MTOP(ps), 0);
00167 if(node==0)
00168 {
00169 MMset(m, 0, NIL);
00170 return 0;
00171 }
00172
00173 if(node->GetNodeType() != SNode::PARTICLE_SYSTEM_TYPE_ID)
00174 {
00175 MMset(m, 0, NIL);
00176 return 0;
00177 }
00178 SParticleSystem* particlesystem = static_cast<SParticleSystem*> (node);
00179
00180 if(b==0)
00181 particlesystem->SetEnable(false);
00182 else
00183 particlesystem->SetEnable(true);
00184
00185 MMset(m,0, ITOM(1));
00186 return 0;
00187
00188 }
00189
00190
00199 int SO3ParticleSystemGetEnable(mmachine m)
00200 {
00201 #ifdef SO3_DEBUG
00202 MMechostr(MSKDEBUG,"SO3ParticleSystemGetEnable\n");
00203 #endif
00204
00205 int ps = MMget(m, 0);
00206 if(ps==NIL)
00207 {
00208 MMset(m, 0, NIL);
00209 return 0;
00210 }
00211
00212 SNode* node = (SNode*) MMfetch(m, MTOP(ps), 0);
00213 if(node==0)
00214 {
00215 MMset(m, 0, NIL);
00216 return 0;
00217 }
00218
00219 if(node->GetNodeType() != SNode::PARTICLE_SYSTEM_TYPE_ID)
00220 {
00221 MMset(m, 0, NIL);
00222 return 0;
00223 }
00224 SParticleSystem* particlesystem = static_cast<SParticleSystem*> (node);
00225
00226 int val = 0;
00227 if(particlesystem->GetEnable())
00228 val = 1;
00229
00230 MMset(m, 0, ITOM(val));
00231 return 0;
00232 }
00233
00234
00244 int SO3ParticleSystemSetPause(mmachine m)
00245 {
00246 #ifdef SO3_DEBUG
00247 MMechostr(MSKDEBUG,"SO3ParticleSystemSetPause\n");
00248 #endif
00249
00250 int b = MTOI(MMpull(m));
00251 int ps = MMget(m,0);
00252 if((ps==NIL)||(b==NIL))
00253 {
00254 MMset(m, 0, NIL);
00255 return 0;
00256 }
00257
00258 SNode* node = (SNode*) MMfetch(m, MTOP(ps), 0);
00259 if(node==0)
00260 {
00261 MMset(m, 0, NIL);
00262 return 0;
00263 }
00264
00265 if(node->GetNodeType() != SNode::PARTICLE_SYSTEM_TYPE_ID)
00266 {
00267 MMset(m, 0, NIL);
00268 return 0;
00269 }
00270 SParticleSystem* particlesystem = static_cast<SParticleSystem*> (node);
00271
00272 if(b == 0)
00273 particlesystem->SetPaused(false);
00274 else
00275 particlesystem->SetPaused(true);
00276
00277 MMset(m, 0, ITOM(1));
00278 return 0;
00279 }
00280
00281
00290 int SO3ParticleSystemGetPause(mmachine m)
00291 {
00292 #ifdef SO3_DEBUG
00293 MMechostr(MSKDEBUG,"SO3ParticleSystemGetPause\n");
00294 #endif
00295
00296 int ps = MMget(m, 0);
00297 if(ps==NIL)
00298 {
00299 MMset(m, 0, NIL);
00300 return 0;
00301 }
00302
00303 SNode* node = (SNode*) MMfetch(m, MTOP(ps), 0);
00304 if(node==0)
00305 {
00306 MMset(m, 0, NIL);
00307 return 0;
00308 }
00309
00310 if(node->GetNodeType() != SNode::PARTICLE_SYSTEM_TYPE_ID)
00311 {
00312 MMset(m, 0, NIL);
00313 return 0;
00314 }
00315 SParticleSystem* particlesystem = static_cast<SParticleSystem*> (node);
00316
00317 int val = 0;
00318 if(particlesystem->GetPaused())
00319 val = 1;
00320
00321 MMset(m, 0, ITOM(val));
00322 return 0;
00323 }
00324
00325
00335 int SO3ParticleSystemSetSpeedFactor(mmachine m)
00336 {
00337 #ifdef SO3_DEBUG
00338 MMechostr(MSKDEBUG, "SO3ParticleSystemSetSpeedFactor\n");
00339 #endif
00340
00341 int sf = MMpull(m);
00342 int ps = MMget(m,0);
00343 if((ps==NIL)||(sf==NIL))
00344 {
00345 MMset(m, 0, NIL);
00346 return 0;
00347 }
00348
00349 SNode* node = (SNode*) MMfetch(m, MTOP(ps), 0);
00350 if(node==0)
00351 {
00352 MMset(m, 0, NIL);
00353 return 0;
00354 }
00355
00356 if(node->GetNodeType() != SNode::PARTICLE_SYSTEM_TYPE_ID)
00357 {
00358 MMset(m, 0, NIL);
00359 return 0;
00360 }
00361 SParticleSystem* particlesystem = static_cast<SParticleSystem*> (node);
00362
00363 particlesystem->SetSpeed(MTOF(sf));
00364 MMset(m, 0, ITOM(1));
00365 return 0;
00366 }
00367
00368
00377 int SO3ParticleSystemGetSpeedFactor(mmachine m)
00378 {
00379 #ifdef SO3_DEBUG
00380 MMechostr(MSKDEBUG, "SO3ParticleSystemGetSpeedFactor\n");
00381 #endif
00382
00383 int ps = MMget(m,0);
00384 if(ps==NIL)
00385 {
00386 MMset(m, 0, NIL);
00387 return 0;
00388 }
00389
00390 SNode* node = (SNode*) MMfetch(m, MTOP(ps), 0);
00391 if(node==0)
00392 {
00393 MMset(m, 0, NIL);
00394 return 0;
00395 }
00396
00397 if(node->GetNodeType() != SNode::PARTICLE_SYSTEM_TYPE_ID)
00398 {
00399 MMset(m, 0, NIL);
00400 return 0;
00401 }
00402 SParticleSystem* particlesystem = static_cast<SParticleSystem*> (node);
00403
00404 MMset(m, 0, FTOM(particlesystem->GetSpeed()));
00405 return 0;
00406 }
00407
00408
00417 int SO3ParticleSystemClear(mmachine m)
00418 {
00419 #ifdef SO3_DEBUG
00420 MMechostr(MSKDEBUG,"SO3ParticleSystemClear\n");
00421 #endif
00422
00423 int ps = MMget(m,0);
00424 if(ps==NIL)
00425 {
00426 MMset(m, 0, NIL);
00427 return 0;
00428 }
00429
00430 SNode* node = (SNode*) MMfetch(m, MTOP(ps), 0);
00431 if(node==0)
00432 {
00433 MMset(m, 0, NIL);
00434 return 0;
00435 }
00436
00437 if(node->GetNodeType() != SNode::PARTICLE_SYSTEM_TYPE_ID)
00438 {
00439 MMset(m, 0, NIL);
00440 return 0;
00441 }
00442 SParticleSystem* particlesystem = static_cast<SParticleSystem*> (node);
00443
00444 particlesystem->ClearParticles();
00445 MMset(m, 0, ITOM(1));
00446 return 0;
00447 }
00448
00449
00453 #define NBPARTICLEPKG 9
00454
00455 char* PARTICLEname[NBPARTICLEPKG]=
00456 {
00457 "SO3ParticleSystemCreateFromTemplate",
00458 "SO3ParticleSystemGetTemplate",
00459 "SO3ParticleSystemSetEnable",
00460 "SO3ParticleSystemGetEnable",
00461 "SO3ParticleSystemSetPause",
00462 "SO3ParticleSystemGetPause",
00463 "SO3ParticleSystemSetSpeedFactor",
00464 "SO3ParticleSystemGetSpeedFactor",
00465 "SO3ParticleSystemClear"
00466 };
00467
00468
00472 int (*PARTICLEFunc[NBPARTICLEPKG])(mmachine m)=
00473 {
00474
00475 SO3ParticleSystemCreateFromTemplate,
00476 SO3ParticleSystemGetTemplate,
00477 SO3ParticleSystemSetEnable,
00478 SO3ParticleSystemGetEnable,
00479 SO3ParticleSystemSetPause,
00480 SO3ParticleSystemGetPause,
00481 SO3ParticleSystemSetSpeedFactor,
00482 SO3ParticleSystemGetSpeedFactor,
00483 SO3ParticleSystemClear
00484 };
00485
00486
00490 int PARTICLEnarg[NBPARTICLEPKG]=
00491 {
00492 3,
00493 1,
00494 2,
00495 1,
00496 2,
00497 1,
00498 2,
00499 1,
00500 1
00501 };
00502
00503
00507 char* PARTICLEType[NBPARTICLEPKG]=
00508 {
00509 "fun [SO3_SCENE S S] SO3_OBJECT",
00510 "fun [SO3_OBJECT] S",
00511 "fun [SO3_OBJECT I] I",
00512 "fun [SO3_OBJECT] I",
00513 "fun [SO3_OBJECT I] I",
00514 "fun [SO3_OBJECT] I",
00515 "fun [SO3_OBJECT F] I",
00516 "fun [SO3_OBJECT] F",
00517 "fun [SO3_OBJECT] I"
00518 };
00519
00520
00526 int SCOLloadParticle(mmachine m,cbmachine w)
00527 {
00528 return PKhardpak(m, "Particle", NBPARTICLEPKG, PARTICLEname, PARTICLEFunc, PARTICLEnarg, PARTICLEType);
00529 }
00530
00531
00536 int SCOLfreeParticle()
00537 {
00538 return 0;
00539 }
00540