move gears along their axis with the mousewheel
authorJohn Tsiombikas <nuclear@mutantstargoat.com>
Sat, 17 Sep 2016 21:58:40 +0000 (00:58 +0300)
committerJohn Tsiombikas <nuclear@mutantstargoat.com>
Sat, 17 Sep 2016 21:58:40 +0000 (00:58 +0300)
src/gear.cc
src/gear.h
src/main.cc

index f6872cf..c916e76 100644 (file)
@@ -48,6 +48,11 @@ void Gear::set_axis(const Vec3 &axis)
        xform_valid = false;
 }
 
+const Vec3 &Gear::get_axis() const
+{
+       return axis;
+}
+
 void Gear::set_position(const Vec3 &pos)
 {
        this->pos = pos;
index e8796e9..7f230e4 100644 (file)
@@ -78,6 +78,7 @@ public:
        // of the gear, to achieve the required tooth pitch
        void set_teeth(int nt, float tooth_pitch);
        void set_axis(const Vec3 &axis);
+       const Vec3 &get_axis() const;
        void set_position(const Vec3 &pos);
        const Vec3 &get_position() const;
        Vec3 get_global_position() const;       // taking parent gear into account
index f98f190..ce8466e 100644 (file)
@@ -215,6 +215,14 @@ static void mouse(int bn, int st, int x, int y)
                        sel_gear = 0;
                }
        }
+
+       if(bidx == 3 || bidx == 4) {    /* wheel */
+               if(hover_gear) {
+                       float dz = bidx == 4 ? 1 : -1;
+                       hover_gear->set_position(hover_gear->get_position() + hover_gear->get_axis() * dz);
+                       machine->invalidate_meshing();
+               }
+       }
 }
 
 static void motion(int x, int y)