googlevr / gvr-android-sdk

Google VR SDK for Android
http://developers.google.com/vr/android/
Other
3.28k stars 1.28k forks source link

Videoplayer example code passes quat values incorrectly to gvrAudioProcessor.updateOrientation #572

Closed t-bashir-uk closed 6 years ago

t-bashir-uk commented 6 years ago

Playing a video clip with 1st order ambisonics audio I noticed that the sounds were coming from the wrong location in the Videoplayer example code. Left and right directions were swapped.

Function updateHeadAndEyeMatrices calls updateOrientation with parameters in order x, y, z, w. gvrAudioProcessor.updateOrientation( (headFromWorld[6] - headFromWorld[9] < 0) != (x < 0) ? -x : x, (headFromWorld[8] - headFromWorld[2] < 0) != (y < 0) ? -y : y, (headFromWorld[1] - headFromWorld[4] < 0) != (z < 0) ? -z : z, w);

However, if you look at the the function definition the order should be w, x, y, z. public synchronized void updateOrientation(float w, float x, float y, float z)

Making this fix corrects the left and right, however front an back are swapped. This can be corrected by changing sign when w and y are calculated...

float w = -(float) Math.sqrt(Math.max(0.0f, 1.0 + sx + sy + sz)) * 0.5f; float x = (float) Math.sqrt(Math.max(0.0f, 1.0 + sx - sy - sz)) * 0.5f; float y = -(float) Math.sqrt(Math.max(0.0f, 1.0 - sx + sy - sz)) * 0.5f; float z = (float) Math.sqrt(Math.max(0.0f, 1.0 - sx - sy + sz)) * 0.5f;

sigmaxipi commented 6 years ago

Thanks for pointing this out. We'll update the sample.

tweenk commented 6 years ago

This has been fixed internally and the fix should be present in the next release.

t-bashir-uk commented 6 years ago

Thanks for fixing it.