Esempio n. 1
0
bool rotate_manipulator::handle_mouse_down(visionaray::mouse_event const& event)
{
    auto bdisc = flip( bounding_disc(), camera_.get_viewport() );

    if (bdisc.contains(event.get_pos()) && event.get_buttons() & buttons_)
    {
        dragging_ = true;

        auto brect = flip( bounding_rect(), camera_.get_viewport() );

        ball_.down_pos = ball_.project(
            event.get_pos().x,
            event.get_pos().y,
            brect
            );
        ball_.down_rotation = ball_.rotation;
        down_pos_ = event.get_pos();
//      selected_ = select_from_mouse_pointer(event);

        return true;
    }
    else
    {
        return false;
    }
}
Esempio n. 2
0
void pan_manipulator::handle_mouse_move(visionaray::mouse_event const& event)
{

    if (!dragging_)
    {
        return;
    }


    if (event.get_buttons() & buttons_)
    {

        auto w  =  camera_.get_viewport().w;
        auto h  =  camera_.get_viewport().h;
        auto dx =  static_cast<float>(last_pos_.x - event.get_pos().x) / w;
        auto dy = -static_cast<float>(last_pos_.y - event.get_pos().y) / h;
        auto s  = 2.0f * camera_.distance();
        auto zaxis = normalize( camera_.eye() - camera_.center() );
        auto yaxis = camera_.up();
        auto xaxis = cross( yaxis, zaxis );
        vec3 d  =  (dx * s) * xaxis + (dy * s) * yaxis;
        
        camera_.look_at( camera_.eye() + d, camera_.center() + d, camera_.up() );

        last_pos_ = event.get_pos();

    }

    camera_manipulator::handle_mouse_move(event);

}
Esempio n. 3
0
int rotate_manipulator::select_from_mouse_pointer(visionaray::mouse_event const& event)
{
    auto scaling = get_scaling(model_matrix_);
    auto radius = length((scaling * vec4(size_, 1.0f)).xyz()) / 2.0f;
    vec2i pos(
            event.get_pos().x,
            camera_.get_viewport().h - 1 - event.get_pos().y
            );

    int result = -1;

    for (int i = 0; i < 3; ++i)
    {
        auto modelview = camera_.get_view_matrix() * model_matrix_ * inverse(scaling);

        circle::for_each_line(
            [&](float x1, float y1, float x2, float y2)
            {
                auto v1 = rotate( vec3(0.0f, x1, y1), i );
                auto v2 = rotate( vec3(0.0f, x2, y2), i );

                vec3 win1;
                project(win1, v1, modelview, camera_.get_proj_matrix(), camera_.get_viewport());

                vec3 win2;
                project(win2, v2, modelview, camera_.get_proj_matrix(), camera_.get_viewport());

                auto minx = min(win1.x, win2.x);
                auto maxx = max(win1.x, win2.x);
                auto miny = min(win1.y, win2.y);
                auto maxy = max(win1.y, win2.y);

                minx -= 2;
                miny -= 2;
                maxx += 2;
                maxy += 2;

                recti bounds(
                        static_cast<int>(floor(minx)),
                        static_cast<int>(floor(miny)),
                        static_cast<int>(ceil(abs(maxx - minx))),
                        static_cast<int>(ceil(abs(maxy - miny)))
                        );

                if (bounds.contains(pos))
                {
                    result = i;
                    return;
                }

            },
            radius * ball_.radius
            );
    }

    return result;

}
Esempio n. 4
0
void arcball_manipulator::handle_mouse_move(visionaray::mouse_event const& event)
{

    bool buttons   = event.get_buttons() & buttons_;
    bool modifiers = (modifiers_ == keyboard::NoKey && down_modifiers_ == keyboard::NoKey)
                   || down_modifiers_ & modifiers_;

    if (dragging_ && buttons && modifiers)
    {

        // rotation

        vec3 curr_pos = ball_.project(
                event.get_pos().x,
                event.get_pos().y,
                camera_.get_viewport()
                );
        ball_.rotation = quat::rotation(ball_.down_pos, curr_pos) * ball_.down_rotation;

        if (true)
        {

            // view transform

            mat4 rotation_matrix = rotation(conjugate(ball_.rotation));

            vec4 eye4(0, 0, camera_.distance(), 1.0);
            eye4 = rotation_matrix * eye4;
            vec3 eye = vec3(eye4[0], eye4[1], eye4[2]);
            eye += camera_.center();

            vec4 up4 = rotation_matrix(1);
            vec3 up(up4[0], up4[1], up4[2]);

            camera_.look_at(eye, camera_.center(), up);

        }
        else
        {

            // model transform

            mat4 model = rotation(ball_.rotation);
            VSNRAY_UNUSED(model);
            //camera_.set_model_matrix(model);

        }

    }

    camera_manipulator::handle_mouse_move(event);

}
Esempio n. 5
0
bool rotate_manipulator::handle_mouse_move(visionaray::mouse_event const& event)
{
    auto bdisc = flip( bounding_disc(), camera_.get_viewport() );

    mouse_over_ = bdisc.contains(event.get_pos());

    if (dragging_ && event.get_buttons() & buttons_)
    {
        auto brect = flip( bounding_rect(), camera_.get_viewport() );

        vec3 curr_pos = ball_.project(
                event.get_pos().x,
                event.get_pos().y,
                brect
                );

        auto last_vsr = rotation(ball_.rotation);
        ball_.rotation = quat::rotation(ball_.down_pos, curr_pos) * ball_.down_rotation;

        auto vsr = rotation(ball_.rotation);

        auto trans = model_matrix_(3);

        model_matrix_.col3 = vec4(0.0f, 0.0f, 0.0f, 1.0f);

        auto vm = camera_.get_view_matrix();
        vm.col3 = vec4(0.0f, 0.0f, 0.0f, 1.0f);

        model_matrix_ = inverse(vm) * vsr * inverse(last_vsr) * vm * model_matrix_;
        model_matrix_.col3 = trans;

        return true;
    }
    else
    {
        hovered_ = select_from_mouse_pointer(event);
        return false;
    }
}
Esempio n. 6
0
void pan_manipulator::handle_mouse_down(visionaray::mouse_event const& event)
{

    if (dragging_)
    {
        return;
    }

    dragging_ = true;

    // TODO: do this in base?
    last_pos_ = event.get_pos();

    camera_manipulator::handle_mouse_down(event);

}
Esempio n. 7
0
void arcball_manipulator::handle_mouse_down(visionaray::mouse_event const& event)
{

    bool buttons   = event.get_buttons() & buttons_;
    bool modifiers = (modifiers_ == keyboard::NoKey && event.get_modifiers() == keyboard::NoKey)
                   || event.get_modifiers()  & modifiers_;

    if (!dragging_ && buttons && modifiers)
    {
        dragging_ = true;
        ball_.down_pos = ball_.project(
                event.get_pos().x,
                event.get_pos().y,
                camera_.get_viewport()
                );
        ball_.down_rotation = ball_.rotation;

        down_modifiers_ = event.get_modifiers();
    }

    camera_manipulator::handle_mouse_down(event);

}