From: Mikko Rasa Date: Fri, 5 Nov 2010 21:25:06 +0000 (+0000) Subject: Make snap limit relative to gauge X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=d6ad508feda1aaa9b2ac2ca2d303c8d28d3094b9;p=r2c2.git Make snap limit relative to gauge Cap snap limit to 5 pixels when zooming very far out --- diff --git a/source/designer/cameracontroller.h b/source/designer/cameracontroller.h index b39b3d5..beed68a 100644 --- a/source/designer/cameracontroller.h +++ b/source/designer/cameracontroller.h @@ -67,6 +67,7 @@ private: 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; diff --git a/source/designer/designer.h b/source/designer/designer.h index 07b3487..90d0d37 100644 --- a/source/designer/designer.h +++ b/source/designer/designer.h @@ -88,7 +88,7 @@ public: 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; } diff --git a/source/designer/manipulator.cpp b/source/designer/manipulator.cpp index e9d6b95..3008021 100644 --- a/source/designer/manipulator.cpp +++ b/source/designer/manipulator.cpp @@ -211,7 +211,7 @@ void Manipulator::connect() return; } - float limit = 0.001; + float limit = designer.get_layout().get_catalogue().get_gauge()/10; Track *track1 = tracks.front().track; Point pos1; @@ -372,6 +372,8 @@ void Manipulator::pointer_motion(int x, int y) } const set <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::const_iterator i=ltracks.begin(); (i!=ltracks.end() && !snapped); ++i) { @@ -381,7 +383,7 @@ void Manipulator::pointer_motion(int x, int y) if(!ok) continue; for(vector::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; } diff --git a/source/libmarklin/track.cpp b/source/libmarklin/track.cpp index 9b63d5b..fbe3f0a 100644 --- a/source/libmarklin/track.cpp +++ b/source/libmarklin/track.cpp @@ -7,6 +7,7 @@ Distributed under the GPL #include #include "block.h" +#include "catalogue.h" #include "driver.h" #include "layout.h" #include "track.h" @@ -194,9 +195,16 @@ float Track::get_endpoint_direction(unsigned epi) const 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 &eps = type.get_endpoints(); const vector &other_eps = other.get_type().get_endpoints(); @@ -213,7 +221,7 @@ bool Track::snap_to(Track &other, bool link) float dx = epp2.x-epp.x; float dy = epp2.y-epp.y; float dz = epp2.z-epp.z; - if(dx*dx+dy*dy