From 4f22144e71494c287b89af979a2a3a8eeaa1ddb6 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Tue, 10 Apr 2012 21:22:06 +0000 Subject: [PATCH] Added Patch example in Android --- .../examples/OpenGL/Advanced/Patch/Patch.pde | 161 ++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 android/examples/OpenGL/Advanced/Patch/Patch.pde diff --git a/android/examples/OpenGL/Advanced/Patch/Patch.pde b/android/examples/OpenGL/Advanced/Patch/Patch.pde new file mode 100644 index 000000000..b5767e3cc --- /dev/null +++ b/android/examples/OpenGL/Advanced/Patch/Patch.pde @@ -0,0 +1,161 @@ +// Bezier patch By Maritus Watz: +// http://www.openprocessing.org/sketch/57709 +// Normal calculation added by Andres Colubri +// Direct port of sample code by Paul Bourke. +// Original code: http://paulbourke.net/geometry/bezier/ + +int ni=2, nj=3, RESI=ni*10, RESJ=nj*10; +PVector outp[][], inp[][]; +PVector normp[][]; +boolean autoNormals = false; + +void setup() { + size(400, 400, P3D); + build(); +} + +void draw() { + background(255); + translate(width/2,height/2); + lights(); + scale(0.9); + rotateY(map(mouseX,0,width,-PI,PI)); + rotateX(map(mouseY,0,height,-PI,PI)); + + noStroke(); + fill(255); + for(int i=0; i= 1) { + blend *= nn; + nn--; + if (kn > 1) { + blend /= (double)kn; + kn--; + } + if (nkn > 1) { + blend /= (double)nkn; + nkn--; + } + } + if (k > 0) + blend *= Math.pow(mu, (double)k); + if (n-k > 0) + blend *= Math.pow(1-mu, (double)(n-k)); + + return(blend); +} + +double DBezierBlend(int k, double mu, int n) { + int nn, kn, nkn; + double dblendf = 1; + + nn = n; + kn = k; + nkn = n - k; + + while (nn >= 1) { + dblendf *= nn; + nn--; + if (kn > 1) { + dblendf /= (double)kn; + kn--; + } + if (nkn > 1) { + dblendf /= (double)nkn; + nkn--; + } + } + + double fk = 1; + double dk = 0; + double fnk = 1; + double dnk = 0; + if (k > 0) { + fk = Math.pow(mu, (double)k); + dk = k*Math.pow(mu, (double)k-1); + } + if (n-k > 0) { + fnk = Math.pow(1-mu, (double)(n-k)); + dnk = (k-n)*Math.pow(1-mu, (double)(n-k-1)); + } + dblendf *= (dk * fnk + fk * dnk); + + return(dblendf); +}