google-ar / three.ar.js

A helper three.js library for building AR web experiences that run in WebARonARKit and WebARonARCore
https://developers.google.com/ar/develop/web/getting-started
Apache License 2.0
2.91k stars 365 forks source link

Normalise the world rotation axis #95

Closed cosmo-naut closed 6 years ago

cosmo-naut commented 6 years ago

Currently world axes are all set according to the rotation and position of the phone when the app is initialised, as far as I understand. Is this correct?

Perhaps there is a very obvious and easy mathematical solution to my problem but I am encountering difficulties. I want to rotate an object so that one of it's faces always points forward from the camera. I was accomplishing this by setting the y rotation of the object to be the y of the camera and the x and z rotations to be that of the plane. This works until I rotate beyond 90 degrees in either direction in which the shape begins to rotate weirdly, spinning more than it should.

I may have incorrectly read my problem but I think it could be an issue to do with the y rotation of the camera changing rapidly in that region.

Perhaps someone could shed some light

jsantell commented 6 years ago

In the load model example, when the model is placed, it is oriented to face the camera/user. This could be a good start, and also check out Three's Object3D lookAt which does something similar, although this is more of a three.js question

cosmo-naut commented 6 years ago

although this is more of a three.js question

You're right, and what you've suggested helped me a lot. Feel free to remove this issue unless you think it's worth keeping for posterity :)