Commit eec89793 authored by Davis King's avatar Davis King

Made the perspective display resort the points with the proper z order

whenever you release the mouse button or add more points.
parent 53e825d3
......@@ -5722,12 +5722,15 @@ namespace dlib
max_pts.z() = std::max(overlay[i].p2.z(), max_pts.z());
}
dot_sorting_is_stale = true;
tform = camera_transform(max_pts,
sum_pts/(overlay_lines.size()*2+overlay_dots.size()),
vector<double>(0,0,1),
tform.get_camera_field_of_view(),
std::min(rect.width(),rect.height()));
sort_dots();
// make the parent window redraw us now that we changed the overlay
parent.invalidate_rectangle(rect);
}
......@@ -5743,17 +5746,17 @@ namespace dlib
if (overlay.size() == 0)
return;
// push this new overlay into our overlay vector
overlay_dots.insert(overlay_dots.end(), overlay.begin(), overlay.end());
for (unsigned long i = 0; i < overlay.size(); ++i)
{
overlay_dots.push_back(std::make_pair(overlay[i], 0));
sum_pts += overlay[i].p;
max_pts.x() = std::max(overlay[i].p.x(), max_pts.x());
max_pts.y() = std::max(overlay[i].p.y(), max_pts.y());
max_pts.z() = std::max(overlay[i].p.z(), max_pts.z());
}
dot_sorting_is_stale = true;
tform = camera_transform(max_pts,
sum_pts/(overlay_lines.size()*2+overlay_dots.size()),
vector<double>(0,0,1),
......@@ -5811,9 +5814,9 @@ namespace dlib
}
for (unsigned long i = 0; i < overlay_dots.size(); ++i)
{
point p = tform(overlay_dots[i].p) + rect.tl_corner();
point p = tform(overlay_dots[i].first.p) + rect.tl_corner();
if (area.contains(p))
assign_pixel(c[p.y()-c.top()][p.x()-c.left()], overlay_dots[i].color);
assign_pixel(c[p.y()-c.top()][p.x()-c.left()], overlay_dots[i].first.color);
}
}
......@@ -5882,7 +5885,7 @@ namespace dlib
const dpoint pp(x,y);
for (unsigned long i = 0; i < overlay_dots.size(); ++i)
{
dpoint p = tform(overlay_dots[i].p) + rect.tl_corner();
dpoint p = tform(overlay_dots[i].first.p) + rect.tl_corner();
double dist = length_squared(p-pp);
if (dist < best_dist)
{
......@@ -5891,7 +5894,43 @@ namespace dlib
}
}
if (dot_clicked_event_handler.is_set())
dot_clicked_event_handler(overlay_dots[best_idx].p);
dot_clicked_event_handler(overlay_dots[best_idx].first.p);
}
}
// ----------------------------------------------------------------------------------------
void perspective_display::
sort_dots (
)
{
if (dot_sorting_is_stale)
{
// sort the dots so that the dots farthest from the camera are drawn first.
// We begin by updating the distance from each dot to the camera.
const vector<double> cam = tform.get_camera_pos();
for (unsigned long i = 0; i < overlay_dots.size(); ++i)
overlay_dots[i].second = length_squared(overlay_dots[i].first.p-cam);
std::sort(overlay_dots.rbegin(), overlay_dots.rend(), compare_second);
dot_sorting_is_stale = false;
parent.invalidate_rectangle(rect);
}
}
// ----------------------------------------------------------------------------------------
void perspective_display::
on_mouse_up (
unsigned long,// btn,
unsigned long,// state,
long,// x,
long// y
)
{
if (!hidden && enabled && overlay_dots.size() != 0)
{
sort_dots();
}
}
......@@ -5922,6 +5961,7 @@ namespace dlib
// now make it have the correct radius relative to the looking at point.
new_pos = (new_pos-tform.get_camera_looking_at()).normalize()*length(radius) + tform.get_camera_looking_at();
dot_sorting_is_stale = true;
tform = camera_transform(new_pos,
tform.get_camera_looking_at(),
tangent_y,
......@@ -5944,6 +5984,7 @@ namespace dlib
vector<double> offset = tangent_x*delta.x() + tangent_y*-delta.y();
dot_sorting_is_stale = true;
tform = camera_transform(
tform.get_camera_pos()+offset,
tform.get_camera_looking_at()+offset,
......
......@@ -3706,20 +3706,35 @@ namespace dlib
bool is_double_click
);
void on_mouse_up (
unsigned long btn,
unsigned long state,
long x,
long y
);
void on_mouse_move (
unsigned long state,
long x,
long y
);
static bool compare_second (
const std::pair<overlay_dot,float>& a,
const std::pair<overlay_dot,float>& b
) { return a.second < b.second; }
void sort_dots();
point last;
std::vector<overlay_line> overlay_lines;
std::vector<overlay_dot> overlay_dots;
std::vector<std::pair<overlay_dot,float> > overlay_dots;
camera_transform tform;
vector<double> sum_pts;
vector<double> max_pts;
any_function<void(const vector<double>&)> dot_clicked_event_handler;
bool dot_sorting_is_stale;
};
// ----------------------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment