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

x-ball-result-2.vr

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


  
  #Author: Leon Webbers                        Date: April 6 2006

  

  

  PROTO bounce [

  exposedField SFFloat accel 0.1

  ]{

  Transform {

  children [

  Transform {

  translation 0 -10 0

  children [

  

  Shape {

           geometry Box { size 5 0.2 5 }

           appearance Appearance {

                  material DEF GROUND Material {

                          diffuseColor 1  0 0

                          }

                  }

  }

  ]}

  

  

        

  DEF OBJECT Transform {

  scale 0.5 0.5 0.5

  children [ 

  DEF switch Switch {

          whichChoice 4

          choice [

  Shape  {

          geometry Sphere { radius 2 }

          appearance Appearance {

                  material DEF MATERIAL Material {

                          diffuseColor 1 0 0

                          }

                  }

  }

  Shape  {

          geometry Cone { 

                          bottomRadius 2

                      height 3

                  }

          appearance Appearance {

                  material USE MATERIAL

                  }

  }

  Shape  {

          geometry Box { 

                  size 2 2 2

                  }

          appearance Appearance {

                  material USE MATERIAL

                  }

  }

  Shape  {

          geometry Cylinder { 

                  radius 1

                  height 2

                  }

          appearance Appearance {

                  material USE MATERIAL

                  }

  }

  DEF TEKST Shape  {

          geometry Text { 

                          string        "HELLO"

                          fontStyle FontStyle {

                                  size 3

                              justify "MIDDLE"

                                  family "Arial"

                                  style "BOLD"

                                  

                          }

                  }

                  appearance Appearance {

                  material USE MATERIAL

                  }

  }

  ] }

  

  ] }

  ] }

  

              

  DEF TIME TimeSensor { loop TRUE cycleInterval 5 } 

  

  

  DEF SCRIPT Script {   

          directOutput TRUE

  

          field SFFloat accel IS accel

  

          field  SFTime  tick   0

  

                  field SFNode sw USE switch

          field SFNode object USE OBJECT

          field SFNode material USE MATERIAL

          field SFNode ground USE GROUND

                  field SFNode txt USE TEKST

          field SFFloat position 0

          field SFFloat color 0.5

  

          field SFInt32 sign -1

          field SFFloat speed 1

                  field SFFloat time 0

                  ##field SFNode monit USE MONITOR

  

          eventIn SFFloat set_fraction    

          url "javascript:

  

  

  

          function set_fraction(value) { 

          if (tick == 0) {

                    tick = value;

                    position = 0;

                    color = 0.5;

                }

                while (tick < value) {

                    update(value);

                    tick = tick + 0.005;

                }

          tick = value;

          }

  

  

          function update(value) {

                  position += 0.005 * sign * speed;

                  color = value;

  

                  if (sign == -1)

                                  {

                                          time += 0.4;

                                  }

                                  else

                                  {

                                          time -= 0.4;

                                  }        

                                          

                  //speed = accel * (time ^ 2);

                                  speed = accel * (time * time);

  

                              object.translation.y = position;

  

                                  //monit.set_string = 'test' + speed + ' ' + position;

  

                  if (speed < 1) sign = -1; 

                  if (position < -9) {

                           effect(value);

                           sign = 1;

                                                   speed *= 0.3;

                           }

                                  if (speed < 1 && position < -9)

                                  { accel = 0;

                                  }

                  }

  

          function effect(value) {

                  material.diffuseColor = new SFColor(Math.max(0.4, Math.round(Math.random())),Math.max(0.4, Math.round(Math.random())),Math.max(0.4, Math.round(Math.random())));

                  ground.diffuseColor = material.diffuseColor;

                                  sw.whichChoice = Math.round(Math.random() * 4);

                                  //txt.geometry.string = speed;

                  }

                  "

          }

  

  ROUTE TIME.fraction_changed TO SCRIPT.set_fraction

  }

  

  

  

  Transform {

  translation -12 0 0

  children [

  bounce { accel 1  }

  ] }

  

  Transform {

  translation 0 0 0

  children [

  bounce { accel 2  }

  ] }

  

  Transform {

  translation 12 0 0

  children [

  bounce { accel 3  }

  ] }

  

  Transform {

  translation -6 0 -10

  children [

  bounce { accel 4  }

  ] }

  

  Transform {

  translation 6 0 -10

  children [

  bounce { accel 5  }

  ] }

  

  

  

  PointLight { location 0 5 -5  }

  Viewpoint {

      description "Sky" 

          position 0 0 30 

  }

  Viewpoint {

      description        "Front"

          position 0 -10 30

  }

  Viewpoint {

      description        "Top"

          position 0 20 20

      orientation -1.5 0 0 1          

  }

  Viewpoint {

      description        "Side"

          position 0 0 30 

  }

  Background {

     skyColor 0 0.7 1

     groundColor[ 0.4 0.2 0, 0.6 0.4 0.2, 0.8 0.6 0.4]

     skyAngle        1.5

     groundAngle [1.13, 1.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.