int ry = y;
map_coords_to_ancestor(rx, ry, *find_ancestor<GLtk::Root>());
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<Track>(ray);
if(track)
{
- place_location = TrackIter(track, 0).block_iter();
- if(place_location)
+ const vector<Block::Endpoint> &eps = track->get_block().get_endpoints();
+ int closest_ep = -1;
+ float closest_dist = -1;
+ for(unsigned i=0; i<eps.size(); ++i)
{
+ Snap sn = eps[i].track->get_snap_node(eps[i].track_ep);
+ float d = (sn.position-ground).norm();
+ if(d<closest_dist || closest_dist<0)
+ {
+ closest_ep = i;
+ closest_dist = d;
+ }
+ }
+
+ if(closest_ep>=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]);