# # #[return] #
# ex-script-touchcube.wrl
#VRML V2.0 utf8 
# Written By Fabiana
# Last Modified 12-03-97

# this example defines a cube and a cone. The cube changes its 
#  color depending on a Touch. The cone is continuously rotating 
#  unless the cube has more than 50% red color
# see more details in [details]
 
# defining cone and box in a group. 
# The box has an associated TouchSensor
Group {
  children [
     DEF Sph Transform { 
          children Shape { 
            geometry Cone {} 
               appearance Appearance { 
                 material Material { diffuseColor 1 0 0 } 
                                      } 
                           } 
                        } 
     Transform {
         translation -2.4 .2 1
         rotation 0 1 1 .9
           children [	
                 Shape { 
                   geometry Box {}
                   appearance Appearance {
                       material DEF MATERIAL Material {} 	
                                          }
                        }
                 DEF TS TouchSensor {}
                     ]
                }

# script file association
     DEF SC Script {	
#url "/vfs/lab1/i/users/lpini/vrml/book/run-examples/exscript.class"
#url "http://www.cgl.uwaterloo.ca/~lpini/leovrml/run-examples/exscript.class"
url "extouchcube.class"

          field SFColor currentColor 0 0 0 
          eventIn SFColor colorIn
          eventOut SFBool isRed
                    }
            ]
    }

DEF myColor ColorInterpolator {
                 keys [0.0, 0.3, 0.6, 1.0 ]
                 values [1 0 0 , 0 1 0, 1 0 0, 0 0 1]
                               }
DEF myClock TimeSensor {
         cycleInterval 10  # 10 seg of animation red <-> blue
                        }
DEF XTIMER TimeSensor {
         loop TRUE         # if true it is not necessary to click
         cycleInterval  5
                       }
DEF ENGINE OrientationInterpolator {
                 keys [ 0, .5, 1]
                 values [ 0 1 0 0, 0 1 0 3.14, 0 1 0 6.28]
                                    }
 ROUTE TS.touchTime TO myClock.set_startTime 
 ROUTE myClock.fraction TO myColor.set_fraction 
 ROUTE myColor.value_changed TO MATERIAL.diffuseColor 
 ROUTE myColor.value_changed TO SC.colorIn 

 ROUTE SC.isRed TO XTIMER.enabled 

 ROUTE XTIMER.fraction TO ENGINE.set_fraction 
 ROUTE ENGINE.value_changed TO Sph.set_rotation
#