![]() |
| ||
| 3D Sound, calculating pan Anyone out there good with 3D math? Unfortunately, I am definitely not. I need a formula to calculate pan, a value between -1 and 1. -1 is full sound on left speaker 0 is equal sound on both speakers 1 is full sound on right speaker Given values are: The source's 3D position The listener's 3D position The "look-at" direction (a normal vector) The "up" direction (also normal) Any help with this would be greatly appreciated. I know a number of computer languages, so it doesn't matter what language you write in, I am mainly just looking for the math. |
| ||
| Re: 3D Sound, calculating pan assuming that look at and 'up' are at roughly at right angles; take the cross product of the look-at and up direction. this will give you a vector that points from the characters left to right ( or right to left ). if the look at and up aren't at right angles... this still should work, but you must normalize the result. now, calculate the normalized vector between the listeners position and the source position. finally take the dot product of the normalized vector between listener and source and the normalized vector that points left to right. the dot product between two vectors gives the scalar projection of one vector onto another, when both vectors are normalized, this projection is a number between -1 and 1. If the value comes out backwards ( negative when it should be positive ) reverse the order of operands to the cross product, or of course, just multiply by -1. Test with something visual first, to see the magnitude of difference between different positions, then scale/offset the result according. S = source position |
| ||
| Re: 3D Sound, calculating pan Quote:
Thanks again! |
| ||
| Re: 3D Sound, calculating pan I needed this algorithm to instead calculate the vibration panning on an xbox360 controller. We would have a player in a pitch black room and an object would emit vibrations and the player could track that object down based on if it were on the left or the right of the player. THERE WAS A BIG PROBLEM HOWEVER I WAS USING GAMESTUDIO GAMESTUDIO IS VERY BAD AT PRECISE CALCULATIONS I thought I was doing the calculation wrong each time I read other people's similar pseudo-code. 5 days later I realized that Gamestudio is just plain stupid at any calculations. #define SourcePosition vector (vibra_obje.x, vibra_obje.y, vibra_obje.z) #define LookatDirection vector (camera.x + cos (camera.pan) * 80000000, camera.y + sin (camera.pan) * 80000000, 0) Notice that the value above is 80000000 GAMESTUDIO can only comprehend VERY BIG numbers. Because I tried working with small numbers earlier, GAMESTUDIO had a fit and lost alot of the vital precision. |
| ||
| Re: 3D Sound, calculating pan these codes are really confusing... what is this for? |
| ||
| Re: 3D Sound, calculating pan exactly what the title says |
| All times are GMT -4. The time now is 2:44 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC