X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fengineer%2Fcontrolpanel.cpp;h=c2938cd12f92c1adb4e1679f2546ce7bedc8049b;hb=19a73af1fb956636cb8b9d563ffb6a42e827a5bf;hp=07651c07929fdf5f21d8d65f873f5f997c191911;hpb=b8cf5d2f394c151c6b095396dafdc66162cb060e;p=r2c2.git diff --git a/source/engineer/controlpanel.cpp b/source/engineer/controlpanel.cpp index 07651c0..c2938cd 100644 --- a/source/engineer/controlpanel.cpp +++ b/source/engineer/controlpanel.cpp @@ -16,7 +16,8 @@ using namespace R2C2; ControlPanel::ControlPanel(Engineer &e, Train &t): engineer(e), train(t), - updating(false) + updating(false), + placing(false) { Loader::WidgetMap widgets; DataFile::load(*this, "data/controlpanel.ui", widgets); @@ -108,12 +109,27 @@ void ControlPanel::pointer_motion(int x, int y) int ry = y; map_coords_to_ancestor(rx, ry, *find_ancestor()); Ray ray = engineer.get_main_view().create_ray(rx, ry); + Vector ground = ray.get_start()-ray.get_direction()*ray.get_start().z/ray.get_direction().z; Track *track = engineer.get_layout().pick(ray); if(track) { - place_location = TrackIter(track, 0).block_iter(); - if(place_location) + const vector &eps = track->get_block().get_endpoints(); + int closest_ep = -1; + float closest_dist = -1; + for(unsigned i=0; iget_snap_node(eps[i].track_ep); + float d = (sn.position-ground).norm(); + if(d=0) + { + place_location = BlockIter(&track->get_block(), closest_ep); ghosts.back()->place(place_location.track_iter()); for(unsigned i=ghosts.size()-1; i--; ) ghosts[i]->place_before(*ghosts[i+1]);