HomeHome  CalendarCalendar  FAQFAQ  SearchSearch  MemberlistMemberlist  UsergroupsUsergroups  RegisterRegister  Log inLog in  

Share | 
 

 Action Particle getAge() always zero

View previous topic View next topic Go down 
AuthorMessage
Escen



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

PostSubject: 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
}
Back to top Go down
View user profile
Darktib
Committer


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

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

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

_________________
Back to top Go down
View user profile
Juff
Developer


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

PostSubject: 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 ?
Back to top Go down
View user profile http://spark.developpez.com
Escen



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

PostSubject: 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?
Back to top Go down
View user profile
Darktib
Committer


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

PostSubject: 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...

_________________
Back to top Go down
View user profile
Juff
Developer


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

PostSubject: 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...
Back to top Go down
View user profile http://spark.developpez.com
Escen



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

PostSubject: 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
Back to top Go down
View user profile
Sponsored content




PostSubject: Re: Action Particle getAge() always zero   Today at 3:41 am

Back to top Go down
 
Action Particle getAge() always zero
View previous topic View next topic Back to top 
Page 1 of 1
 Similar topics
-
» Shia Labeouf To Star In Naruto Live Action Film!
» BlueCoreStudios Has Released A Sonic The Hedgehog Live Action Film On Youtube!
» Focus on New Window
» Webdriver C# Mouseover
» If object present do sumthing else proceed to next selenium step

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