Need Math! Got Point A and B Need....
I have a game with sound and I need to figure out right and left volume for the sound source to the players camera.
Ok.. In 3D space I just need 2D cordinates (x,y) of point 1 and 2. I can figure out the distance of the two points.
sqr((x1 - x2) ^ 2 + (y1 - y2) ^ 2) = distance between X and Y
What I need to do is with point 1 and 2 I have to figure out witch side is closer. What would be the best way??? Get a right and left point next to the players location, then calc. the distance from the R and L points to the sound location and figure out the difference for the sound balance?
- Joe
Have you looked into using DirectSound? I believe it handles 3D sounds pretty good. Even implementing things like the doplar effect for you.
In 3D space the distance is sqrt((x2-x1)^2 + (y2-y1)^2 + (z2-z1)^2)...
To get the right volume, calculate the unit vector from the player to the sound source, then calculate the scalar product x of the unit right vector of the player with this player-sound source vector. Then the right volume should be (1 + x)/2 (if 1 is the whole volume), the left volume is 1 - right volume.
Visit our homepage: www.rarebyte.de.st
GA
Edited by - ga on June 13, 2000 6:09:13 PM
To get the right volume, calculate the unit vector from the player to the sound source, then calculate the scalar product x of the unit right vector of the player with this player-sound source vector. Then the right volume should be (1 + x)/2 (if 1 is the whole volume), the left volume is 1 - right volume.
Visit our homepage: www.rarebyte.de.st
GA
Edited by - ga on June 13, 2000 6:09:13 PM
Visit our homepage: www.rarebyte.de.stGA
I am using DX7a. I didn''t see anything about this in Direct Sound. But I''m a newbi.
Well, you should avoid the sqr function at all times. If you ONLY need to find which one is closer, you simply do this
if (x1*x1+y1*y1) < (x2*x2+y2*y2) then
p1 is closer
else
p2 is closer
end if
See how easy it was to just avoid the sqr function? Well, I got this from "The good-looking textured light-sourced bouncy fun smart and stretchy page."
------------------------
Captured Reality.
if (x1*x1+y1*y1) < (x2*x2+y2*y2) then
p1 is closer
else
p2 is closer
end if
See how easy it was to just avoid the sqr function? Well, I got this from "The good-looking textured light-sourced bouncy fun smart and stretchy page."
------------------------
Captured Reality.
Check out the sample programs under Direct Sound, there should be one called Play 3D Sound.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement