Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 6, 2009, 11:12:01 PM (15 years ago)
Author:
rgrieder
Message:

Added some basic sound classes: WorldSound (to be used for 3D sound, is a WorldEntity) and AmbientSound (BaseObject, just add it somewhere and it will play with playOnLoad=true).
Also moved the sound listener device updating to the HumanController. We might want to modify this again so that the listener is at the camera position again, not at the space ship.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core5/src/orxonox/sound/SoundManager.cc

    r5881 r5896  
    3636#include "core/GameMode.h"
    3737#include "core/ScopedSingletonManager.h"
    38 #include "CameraManager.h"
    39 #include "graphics/Camera.h"
    40 #include "SoundBase.h"
    4138
    4239namespace orxonox
     
    8986    }
    9087
    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)
    9889    {
    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;
    10094    }
    10195
    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)
    10697    {
    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();
    113101
    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 };
    117104
    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);
    133106        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)
    148108            COUT(2) << "Sound: OpenAL: Invalid listener orientation" << std::endl;
    149 
    150         // update sounds
    151         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 available
    157     */
    158     bool SoundManager::isSoundAvailable()
    159     {
    160         return this->soundavailable_;
    161109    }
    162110}
Note: See TracChangeset for help on using the changeset viewer.