How to set the camera rotation in OrbitControls when transferring control from FlyControls to OrbitControls?

at NicerApp WebOS Unified Interface, i am working on a 3D folder and file viewer for a music player app.
(that page needs to be refreshed after an initial load at the moment)

when you click the mouse for over a second (left button), 3D cursor control is handed to FlyControls, with .dragToLook=true
so far so good

but when i let go of the mouse button and transfer control back to OrbitControls, the camera rotation gets all messed up.
i narrowed it down to OrbitControls.target not being able to get set to what FlyControls is looking at; FlyControls doesn’t maintain a similar .target coordinate at all! :frowning:

once again, i could really use some help here.

solved now, with the following code added :slight_smile:

onPointerUp( event, t ) {
    t.lookClock = -1;
    t.flyControls.enabled = false;
    t.cameraControls.enabled = true;
    t.orbitControls.enabled = true;

    // adjust camera position
    t.orbitControls.object.position.x = t.flyControls.object.position.x;
    t.orbitControls.object.position.y = t.flyControls.object.position.y;
    t.orbitControls.object.position.z = t.flyControls.object.position.z;

    // adjust view angle
    var tar = t.cameraControls._targetEnd.clone();
    tar.set(0,0,-1).applyQuaternion(t.camera.quaternion).add(t.camera.position);

    t.orbitControls.target.x = tar.x;
    t.orbitControls.target.y = tar.y;
    t.orbitControls.target.z = tar.z;


    t.cameraControls.setLookAt (
        t.flyControls.object.position.x,
        t.flyControls.object.position.y,
        t.flyControls.object.position.z,
        tar.x,
        tar.y,
        tar.z,
        false
    );
}

Glad you got it working!

fyi instead of this:

    t.orbitControls.object.position.x = t.flyControls.object.position.x;
    t.orbitControls.object.position.y = t.flyControls.object.position.y;
    t.orbitControls.object.position.z = t.flyControls.object.position.z;

you can just do

 t.orbitControls.object.position.add(t.flyControls.object.position)

Also when you need to reset orbitcontrols to not rotate your camera after switching to it, you can set the controls.target to a point directly in front of the camera… something like:

orbitControls.target.set(0,0,1).applyQuaternion(camera.quaternion).add(camera.position)