[Papervision3D] 3D Sound Experiment Source

De'Angelo Richardson dialeoson at yahoo.com
Sat Jan 20 21:26:37 EST 2007


Attached is the DisplayObject3D and SceneObject3D slightly modified for the 3d sound.
   
  For sound added to an object you use myobject.addSound( "MySound.mp3", camera); where myobject is a DisplayObject3D and to change the maximun distance for the sound you would use myobject.maxSndDist = 2000 or any other value you would want.
   
  The modifications I included in DisplayObject3D are:
   
   /**
 * A sound object
 * <p/>
 * This is the sound properties
 */
 public var sound :Sound;
 
 public var maxSndDist:Number;
 
 public function updateSound ( camera:CameraObject3D )
 {
  var dist:Number;
  sound = this.sound;
  var newX:Number = int(this.x-camera.x);
  var newY:Number = int(this.y-camera.y);
  var newZ:Number = int(this.z-camera.z);
  if(!maxSndDist){ maxSndDist = 1050; }
  var Sdist:Number = Math.sqrt(newX*newX+newY*newY+newZ*newZ);
  var SndAngle:Number = int(Math.atan(newX/newZ)*180/Math.PI) - camera.rotationY;
  
  
  var Sound3D:Number = SndAngle;
  if (Sound3D>359){
   Sound3D = (Sound3D%360);
    
  } else if(Sound3D<=0){
   Sound3D = 360+(Sound3D%360);
  }
  if (newZ<0){
   Sound3D = ((Sound3D)+180)%360;
  } else if(newZ>0){
   Sound3D = Sound3D;
  }
  if(Sdist<=maxSndDist){
   dist = Math.abs((Sdist/maxSndDist)-1)*100;
  } else {
   dist = 0;
  }
  var ang:Number = Sound3D - 179;
  var Panner:Number = (ang - 180)/180;
  
  if(ang>=-180 and ang<=0){//left ear
   ang += 180;
   Panner = int(ang/90*100);
  } else if (ang<179 and ang>0){//right ear
   ang -= 179;
   Panner = int(ang/90*100);
  }
  if(Panner<-100){
   Panner = -(Panner%100 + 100);
  }else if(Panner>100){
   Panner = 99 - (Panner%100);
  }
  
  sound.setVolume(int(dist));
  sound.setPan(Panner);
   
  
 }//*/
 public function addSound ( soundObj:String, camera:CameraObject3D )
 {
  this.sound = new Sound();
  this.sound.loadSound( soundObj, true );
  updateSound( camera );
 }
   
  The modifications I included in SceneObject3D are:
   
     while( p = objects[--i] ){
    p.updateSound(camera);
    if( p.visible )
     p.project( camera );
   }
   
  -De'Angelo
   
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://osflash.org/pipermail/papervision3d_osflash.org/attachments/20070120/9f736647/attachment-0001.htm
-------------- next part --------------
A non-text attachment was scrubbed...
Name: DisplayObject3D.as
Type: application/octet-stream
Size: 18620 bytes
Desc: 3518202132-DisplayObject3D.as
Url : http://osflash.org/pipermail/papervision3d_osflash.org/attachments/20070120/9f736647/DisplayObject3D-0001.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SceneObject3D.as
Type: application/octet-stream
Size: 6427 bytes
Desc: 549847418-SceneObject3D.as
Url : http://osflash.org/pipermail/papervision3d_osflash.org/attachments/20070120/9f736647/SceneObject3D-0001.obj


More information about the Papervision3D mailing list