media @ VU
[] readme course preface I 1 2 II 3 4 III 5 6 7 IV 8 9 10 V 11 12 afterthoughts appendix references examples resources _

talk show tell print

math-peel-morph.vr

math-peel-morph.vr (wrl ) [ flux / bitmanagement / cortona / octaga ]

proto


  
  PROTO asphere [
     field SFInt32 nlatitude 16
     field SFInt32 nlongitude 16
     field SFFloat creaseAngle 3.14
  ]
  {
  DEF object Transform {
  children [
     DEF IFS IndexedFaceSet {
        coord DEF C Coordinate { }
        texCoord DEF TC TextureCoordinate { }
        creaseAngle IS creaseAngle
     }
   ]}
     DEF S Script {
        field SFInt32 nlat IS nlatitude
        field SFInt32 nl IS nlongitude
        field SFInt32 state 0
        field SFInt32 phase 10
        ##eventOut MFVec3f c
        eventOut MFVec3f c
        eventOut MFVec2f tc
        eventOut MFInt32 ci
        eventIn SFFloat change
        url [
           "javascript:
           function initialize() {
              var r, phi, x, y, z;
              var i, j, idx;
              // Compute coordinates, texture coordinates:
              for (i = 0; i < nlat; i++) {
                 //y = 2 * ( i / (nlat-1) ) - 1;
                 y = 2 * ( i / (nlat-1) ) - 1;
                 r = Math.sqrt( 1 - y*y );
                 for (j = 0; j < nl; j++) {
                    phi = 2 * Math.PI * j / nl;
                    x = -Math.sin(phi)*r;
                    z = -Math.cos(phi)*r;
                    c[i*nl+j] = new SFVec3f(x,y,z);
                    tc[i*nl+j] = new SFVec2f( j/nl, i/(nlat-1) );
                 }
              }
              // And compute indices:
              dfac = 3;
              for (i = 0; i < (nlat-1)/dfac; i++) {
                 for (j = 0; j < nl; j++) {
                    idx = 5*(i*nl+j);
                    ci[idx+0] = dfac*i*nl+(j)\%nl;
                    ci[idx+1] = dfac*i*nl+(j+1)\%nl;
                    ci[idx+2] = (dfac*i+1)*nl+(j+1)\%nl;
                    ci[idx+3] = (dfac*i+1)*nl+(j)\%nl;
                    ci[idx+4] = -1;  // end-of-polygon
                 }
              }
           }   
            function change(value) {
            
            var r, phi, x, y, z;
              var i, j, idx;
              var frac;
              frac = 2.0 * value;
              state += 1;
              if (frac > 1.0) frac = 2.0 - frac;
              frac = 1.0 + frac;
              // Compute coordinates, texture coordinates:
              if (state > phase) state = 0;
              if (state == 1) {
              
              for (i = 0; i < nlat; i++) {
                 //y = 2 * ( i / (nlat-1) ) - 1;
                 y = 2 * ( i / (nlat-1) ) - 1;
                 r = Math.sqrt( 1 - y*y );
                 for (j = 0; j < nl; j++) {
                    phi = 2 * Math.PI * j / nl;
                    x = -Math.sin(phi)*r * frac;
                    z = -Math.cos(phi)*r * frac;
                    c[i*nl+j] = new SFVec3f(x,y,z);
                    //tc[i*nl+j] = new SFVec2f( j/nl, i/(nlat-1) );
                 }
              }
           }
           }"
        ]
     }
     ROUTE S.c TO C.set_point
     ROUTE S.tc TO TC.set_point
     ROUTE S.ci TO IFS.set_coordIndex
     
    DEF time TimeSensor { cycleInterval 10 loop TRUE enabled TRUE }
    DEF rotation OrientationInterpolator {
    key [ 0 0.25 0.5 0.75 1 ]
    keyValue [ 1 1 0 0, 1 1 0 1.57, 1 1 0 3.14
               1 1 0 4.71, 1 1 0 0 
             ]
    }
    
    ROUTE time.fraction TO rotation.fraction
    ROUTE rotation.value TO object.rotation
  
    ROUTE time.fraction TO S.change 
  }
  
   Background { skyColor [0.9 .1 .1] }
   NavigationInfo { type ["EXAMINE", "ANY"] }
    
   Viewpoint { 
       position 0 0 10
       orientation 0 0 1 0
    }
    
    
  
  Transform {
       translation 0 0 0
       scale 2 2 2
       children [
          Shape {
             appearance DEF A Appearance {
                material Material {}
                ##texture ImageTexture { url ["local/images/check.gif"] }
                texture ImageTexture { url ["@logo.jpg"] }
             }
             ##geometry asphere { nlatitude 32 nlongitude 20 }
             geometry asphere { nlatitude 100 nlongitude 100 }
          }
       ]
    }
    
  
  


(C) A. Eliëns 21/5/2007

You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.