zooming based on the position of cursor in mousewheel

Aasha joney

I am currently working on a THREE.js project.While using trackball control zooming it is zooming relative to the center of the model.But i want to zoom according to the position of cursor with mouse wheel.Any one who is familiar please help me over this. Thank you in advance.

Aasha joney

In mousewheel add this code which helps you in zooming based on the cursor position and not relative to the model.

If you are using trackball controls,you could use that for panning and rotating. So set trackball controls enabled to false in mousewheel.

    renderer.domElement.addEventListener('mousewheel',
           function (e) {
                mousewheel(e);
                        },
           false);


    function mousewheel(event) {
            trackBallControls.noZoom = true;
            event.preventDefault();
            var factor = 50;
            var mX = (event.clientX / jQuery(container).width()) * 2 - 1;
            var mY = -(event.clientY / jQuery(container).height()) * 2 + 1;
            var vector = new THREE.Vector3(mX, mY, 0.5);
            //console.log(vector);
            vector.unproject(camera);
            vector.sub(camera.position);
            if (event.deltaY < 0) {
                camera.position.addVectors(camera.position, 
             vector.setLength(factor));
                trackBallControls.target.addVectors(trackBallControls.target, 
             vector.setLength(factor));
                camera.updateProjectionMatrix();
            } else {
                camera.position.subVectors(camera.position, 
                vector.setLength(factor));
                trackBallControls.target.subVectors(trackBallControls.target, 
                vector.setLength(factor));
                camera.updateProjectionMatrix();
            }
        }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Calculating view offset for zooming in at the position of the mouse cursor

From Dev

zooming on cursor position on a THREE.js object

From Dev

Calculating view offset for zooming in at the position of the mouse cursor

From Dev

Zooming graphics based on current mouse position

From Dev

Zooming of an image using mousewheel.

From Dev

Zooming in Iframe effecting the wrong cursor position in cordova iOS application

From Dev

firefox 42 mousewheel began zooming instead of scrolling

From Dev

THREE.js Limit Zooming in mousewheel event

From Dev

Zooming to Mouse position in LWJGL

From Dev

Background colour based on cursor position, specific colour spectrums

From Dev

Screen Mask based on cursor position on page using Jquery

From Dev

zooming a selected part of image with cursor event

From Dev

mouse position (Cursor.Position)

From Dev

Preserving cursor position with angularjs

From Dev

Position div at cursor location

From Dev

How to position the cursor in AutoCompleteTextView

From Dev

Cursor Position relative to Application

From Dev

Cursor position changed in textview

From Dev

Edit text cursor position

From Dev

Cursor shifted from position

From Dev

Cursor in contenteditable: size and position

From Dev

Retain cursor position in contenteditable

From Dev

Setting cursor position of UITextField

From Dev

Insert element at cursor position

From Dev

Position the cursor to end of line

From Dev

Insert smiley at cursor position

From Dev

Cursor position change in TMemo

From Dev

Word insertFile at cursor position

From Dev

Get vertical cursor position