I’m having trouble getting the DeviceOrientationCamera to consistently match the geographic compass direction the phone is pointing in (Android Chrome landscape). So if I’m pointing the device east then I should see the “east” part of my world.
It seems to be rather inconsistent.
Is this not fully supported across all devices yet? If so, is there a workaround?
Looks like it’s not possible … Improvement of DeviceOrientationCamera: Recover the real orientation North / South - Questions - Babylon.js
If that’s the case can I guarantee that the subject of my 3D scene is always in frame on initialization, across devices i.e. the scene starts out with subject directly in front and camera then moves relative to this? I’m concerned that more modern devices that do support absolute orientation may act differently to older devices that only support relative orientation. Or does Babylon DeviceOrientationCamera always produce consistent relative orientation regardless of device?
I’m even getting inconsistent initial camera orientation with this PG
What happens for me on my old Samsung Galaxy S6 is if I hit refresh while rotating slowly, scene objects are never in the same starting place twice. The red quad will flash up quickly in frame, then device orientation camera kicks in, but again it’s not always the same.
It doesn’t seem to initialize in the correct orientation (it is consistent though), it seems consistent and stable to me otherwise.
Maybe poll the magnetometer some more
Maybe recalibrate your phone’s sensor
I tried a newer Android device (mid 2018) and it seems to be consistent. It’s just my old Samsung Galaxy S6 (2015) which produces inconsistent results at times.
Have done more testing with various devices and not achieving consistent results.
Just wondering if it’s possible to force the initial DeviceOrientationCamera starting direction and all subsequent camera movement is relative to that?
Pinging @sebavan @Deltakosh as you’re listed as contributors to
If different devices produce different results for initial camera facing direction (i.e. not possible to 100% consistently match compass direction) due to
DeviceOrientationEvent browser and device differences, is it possible with
DeviceOrientationCamera to specify the initial starting camera direction and make all subsequent
DeviceOrientationEvent movements relative to that initial starting direction? At least that would produce consistent results.
I tried setting camera target but it seems to be overridden by device orientation.
Is it not always considering your start position as the default ???
@sebavan no it seems to be quite inconsistent. I can refresh on one device and it’ll sometimes initialise with the camera pointing in a different direction. And it’s difficult to get consistency across multiple devices.
It’s exhibiting this inconsistent behaviour with my complex scene and also this simple PG https://www.babylonjs-playground.com/#12WBC#1006
I’m just wondering if I’m doing something wrong, whether I’ve missed a setting?
Is there a way to force the initial
DeviceOrientationCamera starting direction and then all subsequent camera movement is relative to that?
Maybe @RaananW has an idea ???
The device orientation is providing us with the orientation of the device in space. This information is provided by the device itself, and its heading is decided by the device. It is using the accelerometer data, which means the only thing that is guaranteed is the direction of gravity. your bearing is not set at all and can be decided by the device itself. iOS deals with it differently than android, and even in the android eco-system, different browsers deal with it differently. Even if it does, compass data on mobile devices is very inaccurate and must be calibrated beforehand.
To get the orientation the device provides us, simply enter the scene with an orientation-0enabled device. we do no magic inside. We take the data from the device and pass it to its rotation. If you use touch/mouse before entering orientation mobde, the bearing you selected will be the initial rotation. This can be set by resetting
_initialQuaternion or calling
resetToCurrentRotation with the right axis, but we have already discussed that in a different thread.
Thanks @RaananW. I will try setting initial rotation as per your suggestions.
All I know is that my native stargazing app on android (point it at celestial bodies and it names them, draws constellations etc.) Requires me to calibrate each: pitch,roll,yaw every time I launch it so it provides at least a ‘good’ calibration rating, and even then it tends to be slightly off, but at least consistent.
Excited to see what you come up with.