1

I'm using GVR Android library version 1.190 and trying to play both 360 and 180 degrees videos in the video360 example project. In both cases the 2D view (MonoscopicView) starts the playback fine, but the viewer camera position is never centered to the center of the video. It instead starts randomly off-centered by horizontal axis. Same behavior on multiple devices. Anyone knows how to center the view to the video center when 2D view starts?

1 Answers1

1

Turns out that sensor data from Sensor.TYPE_GAME_ROTATION_VECTOR are having very different values (angles) every time my activity register a listener to it. It only takes a small tilt of the phone to get really different values. Different devices also respond differently but they all have offset readings. This lead to the initial view angle being positioned (usually) 90 degrees either to the left or right from the center of video. Thanks to this post, I managed to calculate the initial heading offset and rotate phone position matrix to compensate.

Add a member variable private float initialHeading with initial value 0. Then, in PhoneOrientationListener's onSensorChanged add the following code after the Android to OpenGL matrix rotation:

if (initialHeading == 0) {
    initialHeading = (float) ((angles[0] + 2 * Math.PI) % (2 * Math.PI));
}
float angle = (float) ((Math.PI - initialHeading) * 180 / Math.PI);
Matrix.rotateM(phoneInWorldSpaceMatrix, 0, angle, 0, 1, 0);