Index: trunk/src/sdl/sdl_audio.cc
===================================================================
--- trunk/src/sdl/sdl_audio.cc	(revision 329)
+++ trunk/src/sdl/sdl_audio.cc	(revision 330)
@@ -7,4 +7,5 @@
 #include "nv/sdl/sdl_audio.hh"
 
+#include <glm/gtx/vector_angle.hpp>
 #include "nv/lib/sdl.hh"
 #include "nv/lib/sdl_mixer.hh"
@@ -31,13 +32,53 @@
 }
 
-
-nv::channel sdl::audio::play_sound( sound a_sound )
+nv::channel nv::sdl::audio::play_sound( sound a_sound, float volume, float pan /*= 0.0f */ )
 {
 	sound_info* info = m_sounds.get( a_sound );
 	if ( info )
 	{
-		if ( Mix_PlayChannel(-1, (Mix_Chunk*)( info->sdl_sound), 0) == -1 )
+		int channel = Mix_PlayChannel(-1, (Mix_Chunk*)( info->sdl_sound), 0);
+		if ( channel == -1 )
 		{
 			NV_LOG( LOG_WARNING, "SDL_mixer failed to play -- " << Mix_GetError() );
+		}
+		else
+		{
+			Mix_Volume( channel, int( volume * 128.0f ) );
+			if ( pan != 0.0f) 
+			{
+				uint8 right = (uint8)( (pan + 1.0f) * 127.0f ); 
+				Mix_SetPanning( channel, 254-right, right );
+			}
+			else
+			{
+				Mix_SetPanning( channel, 255, 255 );
+			}
+		}
+	}
+	return channel();
+}
+
+nv::channel nv::sdl::audio::play_sound( sound a_sound, vec3 position )
+{
+	sound_info* info = m_sounds.get( a_sound );
+	if ( info )
+	{
+		int channel = Mix_PlayChannel(-1, (Mix_Chunk*)( info->sdl_sound), 0);
+		if ( channel == -1 )
+		{
+			NV_LOG( LOG_WARNING, "SDL_mixer failed to play -- " << Mix_GetError() );
+		}
+		else
+		{
+			vec3 relative = position - m_position;
+			float angle = 0;
+			float distance = 0;
+			if ( relative != vec3() )
+			{
+				angle = -glm::orientedAngle( m_forward, glm::normalize( relative ), m_up );
+				distance = glm::clamp( 20.0f * glm::length( relative ), 0.0f, 255.0f );
+			}
+			if ( angle < 0.0f ) angle += 360.0f;
+			Mix_SetPosition( channel, sint16(angle), uint8(distance) );
 		}
 	}
@@ -47,5 +88,5 @@
 nv::sound nv::sdl::audio::load_sound( const std::string& a_path )
 {
-	// TODO: this is a really wierd error - if we remove this check, all hell gets loose
+	// TODO: this is a really weird error - if we remove this check, all hell gets loose
 	if ( Mix_LoadWAV_RW == nullptr || SDL_RWFromFile == nullptr ) 
 	{
@@ -64,7 +105,7 @@
 }
 
-void nv::sdl::audio::update()
+void nv::sdl::audio::update( vec3 position )
 {
-	// no-op
+	m_position = position;
 }
 
@@ -88,2 +129,8 @@
 }
 
+void nv::sdl::audio::set_orientation( vec3 forward, vec3 up )
+{
+	m_forward = forward;
+	m_up      = up;
+}
+
