mirror of
https://github.com/rsheldiii/KeyV2.git
synced 2024-11-26 14:54:21 +00:00
make sideways() transformation
Also make the keytop width changes less dramatic, by centering them around the center of the sides of the keycap. Now instead of choosing the front or back of the keycap and shrinking / expanding the back or front to fit, we shrink / expand both evenly. This actually cleans up the logic too! hooray.
This commit is contained in:
parent
8557d19b02
commit
2172278b72
2893
customizer.scad
2893
customizer.scad
File diff suppressed because it is too large
Load Diff
@ -32,3 +32,11 @@ function top_total_key_height() = $bottom_key_height + ($unit * ($key_height - 1
|
|||||||
function side_tilt(column) = asin($unit * column / $double_sculpt_radius);
|
function side_tilt(column) = asin($unit * column / $double_sculpt_radius);
|
||||||
// tan of 0 is 0, division by 0 is nan, so we have to guard
|
// tan of 0 is 0, division by 0 is nan, so we have to guard
|
||||||
function extra_side_tilt_height(column) = side_tilt(column) ? ($double_sculpt_radius - (unit * abs(column)) / tan(abs(side_tilt(column)))) : 0;
|
function extra_side_tilt_height(column) = side_tilt(column) ? ($double_sculpt_radius - (unit * abs(column)) / tan(abs(side_tilt(column)))) : 0;
|
||||||
|
|
||||||
|
// (I think) extra length of the side of the keycap due to the keytop being tilted.
|
||||||
|
// necessary for calculating flat sided keycaps
|
||||||
|
function vertical_inclination_due_to_top_tilt() = sin($top_tilt) * (top_total_key_height() - $corner_radius * 2) * 0.5;
|
||||||
|
// how much you have to expand the front or back of the keytop to make the side
|
||||||
|
// of the keycap a flat plane. 1 = front, -1 = back
|
||||||
|
// I derived this through a bunch of trig reductions I don't really understand.
|
||||||
|
function extra_keytop_length_for_flat_sides() = ($width_difference * vertical_inclination_due_to_top_tilt()) / ($total_depth);
|
||||||
|
@ -155,3 +155,11 @@ module upside_down() {
|
|||||||
children();
|
children();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module sideways() {
|
||||||
|
$key_shape_type = "flat_sided_square";
|
||||||
|
$dish_overdraw_width = abs(extra_keytop_length_for_flat_sides());
|
||||||
|
extra_y_rotation = atan2($width_difference/2,$total_depth);
|
||||||
|
translate([0,0,cos(extra_y_rotation) * total_key_width()/2])
|
||||||
|
rotate([0,90 + extra_y_rotation ,0]) children();
|
||||||
|
}
|
||||||
|
@ -18,6 +18,9 @@ module key_shape(size, delta, progress = 0) {
|
|||||||
sculpted_square_shape(size, delta, progress);
|
sculpted_square_shape(size, delta, progress);
|
||||||
} else if ($key_shape_type == "rounded_square") {
|
} else if ($key_shape_type == "rounded_square") {
|
||||||
rounded_square_shape(size, delta, progress);
|
rounded_square_shape(size, delta, progress);
|
||||||
|
} else if ($key_shape_type == "flat_sided_square") {
|
||||||
|
// rounded_square_shape handles this
|
||||||
|
rounded_square_shape(size, delta, progress);
|
||||||
} else if ($key_shape_type == "square") {
|
} else if ($key_shape_type == "square") {
|
||||||
square_shape(size, delta, progress);
|
square_shape(size, delta, progress);
|
||||||
} else if ($key_shape_type == "oblong") {
|
} else if ($key_shape_type == "oblong") {
|
||||||
|
@ -1,5 +1,14 @@
|
|||||||
module square_shape_old(size, delta, progress){
|
use <../functions.scad>
|
||||||
square(size - delta * progress, center = true);
|
|
||||||
|
// we do this weird key_shape_type check here because rounded_square uses
|
||||||
|
// square_shape, and we want flat sides to work for that too.
|
||||||
|
// could be refactored, idk
|
||||||
|
module square_shape(size, delta, progress){
|
||||||
|
if ($key_shape_type == "flat_sided_square") {
|
||||||
|
flat_sided_square_shape(size, delta,progress);
|
||||||
|
} else {
|
||||||
|
square(size - delta * progress, center = true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
[-size.x /2,-size.y / 2],
|
[-size.x /2,-size.y / 2],
|
||||||
@ -7,18 +16,15 @@ module square_shape_old(size, delta, progress){
|
|||||||
[size.x / 2, size.y / 2],
|
[size.x / 2, size.y / 2],
|
||||||
[-size.x / 2, size.y / 2] */
|
[-size.x / 2, size.y / 2] */
|
||||||
|
|
||||||
module square_shape(size, delta, progress) {
|
// for side-printed keycaps. Any amount of top tilt (on a keycap with a smaller
|
||||||
// vertical inclination due to top tilt
|
// top than bottom) makes the left and right side of the keycap convex. This
|
||||||
alpha = sin($top_tilt) * (top_total_key_height() - $corner_radius * 2) * 0.5;
|
// shape makes the sides flat by making the top a trapezoid.
|
||||||
|
// This obviously doesn't work with rounded sides at all
|
||||||
// how much we have to tuck in the top and bottom of the keytop to make the sides parallel
|
module flat_sided_square_shape(size, delta, progress) {
|
||||||
gamma = min((($width_difference * alpha) / ($total_depth+alpha)), 0);
|
|
||||||
nega_gamma = max((($width_difference * alpha) / ($total_depth-alpha)), 0);
|
|
||||||
|
|
||||||
polygon(points=[
|
polygon(points=[
|
||||||
[-size.x /2 + delta.x * progress/2 + nega_gamma * progress , -size.y / 2 + delta.y * progress/2],
|
[(-size.x + (delta.x + extra_keytop_length_for_flat_sides()) * progress)/2, (-size.y + delta.y * progress)/2],
|
||||||
[size.x / 2 - delta.x * progress/2 - nega_gamma * progress ,-size.y / 2 + delta.y * progress/2],
|
[(size.x - (delta.x + extra_keytop_length_for_flat_sides()) * progress)/2,(-size.y + delta.y * progress)/2],
|
||||||
[size.x / 2 - delta.x * progress/2 + gamma * progress, size.y / 2 - delta.y * progress/2],
|
[(size.x - (delta.x - extra_keytop_length_for_flat_sides()) * progress)/2, (size.y - delta.y * progress)/2],
|
||||||
[-size.x / 2 + delta.x * progress/2 - gamma * progress, size.y / 2 - delta.y * progress/2]
|
[(-size.x + (delta.x - extra_keytop_length_for_flat_sides()) * progress)/2, (size.y - delta.y * progress)/2]
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user