Changeset 2931
- Timestamp:
- Apr 27, 2009, 2:41:50 PM (16 years ago)
- Location:
- code/branches/sound/src/sound
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/sound/src/sound/SoundBase.cc
r2899 r2931 27 27 */ 28 28 29 #include <SoundBase.h>30 #include <SoundManager.h>31 32 #include <Ogre/SceneNode.h>29 #include "orxonox/objects/worldentities/WorldEntity.h" 30 #include "util/Math.h" 31 #include "SoundManager.h" 32 #include "SoundBase.h" 33 33 34 34 namespace orxonox 35 35 { 36 SoundBase::SoundBase( Ogre::SceneNode* node)36 SoundBase::SoundBase(WorldEntity* entity) 37 37 { 38 38 this->source_ = 0; 39 39 this->buffer_ = 0; 40 this-> node_ = node;40 this->entity_ = entity; 41 41 42 if(SoundBase::soundmanager_s == null)43 SoundBase::soundmanager_s = =SoundManager::instance();42 if(SoundBase::soundmanager_s == NULL) 43 SoundBase::soundmanager_s = SoundManager::instance(); 44 44 } 45 45 46 void SoundBase::attachTo Node(Ogre::ScenceNode* node)46 void SoundBase::attachToEntity(WorldEntity* entity) 47 47 { 48 this->node_ = node; 48 this->entity_ = entity; 49 this->update(); 49 50 } 50 51 52 void SoundBase::update() { 53 if(alIsSource(this->source_)) { 54 Vector3 pos = this->entity_->getPosition(); 55 alSource3f(this->source_, AL_POSITION, pos.x, pos.y, pos.z); 56 ALenum error = alGetError(); 57 if(error == AL_INVALID_VALUE) 58 COUT(2) << "OpenAL: Invalid sound position" << std::endl; 59 60 Vector3 vel = this->entity_->getVelocity(); 61 alSource3f(this->source_, AL_VELOCITY, vel.x, vel.y, vel.z); 62 error = alGetError(); 63 if(error == AL_INVALID_VALUE) 64 COUT(2) << "OpenAL: Invalid sound position" << std::endl; 65 66 Quaternion orient = this->entity_->getOrientation(); 67 Vector3 at = orient.zAxis(); 68 alSource3f(this->source_, AL_DIRECTION, at.x, at.y, at.z); 69 error = alGetError(); 70 if(error == AL_INVALID_VALUE) 71 COUT(2) << "OpenAL: Invalid sound position" << std::endl; 72 } 73 } 74 75 void SoundBase::play(bool loop) { 76 if(alIsSource(this->source_)) { 77 if(loop) 78 alSourcei(this->source_, AL_LOOPING, AL_TRUE); 79 else 80 alSourcei(this->source_, AL_LOOPING, AL_FALSE); 81 alSourcePlay(this->source_); 82 } 83 } 84 85 void SoundBase::stop() { 86 if(alIsSource(this->source_)) { 87 alSourceStop(this->source_); 88 } 89 } 90 91 void SoundBase::pause() { 92 if(alIsSource(this->source_)) { 93 alSourcePause(this->source_); 94 } 95 } 96 97 bool SoundBase::isPlaying() { 98 if(alIsSource(this->source_)) { 99 return getSourceState() == AL_PLAYING; 100 } 101 } 102 103 bool SoundBase::isPaused() { 104 if(alIsSource(this->source_)) { 105 return getSourceState() == AL_PAUSED; 106 } 107 } 108 109 bool SoundBase::isStopped() { 110 if(alIsSource(this->source_)) { 111 return getSourceState() == AL_INITIAL || getSourceState() == AL_STOPPED; 112 } 113 } 114 115 ALint SoundBase::getSourceState() { 116 ALint state; 117 alGetSourcei(this->source_, AL_SOURCE_STATE, &state); 118 return state; 119 } 51 120 } // namespace: orxonox -
code/branches/sound/src/sound/SoundBase.h
r2930 r2931 32 32 #include <string> 33 33 34 class Ogre::SceneNode;35 class Orxonox::SoundManager;36 37 34 namespace orxonox 38 35 { 36 class SoundManager; 37 class WorldEntity; 39 38 /** 40 39 * The SoudBase class is the base class for all sound file loader classes. … … 45 44 { 46 45 public: 47 SoundBase( Ogre::SceneNode* node);46 SoundBase(WorldEntity* entity); 48 47 ~SoundBase(); 49 48 50 void attachTo Node(Ogre::SceneNode* node);49 void attachToEntity(WorldEntity* entity); 51 50 void update(); 52 51 void play(bool loop); … … 55 54 56 55 bool isPlaying(); 56 bool isPaused(); 57 bool isStopped(); 57 58 58 59 virtual void loadFile(std::string filename) = 0; … … 61 62 ALuint source_; 62 63 ALuint buffer_; 63 Ogre::SceneNode* node_;64 WorldEntity* entity_; 64 65 65 66 static SoundManager* soundmanager_s; 67 68 ALint getSourceState(); 66 69 }; // class SoundBase 67 70 } // namepsace orxonox -
code/branches/sound/src/sound/SoundManager.cc
r2930 r2931 32 32 #include "orxonox/objects/worldentities/Camera.h" 33 33 #include "util/Math.h" 34 #include "SoundBase.h" 34 35 #include "SoundManager.h" 35 36 … … 108 109 alListener3f(AL_POSITION, pos.x, pos.y, pos.z); 109 110 ALenum error = alGetError(); 110 if(error != AL_INVALID_VALUE)111 if(error == AL_INVALID_VALUE) 111 112 COUT(2) << "OpenAL: Invalid listener position" << std::endl; 112 113 … … 116 117 Vector3 at = orient.zAxis(); 117 118 118 ALfloat * orientation= { at.x, at.y, at.z,119 ALfloat orientation[6] = { at.x, at.y, at.z, 119 120 up.x, up.y, up.z }; 120 121
Note: See TracChangeset
for help on using the changeset viewer.