]> git.tdb.fi Git - r2c2.git/commitdiff
Make snap limit relative to gauge
authorMikko Rasa <tdb@tdb.fi>
Fri, 5 Nov 2010 21:25:06 +0000 (21:25 +0000)
committerMikko Rasa <tdb@tdb.fi>
Fri, 5 Nov 2010 21:25:06 +0000 (21:25 +0000)
Cap snap limit to 5 pixels when zooming very far out

source/designer/cameracontroller.h
source/designer/designer.h
source/designer/manipulator.cpp
source/libmarklin/track.cpp
source/libmarklin/track.h

index b39b3d5a59a6d0f173e69905888d17c849514510..beed68a483c247f106797cc4e4557c8a9e4e422e 100644 (file)
@@ -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;
 
index 07b34876a06cb4a97486fac32e0160601c9760e1..90d0d3717286cc629cc40d4b48750746fbbd3e8e 100644 (file)
@@ -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; }
 
index e9d6b955f05619e678223200398a8ea8db3b0c85..300802110e295ae0ba090d3ea722c5294546d908 100644 (file)
@@ -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<Track *> &ltracks = 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)
                {
@@ -381,7 +383,7 @@ void Manipulator::pointer_motion(int x, int y)
                        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;
                }
 
index 9b63d5b2c2050cc9f940231bcd6d96c022940001..fbe3f0a709ffe1d2030c37fccee15b78ac134095 100644 (file)
@@ -7,6 +7,7 @@ Distributed under the GPL
 
 #include <cmath>
 #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<TrackType::Endpoint> &eps = type.get_endpoints();
        const vector<TrackType::Endpoint> &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<limit && dz*dz<4e-4)
+                       if(dx*dx+dy*dy<limit && dz*dz<limit)
                        {
                                if(!link || (!flex && !other.get_flex()))
                                {
index e49fe67b5f0e83deebabb378812ef7e19dd59d32..f065cb673e43a030115581d9e2380a1a54db2589 100644 (file)
@@ -79,7 +79,7 @@ public:
        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();