media @ VU
[] readme course(s) preface I 1 2 II 3 4 III 5 6 7 IV 8 9 10 V 11 12 afterthought(s) appendix reference(s) example(s) resource(s) _

talk show tell print

vrml-math-Surf.vr

vrml-math-Surf.vr (wrl ) [ flux / bitmanagement / cortona / octaga ]


  
  # Thanks to R.J.M.Smeenk for suggestion to make CPoint PROTO
  
  NavigationInfo{ type "EXAMINE" }
  Viewpoint{ position 0 2.1 6 orientation 1 0 0 -.4}
  
  PROTO CPoint[
   field SFInt32 Id 0
   field SFColor col 0 1 1
   eventOut SFInt32 setId
   exposedField SFVec3f translation 0 0 0 ]{
  Transform{ translation IS translation  children[ Shape{
   appearance Appearance{ material Material{ diffuseColor IS col } }
   geometry Sphere{ radius .05}}
   DEF ts TouchSensor{}]
  }
  DEF CPscr Script{
   eventIn SFBool getTS
   eventOut SFInt32 setId IS setId
   field SFInt32 Id IS Id
   directOutput TRUE
  url ["javascript: function getTS(val){ if(val) setId = Id; }"]
  }
  ROUTE ts.isActive TO CPscr.getTS
  }
  DEF N0 CPoint{ translation -1 0 -1  col 1 1 0}
  DEF N1 CPoint{ translation -.5 .5 -1 Id 1}
  DEF N2 CPoint{ translation .5 .5 -1  Id 2}
  DEF N3 CPoint{ translation 1 0 -1  Id 3  col 1 1 0}
  DEF N4 CPoint{ translation -1 .5 -.5  Id 4}
  DEF N5 CPoint{ translation -.5 1 -.5  Id 5  col 1 0 1}
  DEF N6 CPoint{ translation .5 1 -.5  Id 6  col 1 0 1}
  DEF N7 CPoint{ translation 1 .5 -.5  Id 7}
  DEF N8 CPoint{ translation -1 .5 .5  Id 8}
  DEF N9 CPoint{ translation -.5 1 .5  Id 9  col 1 0 1}
  DEF N10 CPoint{ translation .5 1 .5  Id 10  col 1 0 1}
  DEF N11 CPoint{ translation 1 .5 .5  Id 11}
  DEF N12 CPoint{ translation -1 0 1  Id 12  col 1 1 0}
  DEF N13 CPoint{ translation -.5 .5 1  Id 13}
  DEF N14 CPoint{ translation .5 .5 1  Id 14}
  DEF N15 CPoint{ translation 1 0 1  Id 15  col 1 1 0}
  
  PROTO Bunch[ field SFNode coor NULL]{
  Transform{ children[ Shape{
   appearance Appearance{ material Material{ emissiveColor 0 1 1 } }
   geometry IndexedLineSet{ coord IS coor coordIndex[1 0 2 -1 0 3]} }
  ]}}
  Bunch{ coor DEF bunch0 Coordinate{} }
  Bunch{ coor DEF bunch1 Coordinate{} }
  Bunch{ coor DEF bunch2 Coordinate{} }
  Bunch{ coor DEF bunch3 Coordinate{} }
  
  DEF spIFS Switch{ whichChoice 0 choice[ Transform{ children[ Shape{
   appearance Appearance{ material Material{ diffuseColor 1 1 1 } }
   geometry DEF spline IndexedFaceSet{ coord DEF spCoord Coordinate{}
    creaseAngle 1 solid FALSE}}
  ]} ]}
  DEF swGrid Switch{ whichChoice 0 choice[ Transform{ children[ Shape{
   appearance Appearance{ material Material{ emissiveColor 1 1 1 } }
   geometry DEF spGrid IndexedLineSet{ coord USE spCoord } }
  ]} ]}
  Transform{ translation 2.5 1 -2 children[ Shape{
   appearance Appearance{ material Material{ diffuseColor 1 0 0}}
   geometry Sphere{ radius .2}}
   DEF tsIFS TouchSensor{}
  ]}
  Transform{ translation 2.5 0 -2 children[ Shape{
   appearance Appearance{ material Material{ diffuseColor 1 1 1}}
   geometry Sphere{ radius .2}}
   DEF tsGrid TouchSensor{}
  ]}
  Transform{ translation 2.5 -1 -2 children[ Shape{
   appearance Appearance{ material Material{ diffuseColor 0 0 1}}
   geometry Sphere{ radius .2}}
   DEF tsPrint TouchSensor{}
  ]}
  DEF Marker Transform{ children[ Shape{
   appearance Appearance{ material Material{ diffuseColor 1 1 1 transparency .3} }
   geometry Sphere{ radius .08}
  }]}
  
  PROTO Pointer[ field SFColor col 0 0 1
   exposedField SFVec3f translation 0 0 0]{
  Transform{ translation IS translation  children[ Shape{
   appearance Appearance{ material Material{ diffuseColor IS col } }
   geometry Sphere{ radius .07} }
  ]}}
  DEF ptXY Pointer{}
  DEF ptXZ Pointer{ col 0 1 0}
  DEF ptYZ Pointer{ col 1 0 0}
  
  Transform{ children[ Shape{
   appearance Appearance{ material Material{ diffuseColor 0 0 .9 transparency .5}}
   geometry DEF plane IndexedFaceSet{
   coord Coordinate{ point[-2 -2 -2,2 -2 -2,2 2 -2,-2 2 -2]}
   coordIndex[0 1 2 3] solid FALSE} }
   Shape{ appearance Appearance{ material Material{ emissiveColor 0 0 1} }
   geometry DEF grid IndexedLineSet{ coord Coordinate{
   point[-2 -2 -1.99,2 -2 -1.99,-2 -1 -1.99,2 -1 -1.99,-2 0 -1.99,2 0 -1.99,
   -2 1 -1.99,2 1 -1.99,-2 2 -1.99,2 2 -1.99,  -2 -2 -1.99,-2 2 -1.99,
   -1 -2 -1.99,-1 2 -1.99,0 -2 -1.99,0 2 -1.99, 1 -2 -1.99,1 2 -1.99,
   2 -2 -1.99,2 2 -1.99]}
   coordIndex[0 1 -1 2 3 -1 4 5 -1 6 7 -1 8 9 -1 10 11 -1 12 13 -1 14 15 -1
   16 17 -1 18 19]} }
   DEF tsXY PlaneSensor{}
  ]}
  Transform{ rotation 1 0 0 -1.57 children[ Shape{
   appearance Appearance{ material Transform{ rotation 1 0 0 -1.57 children[ Shape{

   appearance A
  |2`.html>Material{ diffuseColor .8 .8 .8 transparency .5}}
   geometry USE plane }
   Shape{ appearance Appearance{ material Material{ emissiveColor .5 .5 .5} }
   geometry USE grid}
   DEF tsXZ PlaneSensor{}
  ]}
  Transform{ rotation 0 1 0 1.57 children[ Shape{
   appearance Appearance{ material Material{ diffuseColor 1 0 0 transparency .5}}
   geometry USE plane }
   Shape{ appearance Appearance{ material Material{ emissiveColor .9 0 0} }
   geometry USE grid}
   DEF tsYZ PlaneSensor{}
  ]}
  
  DEF SCR Script{
   eventIn SFVec3f setXY
   eventIn SFVec3f setYZ
   eventIn SFVec3f setXZ
   eventIn SFInt32 getId
   eventIn SFBool setIFS
   eventIn SFBool setGrid
   eventIn SFBool Print
   field SFNode Marker USE Marker
   field SFNode ptXY USE ptXY
   field SFNode ptYZ USE ptYZ
   field SFNode ptXZ USE ptXZ
   field SFNode N0 USE N0
   field SFNode N1 USE N1
   field SFNode N2 USE N2
   field SFNode N3 USE N3
   field SFNode N4 USE N4
   field SFNode N5 USE N5
   field SFNode N6 USE N6
   field SFNode N7 USE N7
   field SFNode N8 USE N8
   field SFNode N9 USE N9
   field SFNode N10 USE N10
   field SFNode N11 USE N11
   field SFNode N12 USE N12
   field SFNode N13 USE N13
   field SFNode N14 USE N14
   field SFNode N15 USE N15
   field SFNode spline USE spline
   field SFNode swGrid USE swGrid
   field SFNode spGrid USE spGrid
   field SFNode spCoord USE spCoord
   field SFNode bunch0 USE bunch0
   field SFNode bunch1 USE bunch1
   field SFNode bunch2 USE bunch2
   field SFNode bunch3 USE bunch3
   field SFNode spIFS USE spIFS
   directOutput TRUE
  
   ## globals
   field MFNode Ni []
   field SFVec3f mark 0 0 0
   field MFVec3f p []
   field SFVec3f posXY 0 0 0
   field SFVec3f posXZ 0 0 0
   field SFVec3f posYZ 0 0 0 
   field SFInt32 num 0
   field SFInt32 iN 0
   field MFFloat b0 []
   field MFFloat b1 []
   field MFFloat b2 []
   field MFFloat b3 []
  
   field SFInt32 swi 0
   field SFInt32 swg 0
  
  url ["javascript:
  
  function initialize() { 
   var st,i,j;
  
   Ni = new MFNode(N0,N1,N2,N3,N4,N5,N6,N7,N8,N9,N10,N11,N12,N13,N14,N15);
   mark = new SFVec3f(0, 0, 0);
  
   p = new MFVec3f(new SFVec3f(-1,0,-1),new SFVec3f(-.5,.5,-1),
    new SFVec3f(.5,.5,-1),new SFVec3f(1,0,-1),
    new SFVec3f(-1,.5,-.5),new SFVec3f(-.5,1,-.5),
    new SFVec3f(.5,1,-.5),new SFVec3f(1,.5,-.5),
    new SFVec3f(-1,.5,.5),new SFVec3f(-.5,1,.5),
    new SFVec3f(.5,1,.5),new SFVec3f(1,.5,.5),
    new SFVec3f(-1,0,1),new SFVec3f(-.5,.5,1),
    new SFVec3f(.5,.5,1), new SFVec3f(1,0,1) );
   posXY = new SFVec3f(0, 0, -2);
   posXZ = new SFVec3f(0, -2, 0);
   posYZ = new SFVec3f(-2, 0, 0);
   num = 10; st = 1./(num-1);
   var c = new MFInt32();  c.length = 2*num*(num+1);
   b0 = new MFFloat();  b0.length = num;
   b1 = new MFFloat();  b1.length = num;
   b2 = new MFFloat();  b2.length = num;
   b3 = new MFFloat();  b3.length = num;
   var nn1 = num*(num+1);
   for (i= 0; i< num; i++){
    for (j= 0; j< num; j++){
     c[i*(num+1)+j] = i*num + j;
     c[nn1+i*(num+1)+j] = j*num + i;}
    c[(i+1)*(num+1)-1] = c[nn1+(i+1)*(num+1)-1] = -1;
    u = i*st; u1 = 1-u; u12 = u1*u1; u2 = u*u;
    b0[i] = u1*u12; b1[i] = 3*u*u12; b2[i] = 3*u2*u1; b3[i] = u*u2;}
   spGrid.set_coordIndex = c;
   var s = new MFInt32();  s.length = 8*(num-1)*(num-1);
   k=0;
   for (j= 0; j< num-1; j++)
    for (i= 0; i< num-1; i++) {
     s[k++] = i+num*j+1; s[k++] = i+num*j; s[k++] = i+num*(j+1); s[k++] = -1;
     s[k++] = i+num*(j+1); s[k++] = i+num*(j+1)+1; s[k++]=i+num*j+1; s[k++]=-1;}
   spline.set_coordIndex = s;
   iN = 15;
   setXYZ(p[iN]);
   swi = 0;  swg = 0;
  }
  
  function getId( Id ){ iN = Id; setXYZ(p[iN]);}
  function setXYZ(val){
   mark.x = posXZ.x = posXY.x = val.x;
   mark.y = posXY.y = posYZ.y = val.y;
   mark.z = posXZ.z = posYZ.z = val.z;
   Marker.set_translation = mark;
   ptXY.set_translation = posXY;
   ptXZ.set_translation = posXZ;
   ptYZ.set_translation = posYZ;
   p[iN].x = val.x; p[iN].y = val.y; p[iN].z = val.z;
   Ni[iN].set_translation = p[iN];
   var pt = new MFVec3f(); pt.length = num*num;
   t = 0;
   for (j= 0; j< num; j++) for (i= 0; i< num; i++){
    d = p[0].multiply(b0[i]).add(p[1].multiply(b1[i]))
     .add(p[2].multiply(b2[i])).add(p[3].multiply(b3[i])).multiply(b0[j]);
    d = d.add(p[4].multiply(b0[i]).add(p[5].multiply(b1[i]))
     .add(p[6].multiply(b2[i])).add(p[7].multiply(b3[i])).multiply(b1[j]));
    d = d.add(p[8].multiply(b0[i]).add(p[9].multiply(b1[i]))
     .add(p[10].multiply(b2[i])).add(p[11].multiply(b3[i])).multiply(b2[j]));
    pt[t++] = d.add(p[12].multiply(b0[i]).add(p[13].multiply(b1[i]))
     .add(p[14].multiply(b2[i])).add(p[15].multiply(b3[i])).multiply(b3[j])); }
   spCoord.set_point = pt;
   bunch0.set_point = new MFVec3f(p[0],p[1],p[4],p[5]);
   bunch1.set_point = new MFVec3f(p[3],p[2],p[6],p[7]);
   bunch2.set_point = new MFVec3f(p[12],p[8],p[9],p[13]);
   bunch3.set_point = new MFVec3f(p[15],p[10],p[11],p[14]);
  }
  function setXY(val){ setXYZ(new SFVec3f(val.x,val.y,mark.z));}
  function setYZ(val){ setXYZ(new SFVec3f(mark.x,val.y,-val.x));}
  function setXZ(val){ setXYZ(new SFVec3f(val.x,mark.y,-val.y));}
  function setIFS(val){ if(val){ swi = (swi+1)%2; spIFS.set_whichChoice = swi;}}
  function setGrid(val){ if(val){ swg = (swg+1)%2; swGrid.set_whichChoice = swg;}}
  function Print(val){ if(val) for(i=0; i<16; i++) print( p[i] );}
  "]
  }
  ROUTE N0.setId TO SCR.getId
  ROUTE N1.setId TO SCR.getId
  ROUTE N2.setId TO SCR.getId
  ROUTE N3.setId TO SCR.getId
  ROUTE N4.setId TO SCR.getId
  ROUTE N5.setId TO SCR.getId
  ROUTE N6.setId TO SCR.getId
  ROUTE N7.setId TO SCR.getId
  ROUTE N8.setId TO SCR.getId
  ROUTE N9.setId TO SCR.getId
  ROUTE N10.setId TO SCR.getId
  ROUTE N11.setId TO SCR.getId
  ROUTE N12.setId TO SCR.getId
  ROUTE N13.setId TO SCR.getId
  ROUTE N14.setId TO SCR.getId
  ROUTE N15.setId TO SCR.getId
  ROUTE tsXY.trackPoint_changed TO SCR.setXY
  ROUTE tsXZ.trackPoint_changed TO SCR.setXZ
  ROUTE tsYZ.trackPoint_changed TO SCR.setYZ
  ROUTE tsIFS.isActive TO SCR.setIFS
  ROUTE tsGrid.isActive TO SCR.setGrid
  ROUTE tsPrint.isActive TO SCR.Print
  


(C) A. Eliëns 2/9/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.