InjectionInitializer, RevolvingModifier

  ... the case you feel the need for a new feature or want to submit one.

InjectionInitializer, RevolvingModifier

Postby ozero » Wed Jan 05, 2011 4:52 pm

For my LiveWallpaper(clone of this AMV : http://goo.gl/vKxsD ),
I added some simple initializer and modifier.

market(AndroLib): http://goo.gl/dxDNC
repository: http://goo.gl/TT9DA

InjectionInitializer:
cast particle into any way(pHeading+pRange) at the certain speed(pVelocity).

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class InjectionInitializer extends BaseDoubleValueInitializer {
  2.         private float pVelocityX, pVelocityY, pHeading, pVelocity, pRange;
  3.  
  4.         public InjectionInitializer(float pHeading,float pVelocity, float pRange) {
  5.                 super(0,0,0,0);
  6.                 this.pHeading = pHeading;
  7.                 this.pVelocity = pVelocity;
  8.                 this.pRange = pRange;
  9.         }
  10.  
  11.  
  12.         @Override
  13.         public void onInitializeParticle(final Particle pParticle,
  14.                         final float pVelocityX, final float pVelocityY) {
  15.                 float way = (float) (this.pRange*Math.random());
  16.                 this.pVelocityX = (float) (Math.sin(
  17.                                 this.pHeading + way) * this.pVelocity);
  18.                 this.pVelocityY = (float) (Math.cos(
  19.                                 this.pHeading + way) * this.pVelocity);
  20.                
  21.                 pParticle.setVelocity(
  22.                                 this.pVelocityX,
  23.                                 this.pVelocityY
  24.                 );
  25.         }
  26. }
  27.  
Parsed in 0.012 seconds, using GeSHi 1.0.8.4



RevolvingModifier:
It keeps all particles revolving in same speed(pCycle).

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class RevolvingModifier implements IParticleModifier {
  2.         private float pRotate;
  3.         private float pCycle;
  4.  
  5.         public RevolvingModifier(float pCycle) {
  6.                 this.pCycle = pCycle;
  7.         }
  8.  
  9.         @Override
  10.         public void onInitializeParticle(final Particle pParticle) {
  11.         }
  12.  
  13.         @Override
  14.         public void onUpdateParticle(final Particle pParticle) {
  15.                 pRotate = 360 * ((pParticle.getLifeTime() % this.pCycle)/this.pCycle);
  16.                 if(pRotate > 360){pRotate = pRotate - 360;}
  17.                 pParticle.setRotation(pRotate);
  18.         }
  19. }
  20.  
Parsed in 0.011 seconds, using GeSHi 1.0.8.4
ozero
 
Posts: 1
Joined: Mon Sep 20, 2010 4:49 pm

Return to Features

Who is online

Users browsing this forum: No registered users and 7 guests