Saturday, December 12, 2009

Boundary Collision Sparks

View SWF
View source
Stardust project homepage

That's it. I've always wanted to create an action trigger that is triggered by "collision" with a deflector, or "deflection" with a deflector not acting as an obstacle. Now I've finally got it done :)

The magic behind the scene is quite simple: the Deflect class is modified so as to map a deflector to a boolean value, a flag for determining if a "collision" or "deflection" has occurred, through a dictionary object; the DeflectorTrigger class then simply check the flag to determine if the trigger is triggered.

However, extra caution is now required when creating custom deflectors. If you decide that a deflector does not "deflect" a particle, the overrided calculateMotionData4D method must return a null value instead of a "new MotionData(particle.x, particle.y, particle.vx, particle.vy)" copy of the particle's original position and velocity, which tells the DeflectorTrigger class that it should not be triggered.

My next target should be creating a trigger that can detect interparticle collision, which would not be an easy task. Well, it's easy, but what I mean is that it's not going to be easy to implement it with action trigger structures; at least now I don't have the slightest idea about how to do it. I'll try and figure out a way to do it cleanly and efficiently.

No comments: