sound3.js 443 B

123456789101112131415161718
  1. this.tick = function( time ) {
  2. this.updateVolume( [ 0, 0, 0 ] );
  3. }
  4. this.updateVolume = function( camerapos ) {
  5. var x = Vec3.distance( camerapos, this.parent.worldPosition );
  6. x = Math.max( 0, x );
  7. var v = this.volume;
  8. var vol = ( ( -x + v ) / ( v || 1 ) ) * ( ( -x + v ) / ( v || 1 ) );
  9. if( x > v ) {
  10. vol = 0;
  11. }
  12. this.volume = Math.max( Math.min( vol, 1 ), 0 ) * 100;
  13. }