6

I have 1 object on scene and want to rotate it relative to its axis. I use THREE.TrackballControls. But when my object in not in the center of screen, rotation is bad (it is rotating relative to center of screen). I tried to change camera position before creating controls. But it did not work.

    var scene = new THREE.Scene();
    var camera = new THREE.PerspectiveCamera(75, 1, 0.1, 1000);
    camera.position.z = 3;
    camera.position.y = 10;

    controls = new THREE.TrackballControls( camera );

Is it possible to specify the center of camera rotation in TrackballControls? (So object will rotate not relatively center of scene)

Thanks, Zhenya

Zheden
  • 583
  • 2
  • 11
  • 36

1 Answers1

7

TrackballControls is rotating the camera, not the object.

You can set the controls.target like so:

controls.target.set( x, y, z );

three.js r.58

WestLangley
  • 102,557
  • 10
  • 276
  • 276
  • ah, set the cam initial position but not cam lookAt before `new THREE.TrackballControls`, then after use `.target.set` for the desired initial cam lookAt point. – Michelle Norris Jul 14 '16 at 13:37
  • I am using this code var bb = new THREE.Vector3(mesh.geometry.boundingBox.center()); controls.target.set(bb.x, bb.y, -6000); But it is not working.. – user2118784 Sep 19 '16 at 12:39