I am looking to implement a feature where objects can be moved along a plane parallel to the projection plane using the mouse. The challenge is to keep the distance between any selected object and the camera's projection plane constant throughout the movement. While a similar query has been raised before, my requirement extends beyond just the z=0 plane and encompasses arbitrary camera angles and positions of both camera and objects. Additionally, it must support orthographic projection as well. I have set up a fiddle for this purpose
In the code snippet within the mousemove event handler:
var v = new THREE.Vector3(
(event.clientX/window.innerWidth)*2-1,
-(event.clientY/window.innerHeight)*2+1,
1
);
projector.unprojectVector(v,camera);
var dist = circle.position.sub(camera.position,circle.position),
pos = camera.position.clone();
pos = pos.add(pos,
v.sub(v,camera.position).normalize().multiplyScalar(dist.length())
);
The circle now follows the mouse position while maintaining a constant distance from the camera, resulting in spherical movement. However, when switching to the ortographic camera mode (click), the expected behavior of tracking the mouse position is not observed.