From f6762031dbc15fd891b905f311d053436165d1df Mon Sep 17 00:00:00 2001 From: Bob Date: Sat, 11 Jan 2020 23:32:14 -0500 Subject: [PATCH] front placement now you can put labels on the front of keycaps! --- src/key.scad | 39 ++++++++++++++++++++++++++++++++++----- src/settings.scad | 2 +- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/key.scad b/src/key.scad index ed2eaf2..bedd248 100644 --- a/src/key.scad +++ b/src/key.scad @@ -192,6 +192,25 @@ module top_placement(depth_difference=0) { } } +module front_placement() { + // all this math is to take top skew and tilt into account + // we need to find the new effective height and depth of the top, front lip + // of the keycap to find the angle so we can rotate things correctly into place + total_depth_difference = sin(-$top_tilt) * (top_total_key_height()/2); + total_height_difference = $top_skew + (1 - cos(-$top_tilt)) * (top_total_key_height()/2); + + angle = atan2(($total_depth - total_depth_difference), ($height_difference/2 + total_height_difference)); + hypotenuse = ($total_depth -total_depth_difference) / sin(angle); + + translate([0,-total_key_height()/2,0]) { + rotate([-(90-angle), 0, 0]) { + translate([0,0,hypotenuse/2]){ + children(); + } + } + } +} + // just to DRY up the code module _dish() { dish(top_total_key_width() + $dish_overdraw_width, top_total_key_height() + $dish_overdraw_height, $dish_depth, $inverted_dish); @@ -309,11 +328,21 @@ module clearance_check() { } module legends(depth) { - top_of_key() { - // outset legend - if (len($legends) > 0) { - for (i=[0:len($legends)-1]) { - keytext($legends[i][0], $legends[i][1], $legends[i][2], depth); + if ($front_print_legends) { + front_placement() { + if (len($legends) > 0) { + for (i=[0:len($legends)-1]) { + rotate([90,0,0]) keytext($legends[i][0], $legends[i][1], $legends[i][2], depth); + } + } + } + } else { + top_of_key() { + // outset legend + if (len($legends) > 0) { + for (i=[0:len($legends)-1]) { + keytext($legends[i][0], $legends[i][1], $legends[i][2], depth); + } } } } diff --git a/src/settings.scad b/src/settings.scad index 6858f17..c48a3fc 100644 --- a/src/settings.scad +++ b/src/settings.scad @@ -151,7 +151,7 @@ $legends = []; $outset_legends = false; // how recessed inset legends / artisans are from the top of the key -$inset_legend_depth = 0.3; +$inset_legend_depth = 0.2; // Dimensions of alps stem $alps_stem = [4.45, 2.25];