Flint Particle System Forum - SnowBall Effect implementation? Thu, 23 Jun 2011 13:39:31 +0100 http://flintparticles.org/forum/ Lussumo Vanilla 1.1.10 & Feed Publisher SnowBall Effect implementation? http://flintparticles.org/forum/comments.php?DiscussionID=127&Focus=501#Comment_501 http://flintparticles.org/forum/comments.php?DiscussionID=127&Focus=501#Comment_501 Fri, 14 Nov 2008 14:56:28 +0000 psilos
I am trying to implement a 3D SnowBall effect,

I would like to ask for some more advice,
My restrictions is that there is not any BoundingSphere Class, so I am using BoundingBox for now.

My idea was to use Brownian Motion for the snow inside the Ball/Box which works fine, and to apply some gravity in the floor of the cube.

So, I have added 4 Actions ( TurnTowardsPoint ) in the 4 corners of the cube,

The result is not the best, is it any way, to stop them moving only if they hit the floor of the cube?

Adding another BoundingBox with Collide = 0, doesn't seem to work either.

Thanks in advance for any help.

Here is my code so far:

public class SnowMotion extends Emitter3D
{
public function SnowMotion()
{
counter = new Blast( 100 );

addInitializer( new PV3DObjectClass( Particle, null, 4 ) );
addInitializer( new ColorInit( 0xFFFFFFFF, 0xFFFFFFFF ) );
addInitializer( new MassInit( 1 ) );
addInitializer( new CollisionRadiusInit( 2 ) );
addInitializer( new ApplyMaterial( ParticleMaterial, 0xFFFFFF, 1, ParticleMaterial.SHAPE_CIRCLE ) );

addInitializer( new Position( new BoxZone( 100, 100, 100, new Vector3D( 0, 0, 70 ), new Vector3D( 0, 1, 0 ), new Vector3D( 0, 0, 1 ) ) ) );
addInitializer( new Velocity( new SphereZone( new Vector3D( 0, 0, 70 ), 120, 100 ) ) );

//addAction( new Accelerate( new Vector3D( 0, 0, -5) ) );
addAction( new Move() );
addAction( new Collide( 1 ) );
addAction( new BoundingBox( -81, 81, -81, 81, -11, 150, 0 ) );

addAction( new TurnTowardsPoint( new Vector3D( 100, -100, 0), 10 ) );
addAction( new TurnTowardsPoint( new Vector3D( 100, 100, 0), 10 ) );
addAction( new TurnTowardsPoint( new Vector3D( -100, 100, 0), 10 ) );
addAction( new TurnTowardsPoint( new Vector3D( -100, -100, 0), 10 ) );
}
}
]]>
SnowBall Effect implementation? http://flintparticles.org/forum/comments.php?DiscussionID=127&Focus=506#Comment_506 http://flintparticles.org/forum/comments.php?DiscussionID=127&Focus=506#Comment_506 Mon, 17 Nov 2008 12:26:46 +0000 Richard SnowBall Effect implementation? http://flintparticles.org/forum/comments.php?DiscussionID=127&Focus=513#Comment_513 http://flintparticles.org/forum/comments.php?DiscussionID=127&Focus=513#Comment_513 Mon, 17 Nov 2008 13:58:19 +0000 psilos
but how can I add these random Actions and switch them on and off?

I have tried to use your example like this, but doesn't work:


public class ShakeGlobe extends ActionBase
{
private var _isDown:Boolean;
private var shake:Accelerate;

public function ShakeGlobe( stage:DisplayObject )
{
_isDown = false;
stage.addEventListener( KeyboardEvent.KEY_DOWN, keyDownListener, false, 0, true );
stage.addEventListener( KeyboardEvent.KEY_UP, keyUpListener, false, 0, true );
}

private function keyDownListener( ev:KeyboardEvent ):void
{
if( ev.keyCode == Keyboard.SHIFT )
{
_isDown = true;
}
}
private function keyUpListener( ev:KeyboardEvent ):void
{
if( ev.keyCode == Keyboard.SHIFT )
{
_isDown = false;
}
}

override public function update( emitter:Emitter, particle:Particle, time:Number ):void
{
if( particle.mass == 1 )
{
if( _isDown )
{
shake = new Accelerate ( new Vector3D ( 0, 0, 65) );
emitter.addAction( shake );
}
else
{
if(emitter.hasAction( shake ))
{
emitter.removeAction( shake );
}
}
}
}


It would be great if you can provide an example, thanks a lot ]]>
SnowBall Effect implementation? http://flintparticles.org/forum/comments.php?DiscussionID=127&Focus=515#Comment_515 http://flintparticles.org/forum/comments.php?DiscussionID=127&Focus=515#Comment_515 Tue, 18 Nov 2008 08:49:29 +0000 Richard
package
{
public class ShakeGlobe extends ActionBase
{
private var shake:Accelerate;

public function ShakeGlobe( stage:DisplayObject )
{
shake = new Accelerate ( new Vector3D ( 0, 0, 65) );
stage.addEventListener( KeyboardEvent.KEY_DOWN, keyDownListener, false, 0, true );
stage.addEventListener( KeyboardEvent.KEY_UP, keyUpListener, false, 0, true );
}

private function keyDownListener( ev:KeyboardEvent ):void
{
if( ev.keyCode == Keyboard.SHIFT )
{
emitter.addAction( shake );
}
}
private function keyUpListener( ev:KeyboardEvent ):void
{
if( ev.keyCode == Keyboard.SHIFT )
{
emitter.removeAction( shake );
}
}
}
}
]]>
SnowBall Effect implementation? http://flintparticles.org/forum/comments.php?DiscussionID=127&Focus=518#Comment_518 http://flintparticles.org/forum/comments.php?DiscussionID=127&Focus=518#Comment_518 Tue, 18 Nov 2008 11:42:11 +0000 psilos
but how do I get access to the referenced emitter now?
My guess is that I would need to update the emitter as well, is that right?

Thanks ]]>
SnowBall Effect implementation? http://flintparticles.org/forum/comments.php?DiscussionID=127&Focus=520#Comment_520 http://flintparticles.org/forum/comments.php?DiscussionID=127&Focus=520#Comment_520 Tue, 18 Nov 2008 12:40:22 +0000 Richard addedToEmitter method to store a reference to the emitter -

package
{
public class ShakeGlobe extends ActionBase
{
private var shake:Accelerate;
private var emitter:Emitter;

public function ShakeGlobe( stage:DisplayObject )
{
shake = new Accelerate ( new Vector3D ( 0, 0, 65) );
stage.addEventListener( KeyboardEvent.KEY_DOWN, keyDownListener, false, 0, true );
stage.addEventListener( KeyboardEvent.KEY_UP, keyUpListener, false, 0, true );
}

private function keyDownListener( ev:KeyboardEvent ):void
{
if( emitter && ev.keyCode == Keyboard.SHIFT )
{
emitter.addAction( shake );
}
}
private function keyUpListener( ev:KeyboardEvent ):void
{
if( emitter && ev.keyCode == Keyboard.SHIFT )
{
emitter.removeAction( shake );
}
}

private function addedToEmitter( emitter:Emitter ):void
{
this.emitter = emitter;
}
private function removedFromEmitter( emitter:Emitter ):void
{
this.emitter = null;
}
}
}
]]>
SnowBall Effect implementation? http://flintparticles.org/forum/comments.php?DiscussionID=127&Focus=527#Comment_527 http://flintparticles.org/forum/comments.php?DiscussionID=127&Focus=527#Comment_527 Tue, 18 Nov 2008 17:26:52 +0000 psilos this is working perfectly now, but unfortunately could not find an Action to apply for realistic shaking the snow.

The initializer seems quite realistic now like this:


public class SnowMotion extends Emitter3D
{
protected static const BOX_SIZE:Number = 160;
protected static const OFFSET:Vector3D = new Vector3D(0, 0, 70);

public function SnowMotion( stage:DisplayObject)
{
counter = new Blast( 150 );

addInitializer( new PV3DObjectClass( Particle, null, 4 ) );
addInitializer( new ColorInit( 0xFFFFFFFF, 0xFFFFFFFF ) );
addInitializer( new MassInit( 1 ) );
addInitializer( new CollisionRadiusInit( 2 ) );
addInitializer( new ApplyMaterial( ParticleMaterial, 0xFFFFFF, 1, ParticleMaterial.SHAPE_CIRCLE ) );
addInitializer( new Position( new BoxZone( BOX_SIZE, BOX_SIZE, BOX_SIZE, OFFSET, new Vector3D( 0, 1, 0 ), new Vector3D( 0, 0, 1 ) ) ) );
addInitializer( new Velocity( new SphereZone( new Vector3D( 0, 0, 70 ), 130, 120 ) ) );

addAction( new Accelerate( new Vector3D( 0, 0, -5) ) );
addAction( new Move() );
addAction( new Collide( 0.5 ) );
addAction( new BoundingBox( -81, 81, -81, 81, 20, 150, 1 ) );
addAction( new SpeedLimit( 60 ) );
addAction( new LinearDrag( 0.15 ) );
addAction( new ShakeGlobe( stage, this ) );
}
}



So, I was thinking how can I accelerate my particles again to fill this Position and Velocity as Initial, I have already tried different approaches like accelerate, targetVelocity, Jet, etc but no luck.

Any ideas?

Thanks ]]>