Fixed DPat to work with crossfader
[SugarCubes.git] / DanHorwitz.pde
index b15bad9d1b6a801a8fd6ebe84610043f3248f8c0..51b22cd22ee015a122e71b4f86d69c042aadd9a3 100755 (executable)
@@ -113,7 +113,10 @@ public class Play extends DPat
        int             nBeats  =       0;\r
        _DhP    pAmp, pRad;\r
        _DhP    pRotX, pRotY, pRotZ;\r
-       xyz             Theta = new xyz();\r
+       xyz             Theta   = new xyz();\r
+       xyz             TSin    = new xyz();\r
+       xyz             TCos    = new xyz();\r
+       \r
        Pick    pTimePattern, pTempoMult, pShape, pForm;\r
        int             RandCube;\r
 \r
@@ -139,9 +142,9 @@ public class Play extends DPat
                t = lx.tempo.rampf();\r
                a = pAmp.Val();\r
 \r
-               Theta.x = pRotX.ZeroOrOne() ? 0 :(pRotX.Val()-.5)*10;\r
-               Theta.y = pRotY.ZeroOrOne() ? 0 :(pRotY.Val()-.5)*10;\r
-               Theta.z = pRotZ.ZeroOrOne() ? 0 :(pRotZ.Val()-.5)*10;\r
+               Theta   .set(pRotX.Val()*PI*2, pRotY.Val()*PI*2, pRotZ.Val()*PI*2);\r
+               TSin    .set(sin(Theta.x), sin(Theta.y), sin(Theta.z));\r
+               TCos    .set(cos(Theta.x), cos(Theta.y), cos(Theta.z));\r
 \r
                if (t<LastMeasure) { CurRandTempo = int(random(4)); } LastMeasure = t;\r
                \r
@@ -169,38 +172,36 @@ public class Play extends DPat
        }\r
 \r
        color CalcPoint(xyz Px) {\r
-               xyz V           = new xyz();\r
-               xyz P           = Px.setNorm();\r
-               if (Theta.x>0)  P = P.RotateZ(xyzHalf, Theta.x);\r
-               if (Theta.y>0)  P = P.RotateZ(xyzHalf, Theta.y);\r
-               if (Theta.z>0)  P = P.RotateZ(xyzHalf, Theta.z);\r
+               xyz V           =       new xyz();\r
+               xyz P           =       Px.setNorm();\r
+                                               P.RotateXYZ(xyzHalf, Theta, TSin, TCos);\r
 \r
                float mp        = min(P.x, P.z);\r
                float yt        = map(t,0,1,.5-a/2,.5+a/2);\r
 \r
                switch (pShape.Cur()) {\r
-                       case 0:         V = new xyz(P.x, yt                                                             , P.z);                                         break;  // bouncing line\r
-                       case 1:         V = new xyz(P.x, map(cos(PI*t * P.x),-1,1,0,1)  , P.z);                                         break;  // top tap\r
-                       case 2:         V = new xyz(P.x, a*map(P.x<.5?P.x:1-P.x,0,.5 ,0,t-.5)+.5, P.z);                         break;  // V shape\r
-                       case 3:         V = new xyz(P.x, P.x < cMidNorm.x ? map(P.x,0,cMidNorm.x, .5,yt) :\r
-                                                                                                                       map(P.x,cMidNorm.x,1, yt,.5), P.z);             break;  //  Random V shape\r
-\r
-                       case 4:         V = new xyz(P.x, .5*(P.x < cMidNorm.x ? map(P.x,0,cMidNorm.x, .5,yt) :\r
-                                                                                                                        map(P.x,cMidNorm.x,1, yt,.5)) +\r
-                                                                                .5*(P.z < cMidNorm.z ? map(P.z,0,cMidNorm.z, .5,yt) :\r
-                                                                                                                        map(P.z,cMidNorm.z,1, yt,.5)), P.z);   break;  //  Random Pyramid shape\r
+                       case 0:         V.set(P.x, yt                                                     , P.z);                                                       break;  // bouncing line\r
+                       case 1:         V.set(P.x, map(cos(PI*t * P.x),-1,1,0,1)  , P.z);                                                       break;  // top tap\r
+                       case 2:         V.set(P.x, a*map(P.x<.5?P.x:1-P.x,0,.5 ,0,t-.5)+.5, P.z);                                       break;  // V shape\r
+                       case 3:         V.set(P.x, P.x < cMidNorm.x ? map(P.x,0,cMidNorm.x, .5,yt) :\r
+                                                                                                         map(P.x,cMidNorm.x,1, yt,.5), P.z);                   break;  //  Random V shape\r
+\r
+                       case 4:         V.set(P.x,      .5*(P.x < cMidNorm.x ?  map(P.x,0,cMidNorm.x, .5,yt) :\r
+                                                                                                                       map(P.x,cMidNorm.x,1, yt,.5)) +\r
+                                                                       .5*(P.z < cMidNorm.z ?  map(P.z,0,cMidNorm.z, .5,yt) :\r
+                                                                                                                       map(P.z,cMidNorm.z,1, yt,.5)), P.z);    break;  //  Random Pyramid shape\r
                                                                                                                        \r
-                       case 5:         V = new xyz(P.x, a*map((P.x-.5)*(P.x-.5),0,.25,0,t-.5)+.5, P.z);                        break;  // wings\r
-                       case 6:         V = new xyz(P.x, a*map((mp -.5)*(mp -.5),0,.25,0,t-.5)+.5, P.z);                        break;  // wings\r
+                       case 5:         V.set(P.x, a*map((P.x-.5)*(P.x-.5),0,.25,0,t-.5)+.5, P.z);                                      break;  // wings\r
+                       case 6:         V.set(P.x, a*map((mp -.5)*(mp -.5),0,.25,0,t-.5)+.5, P.z);                                      break;  // wings\r
 \r
-                       case 7:         V = new xyz(cMid.x,cMid.y,cMid.z);\r
+                       case 7:         V.set(cMid.x,cMid.y,cMid.z);\r
                                                return color(0,0,c1c(1 - (V.distance(Px) > (pRad.getValuef()+.1)*150?1:0)) );           // sphere\r
 \r
-                       case 8:         V = new xyz(cMid.x,cMid.y,cMid.z);\r
+                       case 8:         V.set(cMid.x,cMid.y,cMid.z);\r
                                                return color(0,0,c1c(1 - CalcCone(Px,V,xyzMid) * 0.02 > .5?1:0));                                       // cone\r
 \r
                        case 9:         return color(100 + noise(P.x,P.y,P.z + (NoiseMove+50000)/1000.)*200,\r
-                                                                       85,c1c(P.y < noise(P.x + NoiseMove/2000.,P.z)*(1+a)-a/2.-.1 ? 1 : 0));          //\r
+                                                       85,c1c(P.y < noise(P.x + NoiseMove/2000.,P.z)*(1+a)-a/2.-.1 ? 1 : 0));                  //\r
                }\r
 \r
 \r