#### Archived

This topic is now archived and is closed to further replies.

# Need Math! Got Point A and B Need....

This topic is 6675 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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

##### Share on other sites
Have you looked into using DirectSound? I believe it handles 3D sounds pretty good. Even implementing things like the doplar effect for you.

##### Share on other sites
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.

GA

Edited by - ga on June 13, 2000 6:09:13 PM

##### Share on other sites
I am using DX7a. I didn''t see anything about this in Direct Sound. But I''m a newbi.

##### Share on other sites
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.

##### Share on other sites
Check out the sample programs under Direct Sound, there should be one called Play 3D Sound.

##### Share on other sites
There is a 3D sample in the DX7 SDK. But its in VC++ and I''m working in VB6 Don''t know much about VC.

1. 1
2. 2
Rutin
19
3. 3
4. 4
frob
13
5. 5

• 9
• 18
• 11
• 9
• 17
• ### Forum Statistics

• Total Topics
632605
• Total Posts
3007371

×