Igalia / wolvic

A fast and secure browser for standalone virtual-reality and augmented-reality headsets.
https://wolvic.org
Mozilla Public License 2.0
813 stars 105 forks source link

[VisionGlass] Fix controller orientation issues #1530

Closed svillar closed 2 months ago

svillar commented 2 months ago

Controller orientation was suffering from gimbal lock. This means that rotations higher than 90º started to exhibit weird behaviours like inverted or swapped axis. We tried to fix that in the past without much success, but now we do now the actual culprit of that gimbal lock and can fix that once for all.

The quaternion returned by the phone sensor is using Android axis. If the phone is on a table in horizontal position and portrait orientation with respect to the user, X goes right, Y goes forward and Z goes up. However in our world coordinates, X goes right (same) but Y goes up and Z goes backward (-Z is forward direction). So we have to transform the quaternion to follow that coordinate system.

Once that was fixed gimbal lock dissappeared. The only missing thing was to fix the calibration code removing some workarounds we had to add to get it "working" with the previous incorrect version of the orientation code.

Last but not least, we changed the sensor delay from NORMAL to GAME to get a little bit more accuracy in tracking.

Fixes #1484

svillar commented 2 months ago

LGTM

Great work. Fixes #1484

Perhaps consider inverting the values that we pass to the widget that displays the pointer's position, so it matches where we are actually pointing:

    @Override
    public void onSensorChanged(SensorEvent event) {
        ...

        mBinding.realignButton.updatePosition(- quaternion[1], - quaternion[0]);

        if (mAlignDialogFragment != null && mAlignDialogFragment.isVisible()) {
            mAlignDialogFragment.updatePosition(- quaternion[1], - quaternion[0]);
        }
    }

Ah right, yeah I'll do that.

javifernandez commented 2 months ago

I'm not sure this fixes 1522

javifernandez commented 2 months ago

I'm not sure this fixes 1522

I finally could verify this PR fixes 1522 as well.