Hi, I currently have a arcRotateCamera setup in orthographic mode that zooms by manually setting the orthoLeft, orthoRight, orthoTop and orthoBottom properties on the camera object. This works fine, however I’d like it to zoom where the camera is rather than the centre of the screen. I’m pretty new to the 3D programming world and hence not 100% sure how I would even start to go about accomplishing that so any direction would be great.
For reference, this is roughly the code I wrote to zoom(actually broken up into multiple functions):
const delta = (Math.max(-1, Math.min(1, (event.wheelDelta || -event.detail)))) * 1.5;
const zoomingOut = delta < 0;
// limit zooming in to no less than 3 units.
if (!zoomingOut && Math.abs(camera.orthoLeft) <= 3)
return;
camera.orthoLeft += delta;
camera.orthoRight -= delta;
const ratio = canvas.height / canvas.width;
camera.orthoTop = camera.orthoRight * ratio;
camera.orthoBottom = camera.orthoLeft * ratio;
// decrease pan sensitivity the closer the zoom level.
camera.panningSensibility = 6250 / Math.abs(camera.orthoLeft);
right
You can move from 2d to 3d with something like that:
var target = BABYLON.Vector3.Unproject(
new BABYLON.Vector3(scene.pointerX, scene.pointerY, 0),
screenwidth,
screenheight,
new BABYLON.Matrix.Identity(),
cam.getViewMatrix(),
cam.getProjectionMatrix()
);
Thanks @Deltakosh for the code sample. It seems to give me the correct x & y coordinate however when I try to use those coordinates to set the position of the camera, or set the target of the camera, or both, strange things happen:
@constantinos I brought that in from the project I’m working on. It’s the constant that I found for my use case felt the best at the various zoom levels I allow.
For anyone that’s curious, I ended up changing the orthoLeft/Top/Right/Bottom to get it to zoom the way I wanted rather than changing the target and position of the camera. It works really well.