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

web3d-x-ball-2.vr

web3d-x-ball-2.vr (wrl ) [ flux / bitmanagement / cortona / octaga ]

Web3D/VR

bouncing ball (2)

ground


  
  Transform {
  children [
  Transform {
  translation 0 -10 0
  children [
  Shape {
           geometry Box { size 10 0.2 10 }
           appearance Appearance {
                  material DEF MATERIAL Material {
                          diffuseColor 1  0 0
                          }
                  }
  }
  ]}
  
  

object


        
  DEF OBJECT Transform {
  scale 0.5 0.5 0.5
  children [ 
  Shape  {
          geometry Sphere { radius 1 }
          appearance Appearance {
                  material DEF MATERIAL Material {
                          diffuseColor 1 0 0
                          }
                  }
  }
  ] }
  ] }
  
  

sensor


  DEF TIME TimeSensor { loop TRUE cycleInterval 5 } #<l++>
  
  

script


  DEF SCRIPT Script {   
          directOutput TRUE
  
          field  SFTime  tick   0
  
          field SFNode object USE OBJECT
          field SFNode material USE MATERIAL
          field SFFloat position 0
          field SFFloat color 0.5
          field SFInt32 sign 1
          eventIn SFFloat set_fraction    
          url "javascript:
  
  

fraction


          function set_fraction(value) { // to regulate timing  
          if (tick == 0) {
                    tick = value;
                    position = 0;
                    color = 0.5;
                }
                while (tick < value) {
                    update(value);
                    tick = tick + 0.05;
                }
          tick = value;
          }
  
  

update


          function update(value) {
                  position += 0.2 * sign;
                  color = value;
  
                  object.translation.y = position;
                  material.diffuseColor = new SFColor(1,color,color);
  
                  if (position > 7) sign = -1; 
                  if (position < -9) sign = 1; 
                  }
                  "
          }#<l++>
  

routing


  ROUTE TIME.fraction_changed TO SCRIPT.set_fraction
  
  

environment


  
  Viewpoint { position 0 0 30 }
  Background { skyColor 0.2 0.2 0.4 }
  
  


(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.