fixed co-planar meshing at arbitrary directions
authorJohn Tsiombikas <nuclear@mutantstargoat.com>
Sat, 17 Sep 2016 20:12:49 +0000 (23:12 +0300)
committerJohn Tsiombikas <nuclear@mutantstargoat.com>
Sat, 17 Sep 2016 20:12:49 +0000 (23:12 +0300)
src/machine.cc

index 913b0b0..81aa6f6 100644 (file)
@@ -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;
                                }
 
@@ -116,8 +116,9 @@ void Machine::calc_meshing()
                                Vec2 dir = normalize(ppos[j].xy() - ppos[i].xy());
                                float rel_angle = atan2(dir.y, dir.x);
 
-                               float frac_i = fmod(gears[i]->init_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;