Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (Ayumi, 7th_zorro, 1 invisible), 1,060 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rating: 5
Play_3dsound #58197
10/28/05 20:51
10/28/05 20:51
Joined: Apr 2005
Posts: 64
Italy - Rome
_
_Tommo_ Offline OP
Junior Member
_Tommo_  Offline OP
Junior Member
_

Joined: Apr 2005
Posts: 64
Italy - Rome
Hi,
for my first contribute... here it is this simple but useful (at least for me ) function that allows to play a 3d sound at an arbitrary position. I made this becaus ent_playsound is buggy and needs an entity as emitter. My function needs the sound name string, the position vector of the sound source and the radius (from 0 to unlimited) of the sound. The obstacle detection is very simple for speed reason, and it's better to use short sounds because they aren't dynamically updated.

Code:
 
function play_3dsound(str_snd,&vec_pos,radius)
{
var snd_handle;
var volume;
var balance;
var balance_angle[3];

//--volume calculations

volume = radius / 10;
result = vec_dist(camera.x,vec_pos);
volume = volume - int(result * volume / radius); // result:radius = x:volume -- es with result = 10: 10:700=x:70
volume = int(clamp(volume,1,100));
if(trace(vec_pos,camera.x) != 0) {volume /= 2;} //cut this if you dont want object detection

//----balance calculations
//balance for pan
vec_sub(vec_pos,camera.x);
balance_angle.pan = atan(vec_pos[1]/vec_pos[0]); //find the angle from camera.x to the emitter
balance_angle.pan = ang(camera.pan) - balance_angle.pan; //find the difference between cam.pan and bal.pan
temp = abs(balance_angle.pan);
temp = (temp - (temp - 90)*2*(temp > 90)) / 90 * 50; //temp is locked to 0-90, 0 = 0 and 90 = 100, if temp is bigger, its inverted.
balance = temp * sign(balance_angle.pan); //find if on the right or left headphone.

//balance for roll
balance_angle.roll = atan(vec_pos[2]/vec_pos[1]); //find the angle from camera.x to the emitter
balance_angle.roll = ang(camera.roll) - balance_angle.roll; //find the difference between cam.pan and bal.pan
temp = abs(balance_angle.roll);
temp = (temp - (temp - 90)*2*(temp > 90)) / 90 * 50; //temp is locked to 0-90, 0 = 0 and 90 = 100, if temp is bigger, its inverted.
balance += temp * sign(balance_angle.roll); //find if on the right or left headphone.

//--------

return(snd_play(str_snd,volume,balance));
}



I hope that you'll find it useful... and sorry for the bad english

Re: Play_3dsound [Re: _Tommo_] #58198
10/28/05 22:31
10/28/05 22:31
Joined: Aug 2005
Posts: 1,185
Ukraine
Lion_Ts Offline
Serious User
Lion_Ts  Offline
Serious User

Joined: Aug 2005
Posts: 1,185
Ukraine
O! I have to try...
thank you

Re: Play_3dsound [Re: Lion_Ts] #58199
10/31/05 22:23
10/31/05 22:23
Joined: Apr 2005
Posts: 3,815
Finland
Inestical Offline
Rabbit Developer
Inestical  Offline
Rabbit Developer

Joined: Apr 2005
Posts: 3,815
Finland
on ride tommorow! Going to test that one


"Yesterday was once today's tomorrow."
Re: Play_3dsound [Re: _Tommo_] #58200
11/01/05 21:51
11/01/05 21:51
Joined: Apr 2005
Posts: 64
Italy - Rome
_
_Tommo_ Offline OP
Junior Member
_Tommo_  Offline OP
Junior Member
_

Joined: Apr 2005
Posts: 64
Italy - Rome
Hey i found some little errors... replace the volume part of the function with this:
Code:
 
volume = radius / 10;
volume -= vec_dist(camera.x,vec_pos) * volume / max(0.1,radius); //result:radius = x:volume -- ex with result = 10: 10:700=x:70

trace_mode = ignore_models + ignore_passents + ignore_passable;
if(trace(vec_pos,camera.x) != 0) {volume /= 2;}



And tell me if it works for you

Re: Play_3dsound [Re: _Tommo_] #58201
11/03/05 13:04
11/03/05 13:04
Joined: Aug 2003
Posts: 183
BionicHero Offline
Member
BionicHero  Offline
Member

Joined: Aug 2003
Posts: 183
Hi! I didn't test the script and I don't want to ruin for anyone who wants to use it but this is actually no 3d sound. It's just a stereo sound which means, you would never be able to hear it BEHIND you, right?

Re: Play_3dsound [Re: BionicHero] #58202
11/03/05 21:07
11/03/05 21:07
Joined: Apr 2005
Posts: 64
Italy - Rome
_
_Tommo_ Offline OP
Junior Member
_Tommo_  Offline OP
Junior Member
_

Joined: Apr 2005
Posts: 64
Italy - Rome
Yeah, actually it works for stereo speakers, but because i don't have Surrond to test (I tested it with a headset) i can't say if it will work on it... if you hear the sound from behind, it will just play with a balance of 0. I made it just to use it insistead of ent_playsound, and sorry if i gave to it a wrong name...

Re: Play_3dsound [Re: _Tommo_] #58203
11/20/05 15:01
11/20/05 15:01
Joined: Sep 2003
Posts: 648
Switzerland
snake67 Offline
User
snake67  Offline
User

Joined: Sep 2003
Posts: 648
Switzerland
Thanks a lot for this contribution! Its exactly what i needed. To play a hit sound on level geometry i used a sprite for the hit flash so i could do it with ent_playsound. With your code i can do the effect with a particle wich is faster.


Moderated by  adoado, checkbutton, mk_1, Perro 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1