| Action Particle getAge() always zero | |
|
|
Author | Message |
---|
Escen
Messages : 9 Date d'inscription : 2009-12-01
| Subject: Action Particle getAge() always zero Sat Mar 01, 2014 4:59 pm | |
| Hello, Created my own SPK::Action class using as a setBirthAction, but particle.getAge() returns always zero. Did I miss something? Using svn SPARK2. - Code:
-
void SPK::PartAction::apply(SPK::Particle & particle) const { float age=particle.getAge(); printf("age %f\n",particle.getAge()); // do Stuff }
| |
|
| |
Darktib Committer
Messages : 389 Date d'inscription : 2009-07-20 Localisation : A coté de Paris
| Subject: Re: Action Particle getAge() always zero Sun Mar 02, 2014 8:09 am | |
| Thanks for the report, I'll check this when possible. | |
|
| |
Juff Developer
Messages : 539 Date d'inscription : 2009-07-14 Age : 41
| Subject: Re: Action Particle getAge() always zero Sun Mar 02, 2014 6:10 pm | |
| If your action is set to be called at the birth of particles, isnt it normal that the age of the particle at that time is zero ? | |
|
| |
Escen
Messages : 9 Date d'inscription : 2009-12-01
| Subject: Re: Action Particle getAge() always zero Mon Mar 03, 2014 4:28 am | |
| Oke that make sense, expected to apply an action starting from the birth of the particle and use it over time. In the action description it says:
"Some modifiers can also trigger actions. In a more general way, any object can potentially triggers actions."
I have tried to figure it out myself, but how do trigger an action starting at the beginning of an emitter for a period of time. Or in the general way how do I trigger an action besides 'setBirthAction'. Do you have a quick example? | |
|
| |
Darktib Committer
Messages : 389 Date d'inscription : 2009-07-20 Localisation : A coté de Paris
| Subject: Re: Action Particle getAge() always zero Mon Mar 03, 2014 6:32 am | |
| Uh, I read your question way too fast^^.
Actions are a mean to react to events, but are immediate. If you want something to act on particles over time, you should create a Modifier. Actions are more useful for example to create an emitter when a particle is born and attach to it, or to create another system at a particle location on its death, or whatever... | |
|
| |
Juff Developer
Messages : 539 Date d'inscription : 2009-07-14 Age : 41
| Subject: Re: Action Particle getAge() always zero Mon Mar 03, 2014 6:56 am | |
| For what you want : - Code:
-
class MyModifier :: public SPK::Modifier { // ...
virtual void modify(SPK::Group& group,SPK::DataSet* dataSet,float deltaTime) const { for (GroupIterator particleIt(group); !particleIt.end(); ++particleIt) { if (particleIt->getAge() <= maxAge) { // My processing for young particles } } } };
To set up an action at a specific time in a given modifier. For instance extend the obstacle class to trigger an action when a particle collides (which could be added to SPARK but wasnt yet) : - Code:
-
class SPK_PREFIX Obstacle : public ZonedModifier { public :
//...
inline const Ref<Action>& getCollisionAction() const { return collisionAction; }
inline void setCollisionAction(const Ref<Action>& action) { collisionAction = action; }
private :
// ...
void Obstacle::modify(Group& group,DataSet* dataSet,float deltaTime) const { for (GroupIterator particleIt(group); !particleIt.end(); ++particleIt) { if (checkZone(*particleIt,&normal)) { // All process to handle collision reaction
if (collisionAction && collisionAction->isActive()) // Should add a velocity check to avoid action to be triggered at each frame collisionAction->apply(*particleIt); } } }
Ref<Action> collisionAction; };
Thanks to that any action can be set when a particle collides. This would allow to spawn another particle system or play a sound or whatever... | |
|
| |
Escen
Messages : 9 Date d'inscription : 2009-12-01
| Subject: Re: Action Particle getAge() always zero Mon Mar 03, 2014 8:09 am | |
| Thanks guys, I got it working. It's really cool, I knew it was possible with spark, didn't know how. Spark has some really nice features, mind is the limit.
Both thanks for your support it is greatly appreciated | |
|
| |
Sponsored content
| Subject: Re: Action Particle getAge() always zero | |
| |
|
| |
| Action Particle getAge() always zero | |
|