HomeHome  SearchSearch  RegisterRegister  Log inLog in  

Share
 

 Action Particle getAge() always zero

Go down 
AuthorMessage
Escen



Messages : 9
Date d'inscription : 2009-12-01

Action Particle getAge() always zero Empty
PostSubject: Action Particle getAge() always zero   Action Particle getAge() always zero Icon_minitimeSat 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
}
Back to top Go down
Darktib
Committer
Darktib

Messages : 389
Date d'inscription : 2009-07-20
Localisation : A coté de Paris

Action Particle getAge() always zero Empty
PostSubject: Re: Action Particle getAge() always zero   Action Particle getAge() always zero Icon_minitimeSun Mar 02, 2014 8:09 am

Thanks for the report, I'll check this when possible.

_________________
Action Particle getAge() always zero A824d8828e17173a5d5b383b8744118b28a79bc96c7deba8910bed109308d4304g
Back to top Go down
Juff
Developer


Messages : 539
Date d'inscription : 2009-07-14
Age : 37

Action Particle getAge() always zero Empty
PostSubject: Re: Action Particle getAge() always zero   Action Particle getAge() always zero Icon_minitimeSun 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 ?
Back to top Go down
http://spark.developpez.com
Escen



Messages : 9
Date d'inscription : 2009-12-01

Action Particle getAge() always zero Empty
PostSubject: Re: Action Particle getAge() always zero   Action Particle getAge() always zero Icon_minitimeMon 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?
Back to top Go down
Darktib
Committer
Darktib

Messages : 389
Date d'inscription : 2009-07-20
Localisation : A coté de Paris

Action Particle getAge() always zero Empty
PostSubject: Re: Action Particle getAge() always zero   Action Particle getAge() always zero Icon_minitimeMon 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...

_________________
Action Particle getAge() always zero A824d8828e17173a5d5b383b8744118b28a79bc96c7deba8910bed109308d4304g
Back to top Go down
Juff
Developer


Messages : 539
Date d'inscription : 2009-07-14
Age : 37

Action Particle getAge() always zero Empty
PostSubject: Re: Action Particle getAge() always zero   Action Particle getAge() always zero Icon_minitimeMon 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...
Back to top Go down
http://spark.developpez.com
Escen



Messages : 9
Date d'inscription : 2009-12-01

Action Particle getAge() always zero Empty
PostSubject: Re: Action Particle getAge() always zero   Action Particle getAge() always zero Icon_minitimeMon 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
Back to top Go down
Sponsored content




Action Particle getAge() always zero Empty
PostSubject: Re: Action Particle getAge() always zero   Action Particle getAge() always zero Icon_minitime

Back to top Go down
 
Action Particle getAge() always zero
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
 :: English Forum :: Questions (en)-
Jump to: