viromedia / virocore

ViroCore cross-platform AR/VR renderer
MIT License
370 stars 108 forks source link

Use device SensorManager to rotate custom Camera with ViroViewScene #310

Open fzaiatz opened 5 years ago

fzaiatz commented 5 years ago

I'm using a ViroViewScene to show a virtual environment, and I need to navigate it around the origin by using the devices's sensors (only the rotation). It's kind of working, but it's not a 100% working solution. Is this approach the correct one?

Node pointOfView = new Node();
Camera camera = new Camera();
camera.setPosition(new Vector(0, 1.6f, 0));
pointOfView.setCamera(camera);
viroView.setPointOfView(pointOfView);
viroView.setFrameListener(() -> camera.setRotation(orientationHelper.getQuaternion()));

I'm using this one as the orientation provider. All I do then is:

public com.viro.core.Quaternion getQuaternion() {
    orientationProvider.getQuaternion(tmpQuaternion);
    com.viro.core.Quaternion qq = new com.viro.core.Quaternion(tmpQuaternion.x(), tmpQuaternion.y(), tmpQuaternion.z(), tmpQuaternion.w());
    return qq.invert().multiply(com.viro.core.Quaternion.makeIdentity().makeRotation(-90f, new Vector(1f, 0, 0)));
}

A couple of notes regarding this "almost working" solution:

  1. The Quaternion needs to be inverted
  2. Then rotated 90 around X
  3. The Scene looks good (or not) based on where the user is pointing at <- weird?

This is 100% custom. Do you guys have a working example of this?

Thanks