Hierarchical Mouse Events

This is probably a simple question but I have not been able to figure it out.

I want to be able to implement implement a hierarchical processing of mouse events. For instance, I would like to be able to press on the middle mouse button and then and only then rotate the camera around its position.

Can anyone indicate how to achieve this or point towards some example?

Hello,

The usual behavior for dragging with the middle button is to pan the scene. Do you want to change that behavior? What do you mean by “hierarchical”?

best,

Paulo

Thanks Paulo,

I want to be able to change this behavior. As I mentioned, I would like to have certain camera behaviors that are activated only after certain buttons are pressed. For example, I would like to click the middle mouse button and then and only then have mouse movements to change the yaw and pitch of the camera. If I release the middle button or click again, movements of the mouse trigger movements in the camera position… and so on. So how the movement of the mouse is ‘interpreted’ will depend on whether the middle button was pressed or not. Hopefully this clarifies a bit more what I am after.

thanks,

M

Hello,

To achieve that, you likely need to override certain methods of vtkInteractorStyleTrackballCamera class. I do something like you need by setting boolean variables:

void myMouseInteractor::OnLeftButtonDown()
{
    m_isLBdown = true;

    // Forward the event to the superclass.
    vtkInteractorStyleTrackballCamera::OnLeftButtonDown();
}

void myMouseInteractor::OnMouseMove()
{
    if( m_isLBdown )
        m_isDragging = true;

    // Forward the event to the superclass.
    vtkInteractorStyleTrackballCamera::OnMouseMove();
}

void myMouseInteractor::OnLeftButtonUp()
{
    // Don't pick during dragging.
    if( ! m_isDragging ){

        //Remove the marker actor anyway.
        if( m_pickMarkerActor ) {
            this->GetDefaultRenderer()->RemoveActor( m_pickMarkerActor );
            m_pickMarkerActor = nullptr;
        }
        (...)
    }
    m_isLBdown = false;
    m_isDragging = false;
    // Forward the event to the superclass.
    vtkInteractorStyleTrackballCamera::OnLeftButtonUp();
}

In the example above, I don’t want to trigger a pick/probing if the user is just rotating the scene. Notice how I had to customize three mouse events to achive that.

Complete code here: gammaray/v3dmouseinteractor.h at master · PauloCarvalhoRJ/gammaray · GitHub and gammaray/v3dmouseinteractor.cpp at master · PauloCarvalhoRJ/gammaray · GitHub.

regards,

Paulo

Thanks Paulo… this is helpful!