Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core5/src/orxonox/sound/WorldSound.cc @ 5899

Last change on this file since 5899 was 5899, checked in by rgrieder, 15 years ago

Renaming BaseSound::setSoundFile (and all its associates) to setSource to be compliant with classes like ParicleInterface.

  • Property svn:eol-style set to native
File size: 3.0 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/EventIncludes.h"
35#include "core/XMLPort.h"
36
37namespace orxonox
38{
39    CreateFactory(WorldSound);
40
41    WorldSound::WorldSound(BaseObject* creator)
42        : StaticEntity(creator)
43    {
44        RegisterObject(WorldSound);
45    }
46
47    WorldSound::~WorldSound()
48    {
49    }
50
51    void WorldSound::XMLPort(Element& xmlelement, XMLPort::Mode mode)
52    {
53        SUPER(WorldSound, XMLPort, xmlelement, mode);
54        XMLPortParamExtern(WorldSound, BaseSound, this, "source", setSource, getSource, xmlelement, mode);
55        XMLPortParamExtern(WorldSound, BaseSound, this, "loop", setLoop, getLoop, xmlelement, mode);
56        XMLPortParamExtern(WorldSound, BaseSound, this, "playOnLoad", setPlayOnLoad, getPlayOnLoad, xmlelement, mode);
57    }
58
59    void WorldSound::XMLEventPort(Element& xmlelement, XMLPort::Mode mode)
60    {
61        SUPER(WorldSound, XMLEventPort, xmlelement, mode);
62        XMLPortEventState(WorldSound, BaseObject, "play", play, xmlelement, mode);
63    }
64
65    void WorldSound::tick(float dt)
66    {
67        if (alIsSource(this->audioSource_))
68        {
69            const Vector3& pos = this->getWorldPosition();
70            alSource3f(this->audioSource_, AL_POSITION, pos.x, pos.y, pos.z);
71            ALenum error = alGetError();
72            if (error == AL_INVALID_VALUE)
73                COUT(2) << "Sound: OpenAL: Invalid sound position" << std::endl;
74
75            const Vector3& vel = this->getVelocity();
76            alSource3f(this->audioSource_, AL_VELOCITY, vel.x, vel.y, vel.z);
77            error = alGetError();
78            if (error == AL_INVALID_VALUE)
79                COUT(2) << "Sound: OpenAL: Invalid sound velocity" << std::endl;
80
81            const Quaternion& orient = this->getWorldOrientation();
82            Vector3 at = orient.zAxis();
83            alSource3f(this->audioSource_, AL_DIRECTION, at.x, at.y, at.z);
84            error = alGetError();
85            if (error == AL_INVALID_VALUE)
86                COUT(2) << "Sound: OpenAL: Invalid sound direction" << std::endl;
87        }
88    }
89
90}
Note: See TracBrowser for help on using the repository browser.