Bläddra i källkod

Fixed orientation issues with positional sound

Ivan Safrin 13 år sedan
förälder
incheckning
54c63c1ef2

+ 3 - 1
Core/Contents/Include/PolySceneSound.h

@@ -44,7 +44,7 @@ namespace Polycode {
 	*/	
 	*/	
 	class _PolyExport SceneSound : public SceneEntity {
 	class _PolyExport SceneSound : public SceneEntity {
 		public:
 		public:
-			SceneSound(const String& fileName, Number referenceDistance, Number maxDistance);
+			SceneSound(const String& fileName, Number referenceDistance, Number maxDistance, bool directionalSound = false);
 			virtual ~SceneSound();			
 			virtual ~SceneSound();			
 			void Update();
 			void Update();
 			
 			
@@ -54,6 +54,8 @@ namespace Polycode {
 			Sound *getSound();
 			Sound *getSound();
 			
 			
 		protected:
 		protected:
+		
+			bool directionalSound;
 			Sound *sound;
 			Sound *sound;
 	};
 	};
 	
 	

+ 1 - 1
Core/Contents/Include/PolySoundManager.h

@@ -38,7 +38,7 @@ namespace Polycode {
 		~SoundManager();
 		~SoundManager();
 		
 		
 		void setListenerPosition(Vector3 position);
 		void setListenerPosition(Vector3 position);
-		void setListenerOrientation(Vector3 orientation);	
+		void setListenerOrientation(Vector3 orientation, Vector3 upVector);	
 		void initAL();
 		void initAL();
 		
 		
 		/**
 		/**

+ 15 - 14
Core/Contents/Source/PolySceneSound.cpp

@@ -37,18 +37,17 @@ SceneSoundListener::~SceneSoundListener() {
 void SceneSoundListener::Update() {
 void SceneSoundListener::Update() {
 	Matrix4 finalMatrix = getConcatenatedMatrix();
 	Matrix4 finalMatrix = getConcatenatedMatrix();
 	CoreServices::getInstance()->getSoundManager()->setListenerPosition(finalMatrix.getPosition());
 	CoreServices::getInstance()->getSoundManager()->setListenerPosition(finalMatrix.getPosition());
-	
-	Vector3 direction;
-	direction.x = 0;		
-	direction.y = 0;
-	direction.z = -1;
-	direction = finalMatrix.rotateVector(direction);
-	CoreServices::getInstance()->getSoundManager()->setListenerOrientation(direction);
 
 
+	Vector3 upVector = Vector3(finalMatrix.ml[4], finalMatrix.ml[5], finalMatrix.ml[6]);
+	Vector3 direction = Vector3( -finalMatrix.ml[8], -finalMatrix.ml[9], -finalMatrix.ml[10]);
+	CoreServices::getInstance()->getSoundManager()->setListenerOrientation(direction, upVector);
 }
 }
 
 
 
 
-SceneSound::SceneSound(const String& fileName, Number referenceDistance, Number maxDistance) : SceneEntity() {
+SceneSound::SceneSound(const String& fileName, Number referenceDistance, Number maxDistance, bool directionalSound) : SceneEntity() {
+
+	this->directionalSound = directionalSound;
+	
 	sound = new Sound(fileName);
 	sound = new Sound(fileName);
 	sound->setIsPositional(true);
 	sound->setIsPositional(true);
 	sound->setPositionalProperties(referenceDistance, maxDistance);
 	sound->setPositionalProperties(referenceDistance, maxDistance);
@@ -62,12 +61,14 @@ void SceneSound::Update() {
 	Matrix4 finalMatrix = getConcatenatedMatrix();
 	Matrix4 finalMatrix = getConcatenatedMatrix();
 	sound->setSoundPosition(finalMatrix.getPosition());
 	sound->setSoundPosition(finalMatrix.getPosition());
 	
 	
-	Vector3 direction;
-	direction.x = 0;		
-	direction.y = 0;
-	direction.z = -1;
-	direction = finalMatrix.rotateVector(direction);
-	sound->setSoundDirection(direction);
+	if(directionalSound) {
+		Vector3 direction;
+		direction.x = 0;		
+		direction.y = 0;
+		direction.z = -1;
+		direction = finalMatrix.rotateVector(direction);
+		sound->setSoundDirection(direction);
+	}
 	
 	
 }
 }
 
 

+ 4 - 2
Core/Contents/Source/PolyScreenSound.cpp

@@ -37,13 +37,15 @@ ScreenSoundListener::~ScreenSoundListener() {
 void ScreenSoundListener::Update() {
 void ScreenSoundListener::Update() {
 	Matrix4 finalMatrix = getConcatenatedMatrix();
 	Matrix4 finalMatrix = getConcatenatedMatrix();
 	CoreServices::getInstance()->getSoundManager()->setListenerPosition(finalMatrix.getPosition());
 	CoreServices::getInstance()->getSoundManager()->setListenerPosition(finalMatrix.getPosition());
-	
+
+	Vector3 upVector = Vector3(0.0, 0.0, 1.0);
+		
 	Vector3 direction;
 	Vector3 direction;
 	direction.x = 0;		
 	direction.x = 0;		
 	direction.y = 0;
 	direction.y = 0;
 	direction.z = -1;
 	direction.z = -1;
 	direction = finalMatrix.rotateVector(direction);
 	direction = finalMatrix.rotateVector(direction);
-	CoreServices::getInstance()->getSoundManager()->setListenerOrientation(direction);
+	CoreServices::getInstance()->getSoundManager()->setListenerOrientation(direction, upVector);
 
 
 }
 }
 
 

+ 10 - 2
Core/Contents/Source/PolySoundManager.cpp

@@ -97,8 +97,16 @@ void SoundManager::setListenerPosition(Vector3 position) {
 	alListener3f(AL_POSITION, position.x, position.y, position.z);
 	alListener3f(AL_POSITION, position.x, position.y, position.z);
 }
 }
 
 
-void SoundManager::setListenerOrientation(Vector3 orientation) {
-	alListener3f(AL_ORIENTATION, orientation.x, orientation.y, orientation.z);
+void SoundManager::setListenerOrientation(Vector3 orientation, Vector3 upVector) {
+	ALfloat ori[6];
+	ori[0] = orientation.x;
+	ori[1] = orientation.y;
+	ori[2] = orientation.z;
+	
+	ori[3] = upVector.x;
+	ori[4] = upVector.y;
+	ori[5] = upVector.z;	
+	alListenerfv(AL_ORIENTATION,ori);
 }
 }
 
 
 SoundManager::~SoundManager() {
 SoundManager::~SoundManager() {