Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt 5.9 Qt OpenGL Hello GL2 Example Calculate object rotation angle from mouse movement

Qt 5.9 Qt OpenGL Hello GL2 Example Calculate object rotation angle from mouse movement

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 584 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dalishi
    wrote on last edited by
    #1

    In the Qt 5.9 Qt OpenGL Hello GL2 Example, to implement the rotation of the objects, there is a degree normalization function when calculate the rotation from the movement of the mouse. I just don't get it 1) why it needs dx and dy time 8 to get the mouse movement distance? and 2) then 360 times 16 here to normalize the angle, why 16? And 3) when set up the rotation in render by dividing 16? Thanks.

    void GLWidget::mouseMoveEvent(QMouseEvent *event)
    {
        int dx = event->x() - m_lastPos.x();
        int dy = event->y() - m_lastPos.y();
    
        if (event->buttons() & Qt::RightButton) {
            ....
            setZRotation(m_zRot + 8 * dx);
        }
        m_lastPos = event->pos();
    }
    
    static void qNormalizeAngle(int &angle) {
        while (angle < 0)
            angle += 360 * 16;
        while (angle > 360 * 16)
            angle -= 360 * 16;
    }
    
    void GLWidget::setZRotation(int angle)
    {
        qNormalizeAngle(angle);
        if (angle != m_zRot) {
            m_zRot = angle;
            .....
            update();
        }
    }
    
    void GLWidget::paintGL() {
        ....
        m_world.rotate(m_zRot / 16.0f, 0, 0, 1);
        ....
    }
    
    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved