1

I am using threejs (r73). I use a PerspectiveCamera. My goal is to implement mouse interaction. For that purpose I want to use TrackballControls.js . But I want a slightly different behaviour.

  1. I want to rotate around the point that the user picked on the screen
  2. I want to zoom in direction of the mouse position

For the second point I already found a "solution" at stackoverflow. The zoom works, but when I change the target vector of the control, panning and rotating does not work any longer.

Can anyone provide such an modified implementation of TrackballControls or help me with that?

EDIT

With the applied "solution" panning still works but rotating doesn't.

The idea from https://stackoverflow.com/a/16817727/2657179 also does not work.

Community
  • 1
  • 1
Kilian
  • 533
  • 4
  • 11
  • In the application you are using, will the point that the user clicks be an object? Or could it potentially be empty space? – Rush2112 Jul 14 '16 at 13:05
  • It could be empty space. I am using the following function to get the 3D-Coordinates from a mouse click: `function mouseToWorldSpace(clientX, clientY, camera) { //calculate mouse position in normalized device coordinates //(-1 to +1) var mouseX = (clientX / window.innerWidth) * 2 - 1; var mouseY = -(clientY / window.innerHeight) * 2 + 1; var vector = new THREE.Vector3(mouseX, mouseY, 1); vector.unproject(camera); return vector; }` @Rush2112 – Kilian Jul 18 '16 at 07:19
  • The biggest problem with empty space orbiting is that you don't know _where_ they want to click, you'll have to assume, so that will require linear algebra to make the correct assumption on where they want to orbit around. Otherwise, unprojecting the vector will place the 3D mouseclick extremely close to the camera – Rush2112 Jul 18 '16 at 13:03
  • @Rush2112 You are completly right! Within my Scene, I am rendering a machine. My workaround now is, that when the user rotates the scene while clicking the machine, I want to rotate around that picked point on the machine. When the user clicks in empty space, I just rotate around the boundingbox-center of the machine. – Kilian Jul 22 '16 at 07:51
  • I have one problem now. Setting TrackballControls.target means that the picked point automatically will be moved to the center of the screen. @Rush2112 – Kilian Jul 22 '16 at 14:03
  • That;s because on the Trackball update function, it calls `lookAt( target )` https://github.com/mrdoob/three.js/blob/dev/examples/js/controls/TrackballControls.js#L322 – Rush2112 Jul 22 '16 at 15:28
  • Yes, I tried to add a new member "rotationTarget" to the class and adapt the function "rotateCamera" to rotate about that "rotationTarget" but without any success yet. @Rush2112 – Kilian Jul 25 '16 at 07:09

0 Answers0