48 lines
1.6 KiB
C++
48 lines
1.6 KiB
C++
#include "audio.h"
|
|
|
|
irrklang::vec3df Audio::convertVector(Vector3f& vec) const { return irrklang::vec3df(vec.x, vec.y, vec.z); };
|
|
|
|
Audio::Audio() {
|
|
m_engine = irrklang::createIrrKlangDevice();
|
|
m_engine->setDopplerEffectParameters(1);
|
|
m_engine->setRolloffFactor(1);
|
|
m_engine->setDefault3DSoundMinDistance(1);
|
|
m_engine->setDefault3DSoundMaxDistance(1000);
|
|
}
|
|
|
|
Audio::Audio(const char * music) {
|
|
m_engine = irrklang::createIrrKlangDevice();
|
|
m_engine->setDopplerEffectParameters(1);
|
|
m_engine->setRolloffFactor(1);
|
|
m_engine->setDefault3DSoundMinDistance(1);
|
|
m_engine->setDefault3DSoundMaxDistance(1000);
|
|
m_music = m_engine->play2D(music, true, true, true, irrklang::ESM_STREAMING);
|
|
}
|
|
|
|
Audio::~Audio() {
|
|
m_music->drop();
|
|
m_engine->drop();
|
|
}
|
|
|
|
void Audio::Update3DAudio(Vector3f& pos, Vector3f& dir, Vector3f& speed) {
|
|
m_engine->setListenerPosition(convertVector(pos),
|
|
convertVector(dir),
|
|
convertVector(speed));
|
|
}
|
|
|
|
void Audio::Create3DAudioObj(irrklang::ISound* sound, const char* name, Vector3f& pos, Vector3f& speed, float volume = 1) {
|
|
sound = m_engine->play3D(name, convertVector(pos), true, false, true, irrklang::ESM_NO_STREAMING, true);
|
|
sound->setVelocity(convertVector(speed));
|
|
sound->setVolume(volume);
|
|
}
|
|
|
|
void Audio::Render3DAudioObj(irrklang::ISound* sound, Vector3f& pos, Vector3f& speed, float volume = 1) {
|
|
sound->setPosition(convertVector(pos));
|
|
sound->setVelocity(convertVector(speed));
|
|
sound->setVolume(volume);
|
|
}
|
|
|
|
void Audio::ToggleMusicState() { m_music->setIsPaused(!m_music->getIsPaused()); }
|
|
|
|
void Audio::PauseEngine() { m_engine->setAllSoundsPaused(); }
|