From dfd78df0c79d03404d1f2e70c08b643655455725 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 11 Apr 2014 02:06:18 +0300 Subject: [PATCH] Use the endpoint closest to the pointer when placing trains --- source/engineer/controlpanel.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/source/engineer/controlpanel.cpp b/source/engineer/controlpanel.cpp index 0ca2d97..c2938cd 100644 --- a/source/engineer/controlpanel.cpp +++ b/source/engineer/controlpanel.cpp @@ -109,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]); -- 2.43.0