SO3Engine
SCOLParticle.cpp
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OpenSpace3D
4For the latest info, see http://www.openspace3d.com
5
6Copyright (c) 2012 I-maginer
7
8This program is free software; you can redistribute it and/or modify it under
9the terms of the GNU Lesser General Public License as published by the Free Software
10Foundation; either version 2 of the License, or (at your option) any later
11version.
12
13This program is distributed in the hope that it will be useful, but WITHOUT
14ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public License along with
18this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20http://www.gnu.org/copyleft/lesser.txt
21
22-----------------------------------------------------------------------------
23*/
24
25
34#include "SCOLPack/SO3SCOL.h"
35
36// particles includes
38
39// Scene Graph includes
41
53{
54#ifdef SO3_DEBUG
55 MMechostr(MSKDEBUG, "SO3ParticleSystemCreateFromTemplate\n");
56#endif
57
58 int temp = MMpull(m);
59 int name = MMpull(m);
60 int s = MMget(m, 0);
61 if ((s == NIL) || (temp == NIL) || (name == NIL))
62 {
63 MMset(m, 0, NIL);
64 return 0;
65 }
66
67 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
68 if (scene == NULL)
69 {
70 MMset(m, 0, NIL);
71 return 0;
72 }
73
74 std::string tmpParticleSystemName(MMstartstr(m, MTOP(name)));
75 std::string tmpParticleSystemtTemplate(MMstartstr(m, MTOP(temp)));
76 SParticleSystem* particlesystem = 0;
77
78 try
79 {
80 particlesystem = scene->CreateParticleSystem(tmpParticleSystemName, tmpParticleSystemtTemplate);
81 }
82 catch (Ogre::Exception& e)
83 {
84 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
85 MMset(m, 0, NIL);
86 return 0;
87 }
88
89 // remove last param
90 MMpull(m);
91 return createObject(m, particlesystem, scene);
92}
93
94
104{
105#ifdef SO3_DEBUG
106 MMechostr(MSKDEBUG, "SO3ParticleSystemGetTemplate\n");
107#endif
108
109 int ps = MMpull(m);
110 if (ps == NIL)
111 {
112 MMpush(m, NIL);
113 return 0;
114 }
115
116 SNode* node = MMgetPointer<SNode*>(m, MTOP(ps));
117 if (node == 0)
118 {
119 MMpush(m, NIL);
120 return 0;
121 }
122
123 if (node->GetNodeType() != SNode::PARTICLE_SYSTEM_TYPE_ID)
124 {
125 MMpush(m, NIL);
126 return 0;
127 }
128
129 SParticleSystem* particlesystem = static_cast<SParticleSystem*> (node);
130 if (particlesystem == 0)
131 {
132 MMpush(m, NIL);
133 return 0;
134 }
135
136 return Mpushstrbloc(m, (char*)(particlesystem->GetParticleTemplateName().c_str()));
137}
138
139
150{
151#ifdef SO3_DEBUG
152 MMechostr(MSKDEBUG, "SO3ParticleSystemSetEnable\n");
153#endif
154
155 int b = MTOI(MMpull(m));
156 int ps = MMget(m, 0);
157 if ((ps == NIL) || (b == NIL))
158 {
159 MMset(m, 0, NIL);
160 return 0;
161 }
162
163 SNode* node = MMgetPointer<SNode*>(m, MTOP(ps));
164 if (node == 0)
165 {
166 MMset(m, 0, NIL);
167 return 0;
168 }
169
170 if (node->GetNodeType() != SNode::PARTICLE_SYSTEM_TYPE_ID)
171 {
172 MMset(m, 0, NIL);
173 return 0;
174 }
175 SParticleSystem* particlesystem = static_cast<SParticleSystem*> (node);
176
177 if (b == 0)
178 particlesystem->SetEnable(false);
179 else
180 particlesystem->SetEnable(true);
181
182 MMset(m, 0, ITOM(1));
183 return 0;
184
185}
186
187
197{
198#ifdef SO3_DEBUG
199 MMechostr(MSKDEBUG, "SO3ParticleSystemGetEnable\n");
200#endif
201
202 int ps = MMget(m, 0);
203 if (ps == NIL)
204 {
205 MMset(m, 0, NIL);
206 return 0;
207 }
208
209 SNode* node = MMgetPointer<SNode*>(m, MTOP(ps));
210 if (node == 0)
211 {
212 MMset(m, 0, NIL);
213 return 0;
214 }
215
216 if (node->GetNodeType() != SNode::PARTICLE_SYSTEM_TYPE_ID)
217 {
218 MMset(m, 0, NIL);
219 return 0;
220 }
221 SParticleSystem* particlesystem = static_cast<SParticleSystem*> (node);
222
223 int val = 0;
224 if (particlesystem->GetEnable())
225 val = 1;
226
227 MMset(m, 0, ITOM(val));
228 return 0;
229}
230
231
242{
243#ifdef SO3_DEBUG
244 MMechostr(MSKDEBUG, "SO3ParticleSystemSetPause\n");
245#endif
246
247 int b = MTOI(MMpull(m));
248 int ps = MMget(m, 0);
249 if ((ps == NIL) || (b == NIL))
250 {
251 MMset(m, 0, NIL);
252 return 0;
253 }
254
255 SNode* node = MMgetPointer<SNode*>(m, MTOP(ps));
256 if (node == 0)
257 {
258 MMset(m, 0, NIL);
259 return 0;
260 }
261
262 if (node->GetNodeType() != SNode::PARTICLE_SYSTEM_TYPE_ID)
263 {
264 MMset(m, 0, NIL);
265 return 0;
266 }
267 SParticleSystem* particlesystem = static_cast<SParticleSystem*> (node);
268
269 if (b == 0)
270 particlesystem->SetPaused(false);
271 else
272 particlesystem->SetPaused(true);
273
274 MMset(m, 0, ITOM(1));
275 return 0;
276}
277
278
288{
289#ifdef SO3_DEBUG
290 MMechostr(MSKDEBUG, "SO3ParticleSystemGetPause\n");
291#endif
292
293 int ps = MMget(m, 0);
294 if (ps == NIL)
295 {
296 MMset(m, 0, NIL);
297 return 0;
298 }
299
300 SNode* node = MMgetPointer<SNode*>(m, MTOP(ps));
301 if (node == 0)
302 {
303 MMset(m, 0, NIL);
304 return 0;
305 }
306
307 if (node->GetNodeType() != SNode::PARTICLE_SYSTEM_TYPE_ID)
308 {
309 MMset(m, 0, NIL);
310 return 0;
311 }
312 SParticleSystem* particlesystem = static_cast<SParticleSystem*> (node);
313
314 int val = 0;
315 if (particlesystem->GetPaused())
316 val = 1;
317
318 MMset(m, 0, ITOM(val));
319 return 0;
320}
321
322
333{
334#ifdef SO3_DEBUG
335 MMechostr(MSKDEBUG, "SO3ParticleSystemSetSpeedFactor\n");
336#endif
337
338 int sf = MMpull(m);
339 int ps = MMget(m, 0);
340 if ((ps == NIL) || (sf == NIL))
341 {
342 MMset(m, 0, NIL);
343 return 0;
344 }
345
346 SNode* node = MMgetPointer<SNode*>(m, MTOP(ps));
347 if (node == 0)
348 {
349 MMset(m, 0, NIL);
350 return 0;
351 }
352
353 if (node->GetNodeType() != SNode::PARTICLE_SYSTEM_TYPE_ID)
354 {
355 MMset(m, 0, NIL);
356 return 0;
357 }
358 SParticleSystem* particlesystem = static_cast<SParticleSystem*> (node);
359
360 particlesystem->SetSpeed(MTOF(sf));
361 MMset(m, 0, ITOM(1));
362 return 0;
363}
364
365
375{
376#ifdef SO3_DEBUG
377 MMechostr(MSKDEBUG, "SO3ParticleSystemGetSpeedFactor\n");
378#endif
379
380 int ps = MMget(m, 0);
381 if (ps == NIL)
382 {
383 MMset(m, 0, NIL);
384 return 0;
385 }
386
387 SNode* node = MMgetPointer<SNode*>(m, MTOP(ps));
388 if (node == 0)
389 {
390 MMset(m, 0, NIL);
391 return 0;
392 }
393
394 if (node->GetNodeType() != SNode::PARTICLE_SYSTEM_TYPE_ID)
395 {
396 MMset(m, 0, NIL);
397 return 0;
398 }
399 SParticleSystem* particlesystem = static_cast<SParticleSystem*> (node);
400
401 MMset(m, 0, FTOM(particlesystem->GetSpeed()));
402 return 0;
403}
404
405
415{
416#ifdef SO3_DEBUG
417 MMechostr(MSKDEBUG, "SO3ParticleSystemClear\n");
418#endif
419
420 int ps = MMget(m, 0);
421 if (ps == NIL)
422 {
423 MMset(m, 0, NIL);
424 return 0;
425 }
426
427 SNode* node = MMgetPointer<SNode*>(m, MTOP(ps));
428 if (node == 0)
429 {
430 MMset(m, 0, NIL);
431 return 0;
432 }
433
434 if (node->GetNodeType() != SNode::PARTICLE_SYSTEM_TYPE_ID)
435 {
436 MMset(m, 0, NIL);
437 return 0;
438 }
439 SParticleSystem* particlesystem = static_cast<SParticleSystem*> (node);
440
441 particlesystem->ClearParticles();
442 MMset(m, 0, ITOM(1));
443 return 0;
444}
445
446
447NativeDefinition natSO3Particle[] = {
448 { "SO3ParticleSystemCreateFromTemplate", 3, "fun [SO3_SCENE S S] SO3_OBJECT", SO3ParticleSystemCreateFromTemplate },
449 { "SO3ParticleSystemGetTemplate", 1, "fun [SO3_OBJECT] S", SO3ParticleSystemGetTemplate },
450 { "SO3ParticleSystemSetEnable", 2, "fun [SO3_OBJECT I] I", SO3ParticleSystemSetEnable },
451 { "SO3ParticleSystemGetEnable", 1, "fun [SO3_OBJECT] I", SO3ParticleSystemGetEnable },
452 { "SO3ParticleSystemSetPause", 2, "fun [SO3_OBJECT I] I", SO3ParticleSystemSetPause },
453 { "SO3ParticleSystemGetPause", 1, "fun [SO3_OBJECT] I", SO3ParticleSystemGetPause },
454 { "SO3ParticleSystemSetSpeedFactor", 2, "fun [SO3_OBJECT F] I", SO3ParticleSystemSetSpeedFactor },
455 { "SO3ParticleSystemGetSpeedFactor", 1, "fun [SO3_OBJECT] F", SO3ParticleSystemGetSpeedFactor },
456 { "SO3ParticleSystemClear", 1, "fun [SO3_OBJECT] I", SO3ParticleSystemClear }
457};
458
459
465int SCOLloadParticle(mmachine m, cbmachine w)
466{
467 return PKhardpak2(m, "SO3Particle.pkg", sizeof(natSO3Particle) / sizeof(natSO3Particle[0]), natSO3Particle);
468}
469
470
476{
477 return 0;
478}
479
int SCOLloadParticle(mmachine m, cbmachine w)
Load the SO3Engine Viewport function.
NativeDefinition natSO3Particle[]
int SCOLfreeParticle()
free the SO3Engine Viewport function
MMechostr(MSKDEBUG, " > Start loading Plugin SO3Engine dll\n")
SCOL_EXPORT int cbmachine w
Definition SO3SCOL.cpp:5150
int createObject(mmachine m, SNode *curNode, SScene *curScene)
int SO3ParticleSystemGetTemplate(mmachine m)
SO3ParticleSystemGetTemplate : Get the template for particle system.
int SO3ParticleSystemGetSpeedFactor(mmachine m)
SO3ParticleSystemGetSpeedFactor : Get the speed factor for particle system.
int SO3ParticleSystemSetEnable(mmachine m)
SO3ParticleSystemSetEnable : Set the Enable state for particle system.
int SO3ParticleSystemSetSpeedFactor(mmachine m)
SO3ParticleSystemSetSpeedFactor : Set the speed factor for particle system.
int SO3ParticleSystemClear(mmachine m)
SO3ParticleSystemClear : Clear a set of particle for a given particle system.
int SO3ParticleSystemGetEnable(mmachine m)
SO3ParticleSystemGetEnable : Get the enable state for particle system.
int SO3ParticleSystemGetPause(mmachine m)
SO3ParticleSystemGetPause : Get the pause state for particle system.
int SO3ParticleSystemSetPause(mmachine m)
SO3ParticleSystemSetPause : Set the pause state for particle system.
int SO3ParticleSystemCreateFromTemplate(mmachine m)
main include