Changeset 5896 for code/branches/core5/src/orxonox/sound/SoundManager.cc
- Timestamp:
- Oct 6, 2009, 11:12:01 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core5/src/orxonox/sound/SoundManager.cc
r5881 r5896 36 36 #include "core/GameMode.h" 37 37 #include "core/ScopedSingletonManager.h" 38 #include "CameraManager.h"39 #include "graphics/Camera.h"40 #include "SoundBase.h"41 38 42 39 namespace orxonox … … 89 86 } 90 87 91 /** 92 * Add a SoundBase object to the list. Every SoundBase object should be in 93 * this list. 94 * 95 * @param sound Pointer to the SoundBase object to add 96 */ 97 void SoundManager::addSound(SoundBase* sound) 88 void SoundManager::setListenerPosition(const Vector3& position) 98 89 { 99 this->soundlist_.push_back(sound); 90 alListener3f(AL_POSITION, position.x, position.y, position.z); 91 ALenum error = alGetError(); 92 if (error == AL_INVALID_VALUE) 93 COUT(2) << "Sound: OpenAL: Invalid listener position" << std::endl; 100 94 } 101 95 102 /** 103 * Remove a SoundBase object from the list and destroy it. 104 */ 105 void SoundManager::removeSound(SoundBase* sound) 96 void SoundManager::setListenerOrientation(const Quaternion& orientation) 106 97 { 107 std::list<SoundBase*>::iterator pos = this->soundlist_.end(); 108 for(std::list<SoundBase*>::iterator i = this->soundlist_.begin(); i != this->soundlist_.end(); i++) 109 { 110 if((*i) == sound) 111 pos = i; 112 } 98 // update listener orientation 99 Vector3 up = orientation.xAxis(); // just a wild guess 100 Vector3 at = orientation.zAxis(); 113 101 114 delete (*pos); 115 this->soundlist_.erase(pos); 116 } 102 ALfloat orient[6] = { at.x, at.y, at.z, 103 up.x, up.y, up.z }; 117 104 118 /** 119 * Tick function, updates listener and registred SoundBase objects 120 * 121 * @param dt @see Orxonox::Tickable 122 */ 123 void SoundManager::tick(float dt) 124 { 125 if (!CameraManager::getInstancePtr()) 126 return; 127 128 // update listener position 129 Camera* camera = CameraManager::getInstance().getActiveCamera(); 130 if(camera == NULL) return; 131 Vector3 pos = camera->getPosition(); 132 alListener3f(AL_POSITION, pos.x, pos.y, pos.z); 105 alListenerfv(AL_POSITION, orient); 133 106 ALenum error = alGetError(); 134 if(error == AL_INVALID_VALUE) 135 COUT(2) << "Sound: OpenAL: Invalid listener position" << std::endl; 136 137 // update listener orientation 138 const Quaternion& orient = camera->getOrientation(); 139 Vector3 up = orient.xAxis(); // just a wild guess 140 Vector3 at = orient.zAxis(); 141 142 ALfloat orientation[6] = { at.x, at.y, at.z, 143 up.x, up.y, up.z }; 144 145 alListenerfv(AL_POSITION, orientation); 146 error = alGetError(); 147 if(error == AL_INVALID_VALUE) 107 if (error == AL_INVALID_VALUE) 148 108 COUT(2) << "Sound: OpenAL: Invalid listener orientation" << std::endl; 149 150 // update sounds151 for(std::list<SoundBase*>::iterator i = this->soundlist_.begin(); i != this->soundlist_.end(); i++)152 (*i)->update();153 }154 155 /**156 * Check if sound is available157 */158 bool SoundManager::isSoundAvailable()159 {160 return this->soundavailable_;161 109 } 162 110 }
Note: See TracChangeset
for help on using the changeset viewer.