Search code examples
three.jsdevice-orientation

Threejs Rotating object with device orientation control


I am trying to achieve an effect similar to one of the cardboard app examples that Google has put out with their cardboard app called the 'exhibit'. I have a 3D object that I want to rotate using device orientation control. Right now with just the device orientation control, I can view the 3D object but when I turn around, the camera rotates (it seems) causing the object to fall out of view until I turn all the way back around to where it was in the beginning. In other words the camera seems to rotate in its axis as I look around. What I want is to be able to rotate the object as I turn around.

Kinda like this example http://threejs.org/examples/#misc_controls_orbit except I want to rotate using device orientation control.

Any idea how I can incorporate this feature?

Thank you for your assistance.


Solution

  • The answer to my own question for future seekers is to replace camera in

    controls = new THREE.DeviceOrientationControls(camera, true);
    

    with the 3D object you are trying to rotate.