-// arcade controller thing
-// Copyright (c) 2017 Clinton Ebadi <clinton@unknownlamer.org>
-// GPLv3 or (at your option) any later version
-// .. insert license text here ...
-
-use <obiscad/bcube.scad>
-
-$button_d = 28;
-
-module button (bezel = $button_d+4) {
- circle (d=$button_d);
- %circle(d=bezel);
-}
-
-js_width = 40;
-js_height = 85;
-
-module joystick () {
- bolt_d = 8;
- center_hole_d = 24;
-
-
- for (x = [0, js_width], y = [0, js_height]) {
- translate ([x, y, 0]) circle (d=bolt_d); // need slot instead
- }
- translate ([js_width/2, js_height/2, 0]) circle (d=center_hole_d);
-
- %square ([js_width, js_height]); // not right...
-}
-
-panel_w = 250;
-panel_h = 120;
-
-module box_base (x_offset=0, y_offset=0, c=2) { // shitty name
- offset (detal = c, chamfer=true) square ([panel_w+c+x_offset, panel_h+c+y_offset]);
-
-}
-
-box_h = 80;
-box_wall = 2;
-base_h = 5;
-// bcube parameters, clean up
-cr = 2;
-cres = 4;
-
-module betterbox_walls () {
- difference() {
-
- bcube([panel_w, panel_h, box_h-base_h], cr, cres);
- bcube([panel_w-box_wall, panel_h-box_wall, box_h], cr, cres);
- }
-}
-
-module betterbox_base () {
- bcube([panel_w, panel_h, base_h], cr, cres);
-}
-
-
-module betterbox () {
- betterbox_base ();
- translate ([0, 0, (box_h)/2]) betterbox_walls ();
-}
-
-betterbox ();
-
-module box () {
-
- linear_extrude (base_h) {
- box_base ();
- }
- translate ([0, 0, base_h]) linear_extrude (box_h) {
- difference () {
- box_base ();
- translate ([box_wall/2, box_wall/2, 0])
- box_base (x_offset=-box_wall, y_offset=-box_wall);
-
- }
- }
-}
-
-//box ();
-
-
-
-module panel () {
- difference () {
- box_base ();
- translate ([15, panel_h/2-js_height/2, 0]) panel_layout ();
- }
-}
-
-//linear_extrude (6) panel ();
-
-
-
-// panel layout
-
-// http://smg.photobucket.com/user/ttooddddyy/media/neogeoMVS-4-25ver3-cpLayout.jpg.html
-
-module panel_layout () {
- joystick ();
-
- // p1, coin
- %translate ([140-$button_d, $button_d+65, 0]) {
- button ();
- translate ([$button_d+10, 0, 0]) button ();
- }
-
- // a, b, c, d
- translate ([js_width/2+$button_d/2+63.5, js_height/2, 0]) {
- button ();
- for (i = [ 1 : 3 ]) {
- translate ([i*($button_d+10)-5, 30, 0]) button ();
- }
- }
-}
-
-//panel_layout ();
+// arcade controller thing
+// Copyright (c) 2017 Clinton Ebadi <clinton@unknownlamer.org>
+// GPLv3 or (at your option) any later version
+// .. insert license text here ...
+
+use <obiscad/bcube.scad>
+use <obiscad/attach.scad>
+
+// PREVIEW
+union () {
+ rotate ([-10, 0, 0]) translate ([0, 0, box_h+20]) panel ();
+ case ();
+}
+
+
+// CONFIGURATION
+
+panel_w = 250;
+panel_h = 120;
+
+box_h = 80; // fixme: box_d.
+box_wall = 2;
+base_h = 5; //fixme: thickness?
+
+// bcube parameters, clean up
+cr = box_wall*2;
+cres = 0;
+
+$button_d = 28;
+js_width = 85;
+js_height = 40;
+
+// PANEL COMPONENTS
+
+module button (bezel = $button_d+4) {
+ circle (d=$button_d);
+ %circle(d=bezel);
+}
+
+
+module joystick () {
+ bolt_d = 8;
+ center_hole_d = 24;
+
+ for (x = [-js_width/2, js_width/2], y = [-js_height/2, js_height/2]) {
+ translate ([x, y, 0]) circle (d=bolt_d); // need slot instead
+ }
+ circle (d=center_hole_d);
+
+ %square ([js_width, js_height], center=true); // not right...
+}
+
+
+// CASE
+
+module case_base (h=base_h) {
+ bcube([panel_w, panel_h, h], cr, cres);
+}
+
+module case_walls () {
+ difference() {
+ bcube([panel_w, panel_h, box_h-base_h], cr, cres);
+ bcube([panel_w-box_wall, panel_h-box_wall, box_h], cr, cres);
+ }
+}
+
+module case () {
+ case_base ();
+ translate ([0, 0, (box_h)/2]) case_walls ();
+}
+
+
+// PANEL
+
+module panel () {
+ difference () {
+ case_base ();
+ linear_extrude (base_h*2,center=true) panel_layout ();
+ }
+}
+
+module panel_attach (position, angle=0) {
+ x = position[0];
+ y = position[1];
+ c1 = [ [x, y, base_h/2], [0,0,1], angle ]; //[0, 0, h];
+ a1 = [ [0,0, 0], [0,0,0], 0 ];
+// connector (c1);
+ attach (c1, a1) children ();
+}
+
+// panel layout inspired by the Neo Geo layout
+module panel_layout () {
+ translate ([-panel_w/2 + 40, 0, 0]) {
+ panel_attach ([0, 0], 90) joystick ();
+
+ // p1, coin (floating off in the distance...)
+ union () {
+ $button_d=18;
+ for (x = [0, $button_d+10]) {
+ panel_attach ([x, 90]) button ();
+ panel_attach ([x, 90]) button ();
+ }
+ }
+
+ // a, b, c, d
+ union () {
+ buttons_offset = 60;
+ panel_attach ([buttons_offset, 0]) button ();
+ for (i = [ 1 : 3 ]) {
+ panel_attach ([i*($button_d+10)+buttons_offset-5, 30]) button ();
+ }
+ }
+ }
+}