Skip to content

Commit

Permalink
[audiosource] removed forgotten log which spams
Browse files Browse the repository at this point in the history
  • Loading branch information
PanosK92 committed Feb 13, 2025
1 parent 324167e commit badfc1d
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions runtime/World/Components/AudioSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,21 +140,30 @@ namespace spartan

if (m_is_3d)
{
// todo: implement panning to stick a dot product in there

// attenuation
if (Camera* camera = Renderer::GetCamera().get())
{
Vector3 camera_position = camera->GetEntity()->GetPosition();
Vector3 sound_position = GetEntity()->GetPosition();
float distance_squared = Vector3::DistanceSquared(camera_position, sound_position);

// inverse square law with a rolloff factor
const float rolloff_factor = 20.0f;
float volume = 1.0f / (1.0f + (distance_squared / (rolloff_factor * rolloff_factor)));
volume = max(0.0f, min(volume, 1.0f));
SP_LOG_INFO("%f", volume);
SetVolume(volume);
Vector3 camera_position = camera->GetEntity()->GetPosition();
Vector3 sound_position = GetEntity()->GetPosition();

// panning
{
Vector3 camera_to_sound = (sound_position - camera_position).Normalized();
float camera_dot_sound = Vector3::Dot(camera->GetEntity()->GetForward(), camera_to_sound);

// todo
// Mix_SetPanning() is probably the key function
}

// attenuation
{
// inverse square law with a rolloff factor
float distance_squared = Vector3::DistanceSquared(camera_position, sound_position);
const float rolloff_factor = 20.0f;
float volume = 1.0f / (1.0f + (distance_squared / (rolloff_factor * rolloff_factor)));
volume = max(0.0f, min(volume, 1.0f));

SetVolume(volume);
}
}
}
}
Expand Down

0 comments on commit badfc1d

Please sign in to comment.