I'm trying to set sound panning in my game depending on camera position, rotation and audio source position.
I was able to set sound panning depending on camera position (listener), and audio source like this:
Vector3 toSourceVector = Vector3::subtract(sourceTransform->position, listenerTransform->position);
float value = MathUtil::clamp(toSourceVector.x, -1.5f, 1.5f);
value = value + 1.5f;
float perc = (value / 3.0f) * 254.0f;
AudioManager::setPanning(254.0f - perc, perc);
Max panning value on the right/left speaker is 254. When I'm standing on the front of the audio source (without rotating my camera), panning values are: 127 and 127, for example, when the audio source is on my right side, panning values are 0 and 254.
Obviously, if I rotate my camera, sound panning is same.
I've got Vector3 with camera (listener) rotation values (x, y, z).
My question is: how to calculate panning values depending on camera rotation too?