- Home /
Using deviceOrientation to calibrate Camera
Hi,
I would like the deviceOrientation to effectively control the camera in a scene, to achieve the effect of moving around a virtual environment within the app. I specifically want the camera to be transformed in sync with the deviceOrientation, rather than transforming everything else.
To achieve this I'm attempting the following flow:
At a single time during runtime, record the current deviceOrientation as 'calibrationOrientation', and the current camera transform as 'calibrationCamera'. From then on: 1. derive a transform 'orientationUpdate' representing the difference from calibrationOrientation to the current deviceOrientation. 2. apply orientationUpdate to calibrationCamera.
I have 2 parts to this question, the first is the sanity check on my approach; am i trying to solve this in a reasonable and logical manner? the second is how do i find the 'difference' between 2 transforms.
ie.
Transform difference = Input.deviceOrientation - calibrationOrientation;
and how do i 'apply' it to the camera
ie.
Camera.current.transform = calibrationCamera + difference;
I think i probably need to obtain a matrix4x4 of the transforms and inverse one and multiply, but I'm not sure how to do this with Unity classes.
Thanks.