1

I want to zoom in/out a part in openGL using mouse. Now I can do it well using the scroll button in mouse. But my goal is now to perform the same operation by holding the left mouse button and moving the mouse to and fro in the screen.

I don't know how to perform the zooming action by detecting the to and fro motion of mouse.

// function for mouse scroll events
void VDUI_GLWidget::wheelEvent (QWheelEvent * e) {
    // here comes the code for zoom in / out based on the scrolling
   MouseWheel (e->delta () / float (WHEEL_STEP), QTWheel2VCG (e->modifiers ()));
   updateGL();
}

Now I want to perform the same using mouse move and mouse press events. I'm unable to pick the event which detects the to and fro motion

aadhithyan
  • 49
  • 10
  • 1
    just store your ```x, y``` mouse coordinate on your ```onPressed``` and ```OnReleased``` – Paltoquet Sep 05 '19 at 08:57
  • how it will help me to zoom in/out by storing the x,y values ? Can you explain little bit briefly ? @DraykoonD – aadhithyan Sep 05 '19 at 10:56
  • 1
    I don't know which API you use, or where is stored your virtual camera. But if you have a way to specify a zoom, a transalation in the view direction or else. Maybe you could at each time you move the mouse do a delta with its previous position. And depending on its value apply a zoom ```zoomFactor = length(delta) / zoomRatio``` – Paltoquet Sep 05 '19 at 11:33

1 Answers1

1

Now I have found the solution. Finding the difference between the current & previous Y axis position, I can zoom in / out the Please refer this below mentioned code.

    // function for mouse move events
    void GLWidget::mouseMoveEvent (QMouseEvent * e) {
        static int curY = 0, prevY = 0;
        if (e->buttons()) {
            curY = e->y(); // current position of Y
            if( (curY - prevY) > 0 ) // call zoom in function
            else // call zoom out function
            updateGL();
        }
        prevY = curY;
    }
aadhithyan
  • 49
  • 10