From 80bcc959131067cc774b85cc1f63e81d8b5a012a Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Sun, 18 Sep 2016 00:52:06 +0300 Subject: [PATCH] did I fix the meshing now? --- src/gear.cc | 11 +++++++++++ src/gear.h | 3 +++ src/machine.cc | 16 +++++++--------- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/gear.cc b/src/gear.cc index 10e8bc8..f6872cf 100644 --- a/src/gear.cc +++ b/src/gear.cc @@ -24,6 +24,17 @@ Gear::~Gear() delete mesh; } +void Gear::set_angular_offset(float offs) +{ + init_angle = offs; + xform_valid = false; +} + +float Gear::get_angular_offset() const +{ + return init_angle; +} + void Gear::set_teeth(int nt, float tooth_pitch) { float circ = tooth_pitch * nt; diff --git a/src/gear.h b/src/gear.h index 45a3d13..e8796e9 100644 --- a/src/gear.h +++ b/src/gear.h @@ -71,6 +71,9 @@ public: Gear(); ~Gear(); + void set_angular_offset(float offs); + float get_angular_offset() const; + // sets the supplied number of teeth, and calculates the radius // of the gear, to achieve the required tooth pitch void set_teeth(int nt, float tooth_pitch); diff --git a/src/machine.cc b/src/machine.cc index 81aa6f6..d6bb338 100644 --- a/src/machine.cc +++ b/src/machine.cc @@ -105,11 +105,14 @@ void Machine::calc_meshing() // fix the initial angles so that teeth mesh as best as possible // should work in one pass as long as the gear train is not impossible for(int i=0; iinit_angle = 0; + float rnd = gears[i]->angle + gears[i]->get_angular_pitch() / 2.0; + float snap = rnd - fmod(rnd, gears[i]->get_angular_pitch()); + gears[i]->set_angle(snap); + gears[i]->set_angular_offset(0); } for(int i=0; iinit_angle += correction * gears[j]->get_angular_pitch(); + float prev_offs = gears[j]->get_angular_offset(); + gears[j]->set_angular_offset(prev_offs + correction * gears[j]->get_angular_pitch()); } } } - - /* - for(int i=0; iinit_angle); - } - */ } void Machine::update_gear(int idx, float angle) -- 1.7.10.4