Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation2/src/orxonox/sound/WorldSound.cc @ 6269

Last change on this file since 6269 was 6269, checked in by rgrieder, 14 years ago

At last, found the sound bug: A long time ago somebody wrote AL_POSITION instead of AL_ORIENTATION and the orientation of the listener was updated AFTER the position.
Also fixed a problem with the wrong quaternion axis for the listener orientation.

  • Property svn:eol-style set to native
File size: 3.2 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Erwin 'vaiursch' Herrsche
24 *      Reto Grieder
25 *   Co-authors:
26 *      ...
27 *
28 */
29
30#include "WorldSound.h"
31
32#include <AL/alut.h>
33#include "util/Math.h"
34#include "core/CoreIncludes.h"
35#include "core/EventIncludes.h"
36#include "core/XMLPort.h"
37#include "SoundManager.h"
38
39namespace orxonox
40{
41    CreateFactory(WorldSound);
42
43    WorldSound::WorldSound(BaseObject* creator)
44        : StaticEntity(creator)
45    {
46        RegisterObject(WorldSound);
47        // WorldSound buffers should be pooled when they're not used anymore
48        this->bPooling_ = true;
49    }
50
51    WorldSound::~WorldSound()
52    {
53    }
54
55    void WorldSound::XMLPort(Element& xmlelement, XMLPort::Mode mode)
56    {
57        SUPER(WorldSound, XMLPort, xmlelement, mode);
58        BaseSound::XMLPortExtern(xmlelement, mode);
59    }
60
61    void WorldSound::XMLEventPort(Element& xmlelement, XMLPort::Mode mode)
62    {
63        SUPER(WorldSound, XMLEventPort, xmlelement, mode);
64        XMLPortEventState(WorldSound, BaseObject, "play", play, xmlelement, mode);
65    }
66
67    void WorldSound::tick(float dt)
68    {
69        if (alIsSource(this->audioSource_))
70        {
71            const Vector3& pos = this->getWorldPosition();
72            alSource3f(this->audioSource_, AL_POSITION, pos.x, pos.y, pos.z);
73            ALenum error = alGetError();
74            if (error == AL_INVALID_VALUE)
75                COUT(2) << "Sound: OpenAL: Invalid sound position" << std::endl;
76
77            const Vector3& vel = this->getVelocity();
78            alSource3f(this->audioSource_, AL_VELOCITY, vel.x, vel.y, vel.z);
79            error = alGetError();
80            if (error == AL_INVALID_VALUE)
81                COUT(2) << "Sound: OpenAL: Invalid sound velocity" << std::endl;
82
83            const Vector3& direction = -this->getWorldOrientation().zAxis();
84            alSource3f(this->audioSource_, AL_DIRECTION, direction.x, direction.y, direction.z);
85            error = alGetError();
86            if (error == AL_INVALID_VALUE)
87                COUT(2) << "Sound: OpenAL: Invalid sound direction" << std::endl;
88        }
89    }
90
91    void WorldSound::changedActivity() 
92    {
93        SUPER(WorldSound, changedActivity);
94        if (this->isActive())
95            this->play();
96        else 
97            this->stop();
98    }
99
100    float WorldSound::getVolumeGain()
101    {
102        return SoundManager::getInstance().getVolume(SoundType::effects);
103    }
104}
Note: See TracBrowser for help on using the repository browser.