1 // Copyright (C) 2015 Lucas Pires Camargo
3 // This file is part of neiasound - Qt-style OpenAL wrapper for games.
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
9 // 1. Redistributions of source code must retain the above copyright notice,
10 // this list of conditions and the following disclaimer.
12 // 2. Redistributions in binary form must reproduce the above copyright notice,
13 // this list of conditions and the following disclaimer in the documentation
14 // and/or other materials provided with the distribution.
16 // THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT ``AS IS'' AND ANY EXPRESS
17 // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
19 // NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
20 // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #include "nSoundListener.h"
27 #include "nSoundSystem.h"
29 #include "../scene/nSceneCamera.h"
30 #include "OgreCamera.h"
35 nSoundListener::nSoundListener(nSoundSystem * parent) :
45 void nSoundListener::setSourceCamera(nSceneCamera * cam)
49 disconnect(this, SLOT(cameraDestroyed()));
52 if(m_camera) //camera can be set to null
54 m_camLastPos = m_camera->ogreCamera()->getPosition();
55 connect(m_camera, SIGNAL(destroyed()), SLOT(cameraDestroyed()));
58 void nSoundListener::cameraDestroyed()
60 disconnect(this, SLOT(cameraDestroyed()));
65 void nSoundListener::update(qreal frameTime)
68 if(m_updating && m_camera)
70 nVec3 pos(m_camera->ogreCamera()->getRealPosition()),
71 dir(m_camera->ogreCamera()->getRealDirection()),
72 up(m_camera->ogreCamera()->getRealUp());
73 nVec3 vel = pos - m_camLastPos;
78 updateManual(QVector3D());
84 void nSoundListener::updateManual(QVector3D pos, QVector3D dir, QVector3D up, QVector3D vel)
95 alListener3f(AL_POSITION, pos[0], pos[1], pos[2]);
96 alListenerfv(AL_ORIENTATION, orient);
97 alListener3f(AL_VELOCITY, vel[0], vel[1], vel[2]);
99 if(alGetError()!=AL_NO_ERROR)
100 throw QString("nSoundListener: Failed to update listener transformations.");