How to simulate Camera Control to get same position, rotation and quarternion?

Following is existing code to move the camera to a certain position (note that cameraControl is an instance of CameraControl class):

cameraControl.dollyTo(label.cam[5], true);
cameraControl.setPosition(label.cam[2], label.cam[3], label.cam[4], true);
cameraControl.setFocalOffset(label.cam[6], label.cam[7], 0, true);
cameraControl.rotateTo(label.cam[1], label.cam[0], true);

Supposely after the above operations, my camera has moved to position p1, with rotation r1 and quarternion q1
My goal is not to use CameraControl to get the same view i.e. same p1, r1 and q1. Is it possible to achieve that?

I tried this to set the position

let vec = new THREE.Vector3(label.cam[2], label.cam[3], label.cam[4]);
cameraRef.current?.position.copy(vec);

but this doesn’t make the camera’s position same as what camera control did.

Thank you for any help.

If by cameraControls, you mean @yomotsu/camera-controls, then you need to know that it has its own internal state, and it will reset the camera transformation from that state after each update.

You can use the toJSON/fromJSON methods, save the targeted state with toJSON, then apply it with fromJSON.

You also can’t control the camera rotation, since the cameraControls has a target, the camera will always look at that target. You can always move the target around.

2 Likes