[3060] | 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: |
---|
[5896] | 23 | * Erwin 'vaiursch' Herrsche |
---|
| 24 | * Reto Grieder |
---|
[3060] | 25 | * Co-authors: |
---|
| 26 | * ... |
---|
| 27 | * |
---|
| 28 | */ |
---|
[3196] | 29 | |
---|
[5896] | 30 | #include "WorldSound.h" |
---|
[3196] | 31 | |
---|
[3060] | 32 | #include <AL/alut.h> |
---|
[3196] | 33 | #include "util/Math.h" |
---|
[5914] | 34 | #include "core/CoreIncludes.h" |
---|
[5896] | 35 | #include "core/EventIncludes.h" |
---|
| 36 | #include "core/XMLPort.h" |
---|
[3060] | 37 | |
---|
[5738] | 38 | namespace orxonox |
---|
[3060] | 39 | { |
---|
[5896] | 40 | CreateFactory(WorldSound); |
---|
| 41 | |
---|
| 42 | WorldSound::WorldSound(BaseObject* creator) |
---|
| 43 | : StaticEntity(creator) |
---|
[3060] | 44 | { |
---|
[5896] | 45 | RegisterObject(WorldSound); |
---|
| 46 | } |
---|
[3060] | 47 | |
---|
[5896] | 48 | WorldSound::~WorldSound() |
---|
| 49 | { |
---|
[3060] | 50 | } |
---|
| 51 | |
---|
[5896] | 52 | void WorldSound::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
[3060] | 53 | { |
---|
[5896] | 54 | SUPER(WorldSound, XMLPort, xmlelement, mode); |
---|
[5899] | 55 | XMLPortParamExtern(WorldSound, BaseSound, this, "source", setSource, getSource, xmlelement, mode); |
---|
[5896] | 56 | XMLPortParamExtern(WorldSound, BaseSound, this, "loop", setLoop, getLoop, xmlelement, mode); |
---|
| 57 | XMLPortParamExtern(WorldSound, BaseSound, this, "playOnLoad", setPlayOnLoad, getPlayOnLoad, xmlelement, mode); |
---|
[3060] | 58 | } |
---|
| 59 | |
---|
[5896] | 60 | void WorldSound::XMLEventPort(Element& xmlelement, XMLPort::Mode mode) |
---|
[3060] | 61 | { |
---|
[5896] | 62 | SUPER(WorldSound, XMLEventPort, xmlelement, mode); |
---|
| 63 | XMLPortEventState(WorldSound, BaseObject, "play", play, xmlelement, mode); |
---|
[3060] | 64 | } |
---|
| 65 | |
---|
[5896] | 66 | void WorldSound::tick(float dt) |
---|
| 67 | { |
---|
[5899] | 68 | if (alIsSource(this->audioSource_)) |
---|
[5896] | 69 | { |
---|
| 70 | const Vector3& pos = this->getWorldPosition(); |
---|
[5899] | 71 | alSource3f(this->audioSource_, AL_POSITION, pos.x, pos.y, pos.z); |
---|
[3060] | 72 | ALenum error = alGetError(); |
---|
[5896] | 73 | if (error == AL_INVALID_VALUE) |
---|
[3060] | 74 | COUT(2) << "Sound: OpenAL: Invalid sound position" << std::endl; |
---|
| 75 | |
---|
[5896] | 76 | const Vector3& vel = this->getVelocity(); |
---|
[5899] | 77 | alSource3f(this->audioSource_, AL_VELOCITY, vel.x, vel.y, vel.z); |
---|
[3060] | 78 | error = alGetError(); |
---|
[5896] | 79 | if (error == AL_INVALID_VALUE) |
---|
[3060] | 80 | COUT(2) << "Sound: OpenAL: Invalid sound velocity" << std::endl; |
---|
| 81 | |
---|
[5896] | 82 | const Quaternion& orient = this->getWorldOrientation(); |
---|
[3060] | 83 | Vector3 at = orient.zAxis(); |
---|
[5899] | 84 | alSource3f(this->audioSource_, AL_DIRECTION, at.x, at.y, at.z); |
---|
[3060] | 85 | error = alGetError(); |
---|
[5896] | 86 | if (error == AL_INVALID_VALUE) |
---|
[3060] | 87 | COUT(2) << "Sound: OpenAL: Invalid sound direction" << std::endl; |
---|
| 88 | } |
---|
| 89 | } |
---|
| 90 | |
---|
[5896] | 91 | } |
---|