fe32dffec5276596dd6761cbd9de11e5069b8663
[clinton/3d-models.git] / ble arcade controller / arcade-box.scad
1 // arcade controller thing
2 // Copyright (c) 2017 Clinton Ebadi <clinton@unknownlamer.org>
3 // GPLv3 or (at your option) any later version
4 // .. insert license text here ...
5
6 use <obiscad/bcube.scad>
7 use <obiscad/attach.scad>
8 use <joints.scad>
9
10
11
12 // PREVIEW
13 preview();
14 module preview () {
15 rotate ([-10, 0, 0]) translate ([0, 0, box_h+20]) panel ();
16 case ();
17 }
18
19
20 // CONFIGURATION
21
22 panel_w = 250;
23 panel_h = 120;
24
25 box_h = 80; // fixme: box_d.
26 box_wall = 2;
27 base_h = 5; //fixme: thickness?
28
29 // bcube parameters, clean up
30 cr = box_wall*2;
31 cres = 0;
32
33 $button_d = 30;
34 js_width = 85;
35 js_height = 40;
36
37 hinge_joint_width = 4;
38 hinge_joint_thickness = 5;
39 hinge_base_height = 10;
40
41 // PANEL COMPONENTS
42
43 module button (bezel = $button_d+4) {
44 circle (d=$button_d);
45 %circle(d=bezel);
46 }
47
48
49 module joystick () {
50 bolt_d = 8;
51 center_hole_d = 24;
52
53 for (x = [-js_width/2, js_width/2], y = [-js_height/2, js_height/2]) {
54 translate ([x, y, 0]) circle (d=bolt_d); // need slot instead
55 }
56 circle (d=center_hole_d);
57
58 %square ([js_width, js_height], center=true); // not right...
59 }
60
61
62 // CASE
63
64 module case_base (h=base_h) {
65 bcube([panel_w, panel_h, h], cr, cres);
66 }
67
68 module case_walls () {
69 difference() {
70 bcube([panel_w, panel_h, box_h-base_h], cr, cres);
71 bcube([panel_w-box_wall, panel_h-box_wall, box_h+1], cr, cres);
72 }
73 %connector (case_connector_wall (x=10));
74 attach (case_connector_wall (x=10), hinge_connector_back ()) hinge_female ();
75 }
76
77 module case () {
78 case_base ();
79 translate ([0, 0, box_h/2]) case_walls ();
80 }
81
82
83 // todo:
84 // specify which wall (rear, front, left, right).
85 // offset from center of wall, as vector
86 // optional: inside/outside
87 function case_connector_wall (x=0, y=0, z=0) = [ [panel_w/2-x, panel_h/2-y, (box_h-base_h)/2-z], [0,-1, 0], 0 ];
88
89 // HINGE
90
91 function hinge_connector_back (th=hinge_joint_thickness*2, h=hinge_base_height) = [ [0, th/2, h/2], [0,1, 0], 0 ];
92
93 module hinge_female () {
94 w = hinge_joint_width * 2;
95 th = hinge_joint_thickness * 2;
96 jt = hinge_joint_thickness;
97 jw = hinge_joint_width;
98 h = hinge_base_height;
99
100 %connector (hinge_connector_back ());
101
102 difference () {
103 cube ([w, th, h], center=true);
104 joint_male_negative(male_joint_width=jw, male_joint_thickness=jt, forward_rom=90, backward_rom=90, male_joint_height=10);
105 }
106 }
107
108
109 // PANEL
110
111 module panel () {
112 difference () {
113 case_base ();
114 linear_extrude (base_h*2,center=true) panel_layout ();
115 }
116 }
117
118 module panel_attach (position, angle=0) {
119 x = position[0];
120 y = position[1];
121 c1 = [ [x, y, base_h/2], [0,0,1], angle ];
122 a1 = [ [0,0, 0], [0,0,0], 0 ];
123 // %connector (c1); // fixme: don't use 2d for layout
124 attach (c1, a1) children ();
125 }
126
127 // panel layout inspired by the Neo Geo layout
128 module panel_layout () {
129 translate ([-panel_w/2 + 40, 0, 0]) {
130 panel_attach ([0, 0], 90) joystick ();
131
132 // p1, coin (floating off in the distance...)
133 translate ([160, 0, 0]) {
134 $button_d=16;
135 for (x = [0, $button_d+10]) {
136 panel_attach ([x, 42]) button ();
137 }
138 }
139
140 // a, b, c, d
141 translate ([60, -20, 0]) {
142 panel_attach ([0, 0]) button ();
143 for (i = [ 1 : 3 ]) {
144 panel_attach ([i*($button_d+10)-10, $button_d]) button ();
145 }
146 }
147 }
148 }