Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set initial rotation for OrbitControls()

Tags:

three.js

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

like image 726
Molly Birk Avatar asked Jul 04 '26 19:07

Molly Birk


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()
like image 92
YGilk1 Avatar answered Jul 06 '26 09:07

YGilk1



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!