Hello! Can you tell me how to get the device orientation properties in babylonjs? The standard DeviceOrientationEvent in Web Api works with Euler angles,which causes gimbal lock in some cases. But the DeviceOrientationCamera in Babylonjs probably uses quaternions, and works perfectly! Is there a way to intercept the rotation values of the device that this camera receives? In my project I use a static camera, but I need to know the phone’s position in space to process the scene. Can I somehow use the quaternion properties of the DeviceOrientationCamera without using it as an active camera in the scene? Thank you!
It is a pity that I did not find the answer how to use the device orientation functionality already built into Babylon. Nevertheless, here is a good article for those who also faced the same problem. Dev.Opera — Practical Application and Usage of the W3C Device Orientation API
Hi @Steff and welcome to the forum. Weekends are always slow on the forum and I do not have a direct answer to your question but here are a couple of items that might be of interest.
Use Multi-Views - Babylon.js Documentation this might give a way of having two active cameras with one viewport so that you can perhaps read the quaternion properties from the DeviceOrientationCamera to apply to the camera used for the rendering. (This is just of the top of my head so no real idea if this would work or not)
Thank you so much! Yeah I understand situation with weekends : ) I will study these topics, maybe it will help.
I think I’m missing something important : )
Here is the specification of the camera class:
It contains accessor “absoluteRotation” which returns the camera’s quaternion.
Following the logic, all other types of cameras should be heirs to the base camera class.
But for some reason I can’t use this accessor with DeviceOrientation and VR cameras.
I would be glad if someone would explain this situation to me
Ok, on a closer look, these are different classes. Then I reformulate my question: is it possible to connect some kind of the InputsManager that is equivalent VR or DeviceOrientaion cameras to the base camera class?
Do not know enough about DeviceOrientationCamera to understand why you might need absoluteRotation and not just DeviceOrientationCamera - Babylon.js Documentation
absolutes are needed when parents used.
The only reason is because I do not find any get_ methods for receiving rotation data from VR and Device cameras. While for the basic camera they are exist. But maybe I do not see the obvious solution
Check the documentation link in my last post it is a property so you can read it directly without a get
Hooray, exactly what I need! Thank you so much for this tip, it saved my day! I was confused by the word Define in the description, for some reason I was sure that this parameter can only be set. I’m just starting to learn Babylon, so I’m confused about basic things : ) Thanks again!
If you check any Babylon.js API page you will find the constructor followed by
properties - public variables that you can read and write directly
accessors - access to private variables that you can get and/or set using their name only, ie in use they appear to behave as properties.
methods - some of which contain the words get and set; these allow you to get and set certain values via functions without and with parameters.