| 1 | //---------------------------------------------------------------------------------------------------------------------------------- |
| 2 | xyz mMax, mCtr, mHalf; |
| 3 | int NumApcRows = 5, NumApcCols = 8; |
| 4 | |
| 5 | boolean btwn (int a,int b,int c) { return a >= b && a <= c; } |
| 6 | boolean btwn (double a,double b,double c) { return a >= b && a <= c; } |
| 7 | float interp (float a, float b, float c) { return (1-a)*b + a*c; } |
| 8 | float randctr (float a) { return random(a) - a*.5; } |
| 9 | float min (float a, float b, float c, float d) { return min(min(a,b),min(c,d)); } |
| 10 | float pointDist(Point p1, Point p2) { return dist(p1.x,p1.y,p1.z,p2.x,p2.y,p2.z); } |
| 11 | float distToSeg(float x, float y, float x1, float y1, float x2, float y2) { |
| 12 | float A = x - x1, B = y - y1, C = x2 - x1, D = y2 - y1; |
| 13 | float dot = A * C + B * D, len_sq = C * C + D * D; |
| 14 | float xx, yy,param = dot / len_sq; |
| 15 | |
| 16 | if (param < 0 || (x1 == x2 && y1 == y2)) { xx = x1; yy = y1; } |
| 17 | else if (param > 1) { xx = x2; yy = y2; } |
| 18 | else { xx = x1 + param * C; |
| 19 | yy = y1 + param * D; } |
| 20 | float dx = x - xx, dy = y - yy; |
| 21 | return sqrt(dx * dx + dy * dy); |
| 22 | } |
| 23 | |
| 24 | |
| 25 | public class Pick { |
| 26 | int NumPicks, Default , CurRow , CurCol , |
| 27 | StartRow, EndRow ; |
| 28 | String tag , Desc[] ; |
| 29 | |
| 30 | Pick (String label, int _Def, int _Num, int nStart, String d[]) { |
| 31 | NumPicks = _Num; Default = _Def; |
| 32 | StartRow = nStart; EndRow = StartRow + floor((NumPicks-1) / NumApcCols); |
| 33 | tag = label; Desc = d; |
| 34 | reset(); |
| 35 | } |
| 36 | |
| 37 | int Cur() { return (CurRow-StartRow)*NumApcCols + CurCol; } |
| 38 | String CurDesc() { return Desc[Cur()]; } |
| 39 | void reset() { CurCol = Default % NumApcCols; CurRow = StartRow + Default / NumApcCols; } |
| 40 | |
| 41 | boolean set(int r, int c) { |
| 42 | if (!btwn(r,StartRow,EndRow) || !btwn(c,0,NumApcCols-1) || |
| 43 | !btwn((r-StartRow)*NumApcCols + c,0,NumPicks-1)) return false; |
| 44 | CurRow=r; CurCol=c; return true; |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | public class DBool { |
| 49 | boolean def, b; |
| 50 | String tag; |
| 51 | int row, col; |
| 52 | void reset() { b = def; } |
| 53 | boolean set (int r, int c, boolean val) { if (r != row || c != col) return false; b = val; return true; } |
| 54 | DBool(String _tag, boolean _def, int _row, int _col) { |
| 55 | def = _def; b = _def; tag = _tag; row = _row; col = _col; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | public class DParam extends BasicParameter { |
| 60 | double dflt; |
| 61 | DParam (String label, double value) { super(label,value); dflt=value; } |
| 62 | void set (double value) { super.setValue(value); } |
| 63 | void reset () { super.setValue(dflt); } |
| 64 | float Val () { return getValuef(); } |
| 65 | } |
| 66 | //---------------------------------------------------------------------------------------------------------------------------------- |
| 67 | public class xyz { float x,y,z; // extends pVector; eliminate half of the functions |
| 68 | xyz() {x=y=z=0;} |
| 69 | xyz(Point p ) {x=p.x ; y=p.y; z=p.z;} |
| 70 | xyz(xyz p ) {set(p); } |
| 71 | xyz(float _x,float _y,float _z) {x=_x ; y=_y ; z=_z ;} |
| 72 | void set(Point p ) {x=p.x ; y=p.y; z=p.z;} |
| 73 | void set(xyz p ) {x=p.x ; y=p.y ; z=p.z ;} |
| 74 | void set(float _x,float _y,float _z) {x=_x ; y=_y ; z=_z ;} |
| 75 | |
| 76 | void zoomX (float zx) {x = x*zx - mMax.x*(zx-1)/2; } |
| 77 | void zoomY (float zy) {y = y*zy - mMax.y*(zy-1)/2; } |
| 78 | |
| 79 | float distance(xyz b) {return dist(x,y,z,b.x,b.y,b.z); } |
| 80 | float distance(float _x, float _y) {return dist(x,y,_x,_y); } |
| 81 | float dot (xyz b) {return x*b.x + y*b.y + z*b.z; } |
| 82 | void add (xyz b) {x += b.x; y += b.y; z += b.z; } |
| 83 | void add (float b) {x += b ; y += b ; z += b ; } |
| 84 | void subtract(xyz b) {x -= b.x; y -= b.y; z -= b.z; } |
| 85 | void scale (float b) {x *= b ; y *= b ; z *= b ; } |
| 86 | |
| 87 | void RotateZ (xyz o, float nSin, float nCos) { |
| 88 | float nX = nCos*(x-o.x) - nSin*(y-o.y) + o.x; |
| 89 | float nY = nSin*(x-o.x) + nCos*(y-o.y) + o.y; |
| 90 | x = nX; y = nY; |
| 91 | } |
| 92 | |
| 93 | void RotateX (xyz o, float nSin, float nCos) { |
| 94 | float nY = nCos*(y-o.y) - nSin*(z-o.z) + o.y; |
| 95 | float nZ = nSin*(y-o.y) + nCos*(z-o.z) + o.z; |
| 96 | y = nY; z = nZ; |
| 97 | } |
| 98 | |
| 99 | void RotateY (xyz o, float nSin, float nCos) { |
| 100 | float nZ = nCos*(z-o.z) - nSin*(x-o.x) + o.z; |
| 101 | float nX = nSin*(z-o.z) + nCos*(x-o.x) + o.x; |
| 102 | z = nZ; x = nX; |
| 103 | } |
| 104 | |
| 105 | void setRand () { x = random(mMax.x); y = random(mMax.y); z = random(mMax.z); } |
| 106 | void setNorm () { x /= mMax.x; y /= mMax.y; z /= mMax.z; } |
| 107 | void interpolate(float i, xyz d) { x = interp(i,x,d.x); y = interp(i,y,d.y); z = interp(i,z,d.z); } |
| 108 | } |
| 109 | //---------------------------------------------------------------------------------------------------------------------------------- |
| 110 | public class DPat extends SCPattern |
| 111 | { |
| 112 | MidiOutput APCOut = null; |
| 113 | |
| 114 | boolean noteOff(Note note) { if (!isFocused()) return false; |
| 115 | int row = note.getPitch(), col = note.getChannel(); |
| 116 | for (int i=0; i<bools.size(); i++) if (bools.get(i).set(row, col, false)) return true; |
| 117 | UpdateLights(); |
| 118 | return false; |
| 119 | } |
| 120 | |
| 121 | boolean noteOn(Note note) { if (!isFocused()) return false; |
| 122 | int row = note.getPitch(), col = note.getChannel(); |
| 123 | for (int i=0; i<picks.size(); i++) if (picks.get(i).set(row, col)) return true; |
| 124 | for (int i=0; i<bools.size(); i++) if (bools.get(i).set(row, col, true)) return true; |
| 125 | if (row == 84 && col==0) { onActive(); StartPattern(); return true; } |
| 126 | println("row: " + row + " col: " + col); return false; |
| 127 | } |
| 128 | |
| 129 | void SetNoteOn (int row, int col, int clr){ if (APCOut != null) APCOut.sendNoteOn (col, row, clr); } |
| 130 | void SetNoteOff (int row, int col, int clr){ if (APCOut != null) APCOut.sendNoteOff (col, row, clr); } |
| 131 | |
| 132 | boolean isFocused() { return midiEngine != null && midiEngine.getFocusedDeck() != null && |
| 133 | this == midiEngine.getFocusedDeck().getActivePattern(); } |
| 134 | void onInactive() { uiDebugText.setText(""); } |
| 135 | void onActive () { |
| 136 | while (lx.tempo.bpm() > 40) lx.tempo.setBpm(lx.tempo.bpm()/2); |
| 137 | for (int i=0; i<params.size(); i++) params.get(i).reset(); |
| 138 | for (int i=0; i<bools .size(); i++) bools.get(i).reset(); |
| 139 | for (int i=0; i<picks .size(); i++) picks.get(i).reset(); |
| 140 | UpdateLights(); |
| 141 | } |
| 142 | |
| 143 | void UpdateLights() { |
| 144 | if (!isFocused() || APCOut == null) return; |
| 145 | for (int i=53;i< 58; i++) for (int j=0; j<NumApcCols; j++) SetNoteOn(i, j, 0); |
| 146 | for (int i=0; i<picks .size(); i++) SetNoteOn (picks.get(i).CurRow, picks.get(i).CurCol, 3); |
| 147 | for (int i=0; i<bools .size(); i++) if (bools.get(i).b) SetNoteOn (bools.get(i).row, bools.get(i).col, 1); |
| 148 | else SetNoteOff (bools.get(i).row, bools.get(i).col, 0); |
| 149 | } |
| 150 | |
| 151 | void SetText() { if (!isFocused()) return; |
| 152 | String Text1="", Text2=""; |
| 153 | for (int i=0; i<bools.size(); i++) if (bools.get(i).b) Text1 += " " + bools.get(i).tag + " "; |
| 154 | for (int i=0; i<picks.size(); i++) Text1 += picks.get(i).tag + ": " + picks.get(i).CurDesc() + " "; |
| 155 | uiDebugText.setText(Text1, Text2); |
| 156 | } |
| 157 | |
| 158 | ArrayList<Pick> picks = new ArrayList<Pick> (); |
| 159 | ArrayList<DBool> bools = new ArrayList<DBool> (); |
| 160 | ArrayList<DParam> params = new ArrayList<DParam>(); |
| 161 | |
| 162 | int nMaxRow = 53; |
| 163 | float LastQuant = -1, LastJog = -1; |
| 164 | float[] xWaveNz, yWaveNz; |
| 165 | int nPoint , nPoints; |
| 166 | xyz xyzJog = new xyz(), vT1 = new xyz(), vT2 = new xyz(); |
| 167 | xyz modmin; |
| 168 | |
| 169 | float NoiseMove = random(10000); |
| 170 | DParam pSpark, pWave, pRotX, pRotY, pRotZ, pSpin, pTransX, pTransY; |
| 171 | |
| 172 | DBool pXsym, pYsym, pRsym, pXdup, pXtrip, pJog, pGrey; |
| 173 | float lxh () { return lx.getBaseHuef(); } |
| 174 | float Dist (xyz a, xyz b) { return dist(a.x,a.y,a.z,b.x,b.y,b.z); } |
| 175 | int c1c (float a) { return round(100*constrain(a,0,1)); } |
| 176 | float interpWv(float i, float[] vals) { return interp(i-floor(i), vals[floor(i)], vals[ceil(i)]); } |
| 177 | |
| 178 | float CalcCone (xyz v1, xyz v2, xyz c) { vT1.set(v1); vT2.set(v2); vT1.subtract(c); vT2.subtract(c); |
| 179 | return degrees( acos ( vT1.dot(vT2) / (sqrt(vT1.dot(vT1)) * sqrt(vT2.dot(vT2)) ) )); } |
| 180 | |
| 181 | void StartPattern() { } |
| 182 | void StartRun(double deltaMs) { } |
| 183 | color CalcPoint(xyz p) { return lx.hsb(0,0,0); } |
| 184 | color blend3(color c1, color c2, color c3){ return blendColor(c1,blendColor(c2,c3,ADD),ADD); } |
| 185 | |
| 186 | DParam addParam(String label, double value) { |
| 187 | DParam P = new DParam(label, value); |
| 188 | super.addParameter(P); |
| 189 | params.add(P); return P; |
| 190 | } |
| 191 | |
| 192 | Pick addPick(String name, int def, int _max, String[] desc) { |
| 193 | Pick P = new Pick(name, def, _max+1, nMaxRow, desc); |
| 194 | nMaxRow = P.EndRow + 1; |
| 195 | picks.add(P); |
| 196 | return P; |
| 197 | } |
| 198 | |
| 199 | DPat(GLucose glucose) { |
| 200 | super(glucose); |
| 201 | |
| 202 | pSpark = addParam("Sprk", 0); |
| 203 | pWave = addParam("Wave", 0); |
| 204 | pTransX = addParam("TrnX", .5); |
| 205 | pTransY = addParam("TrnY", .5); |
| 206 | pRotX = addParam("RotX", .5); |
| 207 | pRotY = addParam("RotY", .5); |
| 208 | pRotZ = addParam("RotZ", .5); |
| 209 | pSpin = addParam("Spin", .5); |
| 210 | |
| 211 | nPoints = model.points.size(); |
| 212 | pXsym = new DBool("X-SYM", false, 48, 0); bools.add(pXsym ); |
| 213 | pYsym = new DBool("Y-SYM", false, 48, 1); bools.add(pYsym ); |
| 214 | pRsym = new DBool("R-SYM", false, 48, 2); bools.add(pRsym ); |
| 215 | pXdup = new DBool("X-DUP", false, 48, 3); bools.add(pXdup ); |
| 216 | pJog = new DBool("JOG" , false, 48, 4); bools.add(pJog ); |
| 217 | pGrey = new DBool("GREY" , false, 48, 5); bools.add(pGrey ); |
| 218 | |
| 219 | modmin = new xyz(model.xMin, model.yMin, model.zMin); |
| 220 | mMax = new xyz(model.xMax, model.yMax, model.zMax); mMax.subtract(modmin); |
| 221 | mCtr = new xyz(mMax); mCtr.scale(.5); |
| 222 | mHalf = new xyz(.5,.5,.5); |
| 223 | xWaveNz = new float[ceil(mMax.y)+1]; |
| 224 | yWaveNz = new float[ceil(mMax.x)+1]; |
| 225 | |
| 226 | //println (model.xMin + " " + model.yMin + " " + model.zMin); |
| 227 | //println (model.xMax + " " + model.yMax + " " + model.zMax); |
| 228 | for (MidiOutputDevice o: RWMidi.getOutputDevices()) { if (o.toString().contains("APC")) { APCOut = o.createOutput(); break;}} |
| 229 | } |
| 230 | |
| 231 | void run(double deltaMs) |
| 232 | { |
| 233 | if (deltaMs > 100) return; |
| 234 | NoiseMove += deltaMs; NoiseMove = NoiseMove % 1e7; |
| 235 | StartRun (deltaMs); |
| 236 | xyz P = new xyz(), tP = new xyz(), pSave = new xyz(); |
| 237 | xyz pTrans = new xyz(pTransX.Val()*200-100, pTransY.Val()*100-50,0); |
| 238 | |
| 239 | SetText(); |
| 240 | nPoint = 0; |
| 241 | |
| 242 | if (pJog.b) { |
| 243 | float tRamp = (lx.tempo.rampf() % .25); |
| 244 | if (tRamp < LastJog) xyzJog.set(randctr(mMax.x*.2), randctr(mMax.y*.2), randctr(mMax.z*.2)); |
| 245 | LastJog = tRamp; |
| 246 | } |
| 247 | |
| 248 | // precalculate this stuff |
| 249 | float wvAmp = pWave.Val(), sprk = pSpark.Val(); |
| 250 | if (wvAmp > 0) { |
| 251 | for (int i=0; i<ceil(mMax.x)+1; i++) |
| 252 | yWaveNz[i] = wvAmp * (noise(i/(mMax.x*.3)-(2e3+NoiseMove)/1500.) - .5) * (mMax.y/2.); |
| 253 | |
| 254 | for (int i=0; i<ceil(mMax.y)+1; i++) |
| 255 | xWaveNz[i] = wvAmp * (noise(i/(mMax.y*.3)-(1e3+NoiseMove)/1500.) - .5) * (mMax.x/2.); |
| 256 | } |
| 257 | |
| 258 | for (Point p : model.points) { nPoint++; |
| 259 | P.set(p); |
| 260 | P.subtract(modmin); |
| 261 | P.subtract(pTrans); |
| 262 | if (sprk > 0) {P.y += sprk*randctr(50); P.x += sprk*randctr(50); P.z += sprk*randctr(50); } |
| 263 | if (wvAmp > 0) P.y += interpWv(p.x-modmin.x, yWaveNz); |
| 264 | if (wvAmp > 0) P.x += interpWv(p.y-modmin.y, xWaveNz); |
| 265 | if (pJog.b) P.add(xyzJog); |
| 266 | |
| 267 | |
| 268 | color cNew, cOld = colors[p.index]; |
| 269 | { tP.set(P); cNew = CalcPoint(tP); } |
| 270 | if (pXsym.b) { tP.set(mMax.x-P.x,P.y,P.z); cNew = blendColor(cNew, CalcPoint(tP), ADD); } |
| 271 | if (pYsym.b) { tP.set(P.x,mMax.y-P.y,P.z); cNew = blendColor(cNew, CalcPoint(tP), ADD); } |
| 272 | if (pRsym.b) { tP.set(mMax.x-P.x,mMax.y-P.y,mMax.z-P.z); cNew = blendColor(cNew, CalcPoint(tP), ADD); } |
| 273 | if (pXdup.b) { tP.set((P.x+mMax.x*.5)%mMax.x,P.y,P.z); cNew = blendColor(cNew, CalcPoint(tP), ADD); } |
| 274 | if (pGrey.b) { cNew = lx.hsb(0, 0, lx.b(cNew)); } |
| 275 | colors[p.index] = cNew; |
| 276 | } |
| 277 | } |
| 278 | } |
| 279 | //---------------------------------------------------------------------------------------------------------------------------------- |
| 280 | class dTurn { |
| 281 | dVertex v; |
| 282 | int pos0, pos1; |
| 283 | dTurn(int _pos0, dVertex _v, int _pos1) { v = _v; pos0 = _pos0; pos1 = _pos1; } |
| 284 | } |
| 285 | |
| 286 | class dVertex { |
| 287 | dVertex c0, c1, // connections on the cube |
| 288 | opp, same; // opp - same strip, opp direction |
| 289 | // same - same strut, diff strip, dir |
| 290 | dTurn t0, t1; |
| 291 | dStrip s; |
| 292 | int dir, ci; // dir -- 1 or -1. |
| 293 | // ci -- color index |
| 294 | |
| 295 | dVertex(dStrip _s, Point _p) { s = _s; ci = _p.index; } |
| 296 | Point getPoint(int i) { return s.s.points.get(dir>0 ? i : 15-i); } |
| 297 | void setOpp(dVertex _opp) { opp = _opp; dir = (ci < opp.ci ? 1 : -1); } |
| 298 | } |
| 299 | |
| 300 | class dStrip { |
| 301 | dVertex v0, v1; |
| 302 | int row, col; |
| 303 | Strip s; |
| 304 | String desc() { return "r:" + row + " c:" + col + "i:" + floor(v0.ci/16); } |
| 305 | dStrip(Strip _s, int _i, int _row, int _col) { s = _s; row = _row; col = _col; } |
| 306 | } |
| 307 | //---------------------------------------------------------------------------------------------------------------------------------- |
| 308 | class dPixel { dVertex v; int pos; dPixel(dVertex _v, int _pos) { v=_v; pos=_pos; } } |
| 309 | class dLattice { |
| 310 | private int iTowerStrips=0; |
| 311 | |
| 312 | dStrip[] DS = new dStrip[glucose.model.strips.size()]; |
| 313 | //int[][] DQ = new int[NumBackTowers][MaxCubeHeight*2]; |
| 314 | //dStrip GetStrip (int row, int col, int off) { |
| 315 | // return (!btwn(off,0,15) || !btwn(row,0,MaxCubeHeight*2-1) || !btwn(col,0,NumBackTowers-1) || DQ[col][row]<0) ? null : |
| 316 | // DS[DQ[col][row]+off]; |
| 317 | //} |
| 318 | |
| 319 | void addTurn(dVertex v0, int pos0, dVertex v1, int pos1) { dTurn t = new dTurn(pos0, v1, pos1); if (v0.t0 == null) v0.t0=t; else v0.t1=t; } |
| 320 | float dist2 (Strip s1, int pos1, Strip s2, int pos2) { return pointDist(s1.points.get(pos1), s2.points.get(pos2)); } |
| 321 | float pd2 (Point p1, float x, float y, float z) { return dist(p1.x,p1.y,p1.z,x,y,z); } |
| 322 | boolean sameSame (Strip s1, Strip s2) { return max(dist2(s1, 0, s2, 0), dist2(s1,15, s2,15)) < 5 ; } // same strut, same direction |
| 323 | boolean sameOpp (Strip s1, Strip s2) { return max(dist2(s1, 0, s2,15), dist2(s1,15, s2,0 )) < 5 ; } // same strut, opp direction |
| 324 | boolean sameBar (Strip s1, Strip s2) { return sameSame(s1,s2) || sameOpp(s1,s2); } // 2 strips on same strut |
| 325 | void addJoint (dVertex v1, dVertex v2) { |
| 326 | // should probably replace parallel but further with the new one |
| 327 | if (v1.c0 != null && sameBar(v2.s.s, v1.c0.s.s)) return; |
| 328 | if (v1.c1 != null && sameBar(v2.s.s, v1.c1.s.s)) return; |
| 329 | if (v1.c0 == null) v1.c0 = v2; |
| 330 | else if (v1.c1 == null) v1.c1 = v2; |
| 331 | } |
| 332 | |
| 333 | dPixel getRand() { return new dPixel(DS[floor(random(iTowerStrips))].v0,floor(random(15))); } |
| 334 | dPixel getClosest(xyz p) { |
| 335 | dVertex v = null; int pos=0; float d = 500; |
| 336 | for (int j=0; j<iTowerStrips; j++) { |
| 337 | dStrip s = DS[j]; |
| 338 | float nd = pd2(s.s.points.get(0),p.x,p.y,p.z); if (nd < d) { v=s.v0; d=nd; pos=0; } |
| 339 | if (nd > 30) continue; |
| 340 | for (int k=0; k<=15; k++) { |
| 341 | nd = pd2(s.s.points.get(k),p.x,p.y,p.z); if (nd < d) { v = s.v0; d=nd; pos=k; } |
| 342 | } |
| 343 | } |
| 344 | return random(2) < 1 ? new dPixel(v,pos) : new dPixel(v.opp,15-pos); |
| 345 | } |
| 346 | |
| 347 | dLattice() { |
| 348 | lattice=this; |
| 349 | //for (int i=0;i<NumBackTowers;i++) for (int j=0;j<MaxCubeHeight*2;j++) DQ[i][j]=-1; |
| 350 | |
| 351 | int col = 0, row = -2, i=-1; |
| 352 | for (Strip strip : glucose.model.strips ) { i++; |
| 353 | if (i % 16 == 0) row+=2; |
| 354 | if (row >= MaxCubeHeight*2-1) { col++; row = (col%2==1)?1:0; } // only include lattice parts! |
| 355 | iTowerStrips++; |
| 356 | dStrip s = DS[iTowerStrips-1] = new dStrip(strip, iTowerStrips-1, row, col); |
| 357 | s.v0 = new dVertex(s,strip.points.get(0 )); |
| 358 | s.v1 = new dVertex(s,strip.points.get(15)); |
| 359 | s.v0.setOpp(s.v1); s.v1.setOpp(s.v0); |
| 360 | //if (col < NumBackTowers) DQ[col][row] = 16*floor((iTowerStrips-1)/16); |
| 361 | //else s.row=-1; |
| 362 | } |
| 363 | |
| 364 | for (int j=0; j<iTowerStrips; j++) { for (int k=j+1; k<iTowerStrips; k++) { |
| 365 | dStrip s1 = DS[j], s2 = DS[k]; |
| 366 | int c=0; |
| 367 | if (sameSame(s1.s,s2.s)) { s1.v0.same = s2.v0; s1.v1.same = s2.v1; |
| 368 | s2.v0.same = s1.v0; s2.v1.same = s1.v1; continue; } // parallel |
| 369 | if (sameOpp (s1.s,s2.s)) { s1.v0.same = s2.v1; s1.v1.same = s2.v0; |
| 370 | s2.v0.same = s1.v1; s2.v1.same = s1.v0; continue; } // parallel |
| 371 | if (dist2(s1.s, 0, s2.s, 0) < 5) { c++; addJoint(s1.v1, s2.v0); addJoint(s2.v1, s1.v0); } |
| 372 | if (dist2(s1.s, 0, s2.s,15) < 5) { c++; addJoint(s1.v1, s2.v1); addJoint(s2.v0, s1.v0); } |
| 373 | if (dist2(s1.s,15, s2.s, 0) < 5) { c++; addJoint(s1.v0, s2.v0); addJoint(s2.v1, s1.v1); } |
| 374 | if (dist2(s1.s,15, s2.s,15) < 5) { c++; addJoint(s1.v0, s2.v1); addJoint(s2.v0, s1.v1); } |
| 375 | if (c>0) continue; |
| 376 | |
| 377 | // Are they touching at all? |
| 378 | int pos1=0, pos2=0; float d = 100; |
| 379 | |
| 380 | while (pos1 < 15 || pos2 < 15) { |
| 381 | float oldD = d; |
| 382 | if (pos1<15) { float d2 = dist2(s1.s, pos1+1, s2.s, pos2+0); if (d2 < d) { d=d2; pos1++; } } |
| 383 | if (pos2<15) { float d2 = dist2(s1.s, pos1+0, s2.s, pos2+1); if (d2 < d) { d=d2; pos2++; } } |
| 384 | if (d > 50 || oldD == d) break ; |
| 385 | } |
| 386 | |
| 387 | if (d>5) continue; |
| 388 | addTurn(s1.v0, pos1, s2.v0, pos2); addTurn(s1.v1, 15-pos1, s2.v0, pos2); |
| 389 | addTurn(s2.v0, pos2, s1.v0, pos1); addTurn(s2.v1, 15-pos2, s1.v0, pos1); |
| 390 | |
| 391 | }} |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | dLattice lattice; |
| 396 | //---------------------------------------------------------------------------------------------------------------------------------- |