View Single Post
Join Date: Mar 2009
Posts: 2
Reputation: razix is an unknown quantity at this point 
Solved Threads: 0
razix razix is offline Offline
Newbie Poster

Re: 3D Sound, calculating pan

 
0
  #4
Mar 4th, 2009
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 ListenerPosition vector (camera.x, camera.y, camera.z)
#define LookatDirection vector (camera.x + cos (camera.pan) * 80000000, camera.y + sin (camera.pan) * 80000000, 0)
#define UpDirection vector (0, 0, 1)

function test_pan ()
{
	/*
	S = source position
	L = listeners positon
	A = look at direction
	B = up direction
	*/
	//dot( normalize( cross( A, B ) ), normalize( S - L ) )
	
	VECTOR cross_LookANDUp;
	vec_cross (cross_LookANDUp, LookatDirection, UpDirection);	
	
	VECTOR S_Subtract_L;
	vec_set (S_Subtract_L, SourcePosition);
	vec_sub (S_Subtract_L, ListenerPosition);
	
	vec_normalize (cross_LookANDUp, 1);
	vec_normalize (S_Subtract_L, 1);
	
	var panning = vec_dot (cross_LookANDUp, S_Subtract_L);
	
	if (panning < 0)
	{
		xbox_ctrl_vibrate (65535, 0);
	}
	else
	{
		xbox_ctrl_vibrate (0, 65535);
	}
}

#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.
Reply With Quote