Commit 215621f1 authored by David Reid's avatar David Reid

Fix an spatialization edge case relating to listener direction.

When the listener is looking at exactly the same direction as the world
up vector the 3D math breaks down due to a cross product evaluating to
a zero length vector.
parent ca502341
...@@ -9347,6 +9347,17 @@ MA_API ma_result ma_spatializer_process_pcm_frames(ma_spatializer* pSpatializer, ...@@ -9347,6 +9347,17 @@ MA_API ma_result ma_spatializer_process_pcm_frames(ma_spatializer* pSpatializer,
*/ */
axisZ = ma_vec3f_normalize(pListener->direction); /* Normalization required here because we can't trust the caller. */ axisZ = ma_vec3f_normalize(pListener->direction); /* Normalization required here because we can't trust the caller. */
axisX = ma_vec3f_normalize(ma_vec3f_cross(axisZ, pListener->config.worldUp)); /* Normalization required here because the world up vector may not be perpendicular with the forward vector. */ axisX = ma_vec3f_normalize(ma_vec3f_cross(axisZ, pListener->config.worldUp)); /* Normalization required here because the world up vector may not be perpendicular with the forward vector. */
/*
The calculation of axisX above can result in a zero-length vector if the listener is
looking straight up on the Y axis. We'll need to fall back to a +X in this case so that
the calculations below don't fall apart. This is where a quaternion based listener and
sound orientation would come in handy.
*/
if (ma_vec3f_len2(axisX) == 0) {
axisX = ma_vec3f_init_3f(1, 0, 0);
}
axisY = ma_vec3f_cross(axisX, axisZ); /* No normalization is required here because axisX and axisZ are unit length and perpendicular. */ axisY = ma_vec3f_cross(axisX, axisZ); /* No normalization is required here because axisX and axisZ are unit length and perpendicular. */
/* /*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment