How can I reuse a function from arcRotateCamera constructor? I want to use `camera.inputs.attached.mousewheel._zoomToMouse(delta)`, is it possible to use this function?

Hello everyone

is it possible to access the some functions inside the src/Cameras/Inputs/arcRotateCameraMouseWheelInput.ts and use it?

I want use the camera.inputs.attached.mousewheel._zoomToMouse(e) to define button for zoom in/out with the button, I want to know is it possible to use it?

here is my PG: https://playground.babylonjs.com/#Q8VH3H#33

and here is my code:


    camera.zoomToMouseLocation = true;
    var a= camera.inputs.attached.mousewheel["_zoomToMouse"]
    console.log("a",a)

        scene.onPointerObservable.add((e) => {
                 let delta = 0.01;

                scene.registerBeforeRender(() => {

            document.onkeydown = (e) => {

                if (e.key == "w") {
                    delta += 0.1
                }

                if (e.key == "q") {
                    delta -= 0.1
                }
            };
        camera.inputs.attached.mousewheel._zoomToMouse(delta)

        });
    }, BABYLON.PointerEventTypes.POINTERTAP);

sometimes it works, and sometimes I have an error which said Uncaught TypeError: Cannot read property 'normal' of undefined

If all you want to do is zoom you can manipulate the Field of View. I did this one up for you. Use “z” down to zoom in and up to zoom back out.

https://playground.babylonjs.com/#RZ7QCR

1 Like

hi @Michael_Prosser Thanks a lot for answering to my question, but I want to zoom to the mouse cursor.

you should not do scene.registerBeforeRender(() => { inside scene.onPointerObservable.add((e) => { or you you will keep adding aboservers for before render. you should do it only once or use scene.onBeforeRenderObservable.addOnce

1 Like

Hi @sebavan

Thanks a lot for answering to my question.

I didn’t understand should I do it like the following code:

    scene.registerBeforeRender(() => {
       scene.onBeforeRenderObservable.addOnce((e) => {
                 let delta = 0.01;
            document.onkeydown = (e) => {

                if (e.key == "w") {
                    delta += 0.1
                }

                if (e.key == "q") {
                    delta -= 0.1
                }
            };
        camera.inputs.attached.mousewheel._zoomToMouse(delta)

        });
    }, BABYLON.PointerEventTypes.POINTERTAP);

but it doesn’t work again.

This will work in the next nightly… https://playground.babylonjs.com/#Q8VH3H#35

but you should create your own controls as using existing ones from _… functions is not guarantee to be back compatible.

3 Likes

Thank you so much :pray: :pray: :pray: