TheCherno / Sparky

Cross-Platform High Performance 2D/3D game engine for people like me who like to write code.
Apache License 2.0
1.1k stars 221 forks source link

Basic 3D audio added #114

Open cappah opened 8 years ago

cappah commented 8 years ago

Audio scales based on the distance of the object emitting sound within a given radius.

Audio is panned left, center or right based on the angle of the object emitting sound in conjunction with the direction the camera is facing. Objects emitting sound that are left of the camera in accordance to the camera's facing direction will pan the audio to the left speaker for example.

cappah commented 8 years ago

UPDATE: 5/18/2016 SetPanByAngle broken

UPDATE: 5/19/2016 Fixed and improved SetPanByAngle SetPanByAngle requires the following in the base Camera class:

protected:
float m_Yaw;
public:
inline float GetYaw() const { return m_Yaw; }

Example Usage Within Test3D::OnInit():

audio::SoundManager::Add(new audio::Sound("name", "resource audio dir/name.*"));
audio::SoundManager::Get("name")->Loop();

Within Test3D::OnUpdate() (specifically in this order):

audio::SoundManager::Get("name")->SetGainByDistance(m_Scene->GetCamera()->GetPosition(), g_CubeTransform, 50.0f, 0.7f);
audio::SoundManager::Get("name")->SetPanByAngle(m_Scene->GetCamera()->GetPosition(), g_CubeTransform, m_Scene->GetCamera()->GetYaw(), 25.0f);
Jacob-Mango commented 8 years ago

I would recommend using SP_INFO instead of std::cout.

cappah commented 8 years ago

@Jacob-Mango That's part of the original Sound.cpp