Guess DistanceSet::get_best_guess(const Point &p1, const Point &p2) const
{
#if DONT_INCLUDE_ZERO_ANSWERS
	Guess g;

	int size = points.size();
	for (int idx1 = 0; idx1 < size; idx1++)
	{
		for (int idx2 = 0; idx2 < size; idx2++)
		{
			if (idx1 == idx2)
			{
				continue;
			}

			Guess another = make_guess(idx1, idx2, p1, p2);
			if (another.is_better_than(g))
			{
				g = another;
			}
		}
	}

	return g;
#else
	int idx1 = get_closest_point(p1);
	int idx2 = get_closest_point(p2);
	return make_guess(idx1, idx2, p1, p2);
#endif
}
static gboolean
egg_piecewise_linear_button_press (GtkWidget *widget, GdkEventButton *event)
{
    EggPiecewiseLinearView
                    *view = EGG_PIECEWISE_LINEAR_VIEW (widget);
    EggPiecewiseLinearViewPrivate
                    *priv = EGG_PIECEWISE_LINEAR_VIEW_GET_PRIVATE (view);
    gdouble          x, y;
    gdouble          distance;
    guint            closest;
    guint            n_points;

    if (event->button != 1)
        return TRUE;

    get_closest_point (widget, event->x, event->y, &x, &y, &closest, &distance);
    n_points = egg_data_points_get_num (priv->points);

    if (!priv->fixed_borders || (closest > 0 && (closest < n_points - 1))) {
        if (distance < 0.1) {
            priv->grabbed   = TRUE;
            priv->dragged_x = egg_data_points_get_x (priv->points, closest);
            priv->dragged_y = egg_data_points_get_y (priv->points, closest);
            priv->dragged_index = closest;

            set_cursor_type (view, GDK_FLEUR);
        }
    }

    return TRUE;
}
void ShapeEditor::mousePressEvent(QMouseEvent *e) {
	
	if (!shape)
		return;
	
	if ( (e->button()==Qt::LeftButton && e->modifiers()&Qt::ControlModifier) || e->button()==Qt::RightButton ) {
		
		int move_idx=get_closest_point( e->pos() );
		if (move_idx>0) { //0 cant be erased
		
			shape->erase_index( move_idx );
			
		}
	} else if (e->button()==Qt::LeftButton) {
		
		int move_idx=get_closest_point( e->pos() );
		
		if (move_idx==-1) {
			
			float val,pos;
			get_shape_pos( e->pos(), &val,&pos);
			
			moving.move_idx=shape->insert( pos, val );
			
		} else {
			
			moving.move_idx=move_idx;
			
		}
	
		update();
		
		shape_changed_signal();
	}
	
}
Example #4
0
void Simulator::mouse_move_event(Mouse_Event const& event)
{
    m_camera_controller.mouse_move_event(event);

    if (event.buttons.test(Mouse_Event::Button::LEFT) &&
            (m_action == Action::MOVE || m_action == Action::ROTATE))
    {
        if (!m_gizmos.started)
        {
            m_gizmos.move.set_override_axis_filter(m_gizmos.move.get_axis_filter());
            m_gizmos.rotate.set_override_axis_filter(m_gizmos.rotate.get_axis_filter());
            m_gizmos.point = m_world->get_uav().get_position();
            m_gizmos.local_base = m_world->get_uav().get_rotation();
            m_gizmos.local_base.get_as_euler_xyz(m_gizmos.rotate_start.x, m_gizmos.rotate_start.y, m_gizmos.rotate_start.z);
            m_world->get_uav().get_body().setAngularVelocity(btVector3(0, 0, 0));
            m_world->get_uav().get_body().clearForces();
            if (m_action == Action::MOVE)
            {
                m_world->get_uav().get_body().setAngularFactor(btVector3(0, 0, 0));
            }
            else if (m_action == Action::ROTATE)
            {
                m_world->get_uav().get_body().setLinearFactor(btVector3(0, 0, 0));
            }
        }

        if (m_action == Action::MOVE)
        {
            math::vec3f filter = m_gizmos.move.get_axis_filter();

            math::line3f ray = m_context.camera.get_ray_from_screen_coordinates(m_camera_controller.get_pointer_2d());
            math::vec3f dir = ray.get_vector_normalized();
            math::vec3f delta;

            {
                math::vec3f normals[2];
                if (filter.x > 0.5f)
                {
                    normals[0] = math::rotate(m_gizmos.local_base, math::vec3f(0, 1, 0));
                    normals[1] = math::rotate(m_gizmos.local_base, math::vec3f(0, 0, 1));
                }
                else if (filter.y > 0.5f)
                {
                    normals[0] = math::rotate(m_gizmos.local_base, math::vec3f(1, 0, 0));
                    normals[1] = math::rotate(m_gizmos.local_base, math::vec3f(0, 0, 1));
                }
                else if (filter.z > 0.5f)
                {
                    normals[0] = math::rotate(m_gizmos.local_base, math::vec3f(1, 0, 0));
                    normals[1] = math::rotate(m_gizmos.local_base, math::vec3f(0, 1, 0));
                }

                math::vec3f line_axis = math::rotate(m_gizmos.local_base, filter) * 1000.0f;
                math::line3f line(m_gizmos.point - line_axis, m_gizmos.point + line_axis);
                math::vec3f point = m_gizmos.point;
                float min_len_sq = FLT_MAX;
                for (size_t i = 0; i < 2; i++)
                {
                    math::planef plane(m_gizmos.point, normals[i]);
                    math::vec3f tmp;
                    if (plane.get_intersection_with_line(ray.start, dir, tmp))
                    {
                        math::vec3f p = line.get_closest_point(tmp);
                        float len_sq = math::distance_sq(tmp,p);
                        if (len_sq < min_len_sq)
                        {
                            min_len_sq = len_sq;
                            point = p;
                        }
                    }
                }
                delta = point - m_gizmos.point;
                m_gizmos.point = point;
            }
            if (m_gizmos.started)
            {
                m_gizmos.delta = delta;
            }

            m_gizmos.started = true;
        }
        else if (m_action == Action::ROTATE)
        {
            auto tangent = m_gizmos.rotate.get_tangent();
            if (!math::equals(tangent.start, tangent.end))
            {
                math::vec2f p = tangent.get_closest_point(m_camera_controller.get_pointer_2d());
                float sign = math::sgn(math::dot(tangent.get_vector_normalized(), p - tangent.get_middle()));
                float dist = 0.005f * sign * math::distance(p, tangent.get_middle());
                auto euler = math::vec3f(dist, dist, dist) * m_gizmos.rotate.get_axis_filter();
                if (euler != m_gizmos.rotate_start)
                {
                    auto delta = euler - m_gizmos.rotate_start;
                    if (m_gizmos.started)
                    {
                        m_gizmos.delta.set(delta.x, delta.y, delta.z);
                    }

                    m_gizmos.started = true;
                    m_gizmos.rotate_start = euler;
                }
            }
        }

    }
}
Example #5
0
static void print_closest_point(ego* faces, int i, std::array<double, 3> pt) {
  auto face = faces[i - 1];
  auto closest = get_closest_point(face, pt);
  printf("closest point to %f %f %f on face %d is %f %f %f\n", pt[0], pt[1],
      pt[2], i, closest[0], closest[1], closest[2]);
}
static gboolean
egg_piecewise_linear_motion_notify (GtkWidget *widget, GdkEventMotion *event)
{
    EggPiecewiseLinearViewPrivate
                    *priv = EGG_PIECEWISE_LINEAR_VIEW_GET_PRIVATE (widget);
    GdkCursorType    cursor_type = GDK_TCROSS;
    gdouble          x, y;
    guint            n_points;
    gdouble          distance;
    guint            closest;
    gboolean         set_x, set_y;

    get_closest_point (widget, event->x, event->y, &x, &y, &closest, &distance);
    n_points = egg_data_points_get_num (priv->points);

    if (!priv->grabbed) {
        if (!priv->fixed_borders || (closest > 0 && closest < n_points - 1)) {
            if (distance < 0.1)
                cursor_type = GDK_FLEUR;
        }
    }
    else {
        set_x = !priv->fixed_x;
        set_y = !priv->fixed_y;

        if (priv->restrict_x) {
            if (priv->dragged_index > 0) {
                gdouble lower_x;
                lower_x = egg_data_points_get_x_value (priv->points, priv->dragged_index - 1);
                set_x = set_x && (x >= lower_x);
            }

            if (priv->dragged_index < n_points - 1) {
                gdouble upper_x;
                upper_x = egg_data_points_get_x_value (priv->points, priv->dragged_index + 1);
                set_x = set_x && (x <= upper_x);
            }
        }

        if (priv->restrict_y) {
            if (priv->dragged_index > 0) {
                gdouble lower_y;
                lower_y = egg_data_points_get_y_value (priv->points, priv->dragged_index - 1);
                set_y = set_y && (y >= lower_y);
            }

            if (priv->dragged_index < n_points - 1) {
                gdouble upper_y;
                upper_y = egg_data_points_get_y_value (priv->points, priv->dragged_index + 1);
                set_y = set_y && (y <= upper_y);
            }
        }

        if (set_x)
            gtk_adjustment_set_value (priv->dragged_x, x);

        if (set_y)
            gtk_adjustment_set_value (priv->dragged_y, y);

        cursor_type = GDK_FLEUR;
        gtk_widget_queue_draw (widget);
    }

    set_cursor_type (EGG_PIECEWISE_LINEAR_VIEW (widget), cursor_type);
    return TRUE;
}