Savinyu Pant
Savinyu Pant

Reputation: 1

How to make orbit controls' center something other than the center of the canvas?

I want to rotate an object or the camera around the center of an object, however the object is not placed in the center of the canvas, a little to the left. So using OrbitControls is making the object rotate it around the center of the canvas. When I change the target of the OrbitControls to the center of the object, due to how orbit controls is defined, it is rearranging the center again to the center of the canvas.

I know OrbitControls should not be used here but I don't know what I should use then? Even tried CameraControls but it still is rotating around the center of the canvas.

Upvotes: 0

Views: 91

Answers (1)

David Fitzgibbon
David Fitzgibbon

Reputation: 1

You need to set the target of the Orbit Controls.

EG

const controls = new OrbitControls(camera, renderer.domElement);
controls.target = mesh.position;
controls.update(); // needed to accurately set the first frame

Demo here: https://codepen.io/loficodes/pen/bGPgYJy/9b059ab08e8ad4dc3cb1c6683ca29be0

Upvotes: 0

Related Questions