void key_press(unsigned, unsigned, wchar_t);
void key_release(unsigned, unsigned);
+public:
/** Return the focus point, i.e. where the look ray intersects with ground. */
Msp::GL::Vector3 get_focus() const;
const Marklin::Catalogue &get_catalogue() const { return catalogue; }
Marklin::Layout &get_layout() { return *layout; }
Marklin::Layout3D &get_layout_3d() { return *layout_3d; }
- const Msp::GL::Camera &get_camera() const { return camera; }
+ const CameraController &get_camera_controller() const { return camera_ctl; }
const Msp::GLtk::Resources &get_ui_resources() const { return ui_res; }
Msp::GLtk::Root &get_root() { return root; }
return;
}
- float limit = 0.001;
+ float limit = designer.get_layout().get_catalogue().get_gauge()/10;
Track *track1 = tracks.front().track;
Point pos1;
}
const set<Track *> <racks = designer.get_layout().get_tracks();
+ float limit = max(designer.get_layout().get_catalogue().get_gauge(),
+ designer.get_camera_controller().get_view_scale()*5/event_source.get_height());
MTrack *snapped = 0;
for(set<Track *>::const_iterator i=ltracks.begin(); (i!=ltracks.end() && !snapped); ++i)
{
if(!ok) continue;
for(vector<MTrack>::iterator j=tracks.begin(); (j!=tracks.end() && !snapped); ++j)
- if(j->track->snap_to(**i, false))
+ if(j->track->snap_to(**i, false, limit))
snapped = &*j;
}
#include <cmath>
#include "block.h"
+#include "catalogue.h"
#include "driver.h"
#include "layout.h"
#include "track.h"
return rot+ep.dir;
}
-bool Track::snap_to(Track &other, bool link)
+bool Track::snap_to(Track &other, bool link, float limit)
{
- float limit = (link && !flex && !other.get_flex()) ? 1e-6 : 1e-4;
+ if(!limit || link)
+ {
+ limit = layout.get_catalogue().get_gauge();
+ if(link && !flex && !other.get_flex())
+ limit /= 10;
+ }
+ limit *= limit;
+
const vector<TrackType::Endpoint> &eps = type.get_endpoints();
const vector<TrackType::Endpoint> &other_eps = other.get_type().get_endpoints();
float dx = epp2.x-epp.x;
float dy = epp2.y-epp.y;
float dz = epp2.z-epp.z;
- if(dx*dx+dy*dy<limit && dz*dz<4e-4)
+ if(dx*dx+dy*dy<limit && dz*dz<limit)
{
if(!link || (!flex && !other.get_flex()))
{
int get_endpoint_by_link(Track &) const;
Point get_endpoint_position(unsigned) const;
float get_endpoint_direction(unsigned) const;
- bool snap_to(Track &, bool);
+ bool snap_to(Track &, bool, float = 0);
bool snap(Point &, float &) const;
void break_link(Track &);
void break_links();