Sound3D affected by camera direction

Software: Away3D 4.x

Beek, Member
Posted: 10 March 2015 01:06 AM   Total Posts: 67

Hi,

Does Sound3D react to the direction of the camera, as well as the camera position?

i.e. I want to control sounds based on where you are looking, as the camera position is fixed.

EDIT: I’ve had a look at the code, and it seems only camera position affects the volume.

A solution I thought of was to create a new listener objectContainer3d, and place it in front of the camera, as a child of the camera so it’s fixed and use that as the listener in Sound3D.

Does anyone know if this will work, and also how to get the listener object to stay in front of the camera ( making it a child of the camera doesn’t seem to make any difference to it’s position when the camera rotates).

 

   

JaykopX, Newbie
Posted: 10 March 2015 01:15 PM   Total Posts: 13   [ # 1 ]

You could write an Update funciton to replace the listener infront of the camera. The listener position would be something like

listenerPostion =distance*camera.forwardVector

If you dont want to call an update function then you can also inheritate from the camera and override all setters of the camera that would affect the listener position, and in thoose custom setters you have to update the listener position.

For example the x-coordinate

public override function set x(value:Number) : void {
listener
.x*distance;

Last method would be the elegant way, in my opinion, but it is quite some work.

   

Beek, Member
Posted: 10 March 2015 08:16 PM   Total Posts: 67   [ # 2 ]

Thanks that’s great.

How do I multiply a vector by a number? i.e.

listener.position camera.forwardVector 500

Or should something like this work

var distance:Vector3D = new Vector3D(200,0,0);
  
listener.position camera.forwardVector.add(distance); 

That isn’t working actually.

 

 

   

JaykopX, Newbie
Posted: 11 March 2015 10:06 AM   Total Posts: 13   [ # 3 ]

The mulitplication of a Scalar with a Vector3D is not defined afaik. You have to do it manually for each component

result.distance*forwardVector.x;
result.distance*forwardVector.y;
result.distance*forwardVector.z

or use the .scaleBy() function wich does exactly the same

result.scaleBy(distance); 

, but of course you have to be carful not manipulating a reference with .scaleBy().
e.g. this would manipulate the reference:

result:Vector3D forwardVector;
result.scaleBy(dist); 

and should be a copy instead:

result:Vector3D = new Vector3D(forwardVector.xforwardVecor.yforwardVector.z);
result.scaleBy(dist); 

Remark: I’m not that deep into as3 and i don’t know if it is possible to define operators like the one needed here for a scalar*vector operation(if it is possible, then of course that would be the elegant way of doing it). Additionally I don’t really know why they called it scaleBy() and not multiply(), since the last name seems to be more convenient.

   

Beek, Member
Posted: 11 March 2015 11:07 PM   Total Posts: 67   [ # 4 ]

Great that’s helped and the listener does appear to be flying around the scene relevant to the camera. It’s not affecting the volume of the sounds tho, so maybe this solution isn’t going to work.

   

Beek, Member
Posted: 12 March 2015 02:52 AM   Total Posts: 67   [ # 5 ]

OK the listener appears to be moving, but the Sound3D object can’t see it,

Object3DEvent.SCENETRANSFORM_CHANGED 

is never getting fired.

Should setting the position like this

var pos:Vector3D = new  Vector3D(view.camera.forwardVector.xview.camera.forwardVector.yview.camera.forwardVector.z);
   
pos.scaleBy(1000); 
   
listener.position pos

Cause this to fire?

   

Beek, Member
Posted: 16 March 2015 03:29 AM   Total Posts: 67   [ # 6 ]

Got this working now the sound position is defiantly not (0,0,0) !

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X