Set initial rotation for OrbitControls()

Viewed 726

I have an initial roll, pitch & yaw for my camera and so I update the camera rotation with the respective values and it seems correct.

When I create and update the OrbitControls() the values are lost and I don't see a way to set the initial direction in the OrbitControls() constructor or methods.

I tried creating the controls after I updated my camera and that didn't help.

Is it possible to do this?

// Molly

1 Answers

You can compute the initial lookAt / target into some Vector3 computed with spherical / cartesian conversion

Then set the Orbit controller's target with it and save the state. It will use this target as a reference from now on

// Your initial target
let sphericalTarget = new THREE.Spherical(1, Math.PI / 2 - pitch, yaw)
let target = new THREE.Vector3().setFromSpherical(sphericalTarget) 

controls = new THREE.OrbitControls()
controls.target = target
controls.saveState()
Related