Roberto
Roberto

Reputation: 9080

Method ViroARScene.getCameraOrientationAsync() returns strange values in rotation array

I'm developing a PoC with ViroReact lib but I'm getting strage values for the camera rotation.

Environment:

The ViroARScene.getCameraOrientationAsync() returns unexpected values in rotation array when I rotate the device over the y-axis, trying to keep the x and z axis fixed.

Specifically, when the y-axis reaches the -90º the x/z values change to +/180º and from this point the y-axis values are getting close to 0, for instance, instead of -135º the y-axis value is -45 with the x/z values in +/-180. In other words the y-axis values NEVER return an absolute value over 90.

Some examples (values have got an error margin of about 6 degrees):

Questions:

The code to retrieve the values:

<ViroARScene onTrackingUpdated={this._onInitialized} anchorDetectionTypes={"PlanesVertical"}>
...
</ViroARScene>

_onInitialized(state, reason) {
    if (state === ViroConstants.TRACKING_NORMAL && reason === ViroConstants.TRACKING_REASON_NONE) {
      console.log('Tracking initiated');
      this._scene.getCameraOrientationAsync().then(
        (orientation) => {
          console.log('Cam rot:', round(orientation.rotation));
        });
    }
  }

I've also created a GitHub issue with some mockups to show the rotation values expected and returned: https://github.com/ViroCommunity/viro/issues/13

Upvotes: 0

Views: 432

Answers (1)

Abraham Brookes
Abraham Brookes

Reputation: 1998

I think what you're coming up against might be Gimbal lock, which is the reason that a lot of 3d rotators are expressed in Quaternions, instead of the xyz (aka Euler - pronounced "oiler") system you are using now. It's probably expected behaviour for your system.

I'm not familiar with your platform but it might have built-in helpers or alternative methods you can use in order to work with Quaternions instead, if not then a solution for you might be to install a library (or write some code) that translates between Euler angles and Quaternions so that your calculations make more sense, if you are going to be spending time around the y-0.

Upvotes: 2

Related Questions