diff options
| -rw-r--r-- | vodaviz.pde | 74 |
1 files changed, 57 insertions, 17 deletions
diff --git a/vodaviz.pde b/vodaviz.pde index 4540841..58c2348 100644 --- a/vodaviz.pde +++ b/vodaviz.pde @@ -34,21 +34,65 @@ // --> this is kind of hidden. why? anyway, it should be possible to use it //another option is to use the OUTLINE of the country (as a purely geometric thing). +/* + http://en.wikipedia.org/wiki/3D_projection + + a- the 3D position of a point A that is to be projected. + c- the 3D position of a point C representing the camera. + O- The orientation of the camera (represented, for instance, by Tait–Bryan angles). + e- the viewer's position relative to the display surface.[1] + + */ + import processing.pdf.*; import geomerative.*; +class pointMapper { + float xo,xs,yo,ys; + pointMapper(float _xo,float _xs,float _yo,float _ys) { + xo=_xo; + xs=_xs; + yo=_yo; + ys=_ys; + } + RPoint map(float _x,float _y) { + //formalise + float px=((_x-xo)/xs); //26)/736); + float py=((_y-yo)/ys); //90)/390); + + //transform + px=(((px-0.5)*0.25)+.25); //front half of sphere + py=((py-0.5)*0.3)+0.5; + + //map to 3D curve + float r=getHeight()*4; + float x=r*cos(px*PI*2)*(sin(py*PI)) *2; + float z=r*sin(px*PI*2)*(sin(py*PI))-985; + float y=r*cos(py*PI)+(getHeight()*0.5)-210; + + //camera at 0,0,0 + //screen plane at 0,0,100 + //(dx-ex)(ez/dz) + //(dy-ey)(ez/dz) + + return new RPoint(x*(100/z),y*(100/z)); + } +} + RShape shp; +pointMapper shpmap; //RRectangle cb; int whichChild,numChildren; void setup(){ println("vodaviz v0.11"); RG.init(this); - size(800,600,P3D); //,PDF, "testoutput.pdf"); //P3D); //832,220); + size(832,220); //PDF, "testoutput.pdf"); //P3D); //832,220); //nb pdf is 800x600 smooth(); float m = millis(); shp = RG.loadShape("world_countries_outlines_split.svg"); + shpmap = new pointMapper(26,736,90,390); RG.ignoreStyles(); println("loaded svg in "+((millis()-m)*.001)+" seconds"); numChildren=shp.children.length; @@ -59,13 +103,15 @@ void draw() { background(0,0,0); noFill(); stroke(255); - //strokeWeight(.1); + strokeWeight(.02); //RG.shape(shp); whichChild=(whichChild+1)%numChildren; //println("child "+whichChild+" of "+numChildren); //cb=shp.children[whichChild].getBounds(); + float xWrap=1.0; + //plot shapes at points for (int i=0;i<numChildren;i++) { String cmd=""; @@ -74,29 +120,23 @@ void draw() { beginShape(); for (int k=0;k<shp.children[i].paths[j].commands.length;k++) { RPoint sp=shp.children[i].paths[j].commands[k].startPoint; + RPoint dp=shpmap.map(sp.x,sp.y); - //map lat,lng coords - //normalise - float px=(sp.x-26)/736; - float py=(sp.y-110)/358; - - float r=getHeight()/2; - float x=r*cos(px*PI*2)*(sin(py)*PI); - float y=r*sin(px*PI*2)*(sin(py)*PI); - float z=r*cos(sin(py)*PI); - - //vertex(px*getWidth(),py*getHeight()); //,0); can't use 3D points with PDF - vertex(x+(getWidth()/2),y+(getHeight()/2),z); //z); - if (i==0&&j==0) cmd+=(x+(getWidth()/2))+","+(y+(getHeight()/2))+","+z+" "; + vertex(dp.x+(getWidth()/2),dp.y+(getHeight()/2)); //,z); //z); + //if (i==0&&j==0) cmd+=(x+(getWidth()/2))+","+(y+(getHeight()/2))+","+z+" "; } endShape(); } if (cmd!="") println(cmd); } - noLoop(); - //exit(); + noLoop(); + // exit(); } void mousePressed() { } + + + + |
