Mingcen
Mingcen

Reputation: 3

Orbit camera redirection in threejs

I have a problem about camera redirection, unsolved for a long time. Briefly, I have a camera whose up vector is always (0,1,0). I want to move camera's position while keeping a certain 3D point appearing in the same position of the screen.

For example, let P be the camera's position, T be the camera's lookat, and F be the point appearing in (x,y) of the screen. Now P is changed to P' (camera's new position); in order to make F still appear in (x,y) of the screen, T must be changed.

Question is, what is the new value of T?

I believe the problem needs a lot of math. Tell me if you have any idea. Thanks greatly!

Upvotes: 0

Views: 108

Answers (1)

bjorke
bjorke

Reputation: 3305

Consider using the object hierarchy instead of applying math to the camera.

var cNull = new THREE.Object3D();
var camera == new THREE.PerspectiveCamera();
cNull.add(camera);
scene.add(cNull);

If you do this, then you can turn the camera to a single angle and the just use your point F(x,y,z) as the .lookAt() point for cNull. cNull will aim its center at F and the angular offset of the camera within cNull's coordinate system will keep that F point in a constant screen location.

Upvotes: 0

Related Questions