I've got a PerspectiveCamera
and set of coordinates (x,y,z).
How could I pan the camera to make these coordinates at the center of the screen?
The idea is to project the target point onto the plane passing through the camera spanned by the camera's up and right vector, and translate the camera to this point.
You can do this in one line with fairly simple math. Pseudocode:
cameraPosition = targetPosition + cameraForward*dot(cameraPosition - targetPosition, cameraForward)
where cameraForward
is the normalized camera's direction, targetPosition
is the point you want to be at the center of view and cameraPosition
is the camera's position. All are in the same coordinate space.
You can just use camera.lookAt(Vector3)
:
perspectiveCamera.lookAt(coordinates);
Here is how I would solve this problem.
Step explanation:
Nearest point:
For the nearest point to the ray, you can use the Ray class and the closestPointToPoint method.
Just create a ray going from the camera position allong the camera forward vector.
Sorry, no code, I don't write three.js.
But I think it isn't to hard to code it yourself.
three.js
, notunity
. \$\endgroup\$