Advertisement
Guest User

Untitled

a guest
Jan 15th, 2012
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. float px;
  2. float py;
  3. float r;
  4. float a;
  5.  
  6. float sbaIndex;
  7. float aaIndex;
  8. float diff;
  9. float sval;
  10.  
  11. float springForce;
  12.  
  13.  
  14. //params
  15. float dampingFactor = 1-Parameters[6]*Parameters[6];
  16. float sampleSize = sqrt(Parameters[8]);
  17. float attackThreshold = Parameters[7]*Parameters[7]*Parameters[7];
  18.  
  19.  
  20. currentModel.colorThreshold = Parameters[12]*3;
  21.  
  22. for(float x=0; x<64; x++){ //For every particle
  23.   for(float y=0; y<64; y++){
  24.     if(Particles[x, y, 3] > 0 && Particles[x, y, 0] + Particles[x, y, 1] + Particles[x, y, 2] >= currentModel.colorThreshold){
  25.       //Read Particle props
  26.       px = Particles[x,y,4];
  27.       py = Particles[x,y,5];
  28.       r = Particles[x,y,10];
  29.       a = Particles[x,y,13];
  30.  
  31.       //get index of for SprecBandAray depending on radius
  32.       sbaIndex = Parameters[2] + r*(Parameters[3] - Parameters[2])*2;
  33.       sbaIndex = floor(sbaIndex*SpecBandArray.SizeDim1);
  34.       sbaIndex = clamp(sbaIndex, 0, SpecBandArray.SizeDim1-1);
  35.  
  36.       //get index of wave array depending on angle and sample size param
  37.       aaIndex = a*AudioArray.SizeDim1*sampleSize;
  38.       aaIndex = clamp(aaIndex ,0,AudioArray.SizeDim1-1);
  39.  
  40.       //Derive spectral movement (current - previous)
  41.       diff = clamp(SpecBandArray[sbaIndex],0,1) - clamp(SpecBandArray_Prev[sbaIndex],0,1);
  42.  
  43.       //radial force
  44.       sval = AudioArray[aaIndex]*Parameters[1];
  45.  
  46.       //apply to velocity
  47.       if(diff > attackThreshold){
  48.         Particles[x,y,9] += diff*Parameters[0]*3;
  49.       }
  50.       Particles[x,y,7] += sval*px;
  51.       Particles[x,y,8] += sval*py;
  52.  
  53.       //spring force
  54.       springForce = (Parameters[4] + r*(Parameters[5] - Parameters[4])*2)*4;
  55.       Particles[x,y,7] -= (Particles[x,y,4] - Particles[x,y,11])*springForce;
  56.       Particles[x,y,8] -= (Particles[x,y,5] - Particles[x,y,12])*springForce;
  57.       Particles[x,y,9] -= Particles[x,y,6]*springForce;
  58.  
  59.       //Damping
  60.       Particles[x,y,7] *= dampingFactor;
  61.       Particles[x,y,8] *= dampingFactor;
  62.       Particles[x,y,9] *= dampingFactor;
  63.  
  64.       //Update Position (integrate velocity)
  65.       Particles[x,y,4] += Particles[x,y,7];
  66.       Particles[x,y,5] += Particles[x,y,8];
  67.       Particles[x,y,6] += Particles[x,y,9];
  68.  
  69.     }
  70.   }
  71. }
  72.  
  73. //prepare next derivation cycle
  74. for(float i=0; i<SpecBandArray.SizeDim1; i++){
  75.   SpecBandArray_Prev[i] = SpecBandArray[i];
  76. }
  77.  
  78.  
  79. //zoom
  80. Cam.Position.Z = (1-Parameters[10])*2;
  81. Cam.Position.Z = Cam.Position.Z*Cam.Position.Z;
  82.  
  83. //Illumination
  84. currentModel.illuminationFactor = 100*Parameters[13]*Parameters[13];
  85.  
  86.  
  87. //Rotate
  88. ParticlesTransform.Rotate.Z += (Parameters[11]-0.5)*(Parameters[11]-0.5)*0.1;
  89.  
  90. //set pixel size
  91. currentModel.pixelSize = App.ViewportHeight/16*Parameters[15];
  92. if(currentModel.pixelSize < 1) currentModel.pixelSize = 1;
  93.  
  94. //view angle
  95. currentModel.Rotation.X = 1-Parameters[9];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement