X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Fmachine.cc;h=d6bb33800a03283f6df68190911cb843701d9159;hb=b29d7193d03833109cfdda3ab576fe183efd8acf;hp=913b0b0269405c64c7e3febbe78000f28600ea2b;hpb=014fccdee30291407985658e8cefd9be7dc9e9fa;p=antikythera diff --git a/src/machine.cc b/src/machine.cc index 913b0b0..d6bb338 100644 --- a/src/machine.cc +++ b/src/machine.cc @@ -88,7 +88,7 @@ void Machine::calc_meshing() float inner_rad_sum = outer_rad_sum - gears[i]->teeth_length - gears[j]->teeth_length; if(dsq <= outer_rad_sum * outer_rad_sum && dsq >= inner_rad_sum * inner_rad_sum) { - printf("connecting co-planar gears %d - %d\n", i, j); + //printf("connecting co-planar gears %d - %d\n", i, j); meshing[i][j] = meshing[j][i] = true; } @@ -105,32 +105,31 @@ 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 / gears[i]->get_angular_pitch() + 1.0, 1.0); - float frac_j = fmod((gears[j]->init_angle + rel_angle) / gears[j]->get_angular_pitch() + 1.0, 1.0); + float frac_i = fmod((gears[i]->init_angle + rel_angle) / gears[i]->get_angular_pitch() + 100.0, 1.0); + float frac_j = fmod((gears[j]->init_angle - rel_angle) / gears[j]->get_angular_pitch() + 100.0, 1.0); + assert(frac_i >= 0.0 && frac_j >= 0.0); float delta = frac_j - frac_i; float correction = 0.5 - delta; - gears[j]->init_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)