#VRML V2.0 utf8 WorldInfo { info "Touch the light switch and light the dark blue one" } # Let it be dark .. well no! # NavigationInfo { # headlight FALSE .. hmm CP 1.02 makes it really dark headlight TRUE } DEF EntryVP Viewpoint { position 0 0 7 description "Normal viewpoint" } DEF CloseVP Viewpoint { position 0 0 4 description "Close viewpoint" } DEF FarVP Viewpoint { position 0 0 10 description "Far viewpoint" } # The touchsensors for putting the Light ON and OFF # DEF LightSwitch Transform { translation -0.5 0.5 4 children [ DEF Switcher Switch { whichChoice 0 choice [ # light ON node Group { children [ DEF LightSwitchONSensor TouchSensor { } Inline { url ["../common/light-switch.wrl"] } ] } # Light OFF node Group { children [ DEF LightSwitchOFFSensor TouchSensor { # must be off, since it is ACTIVE even if hidden enabled FALSE } Inline { url ["../common/light-switch2.wrl"] } ] } ] } ] } # The light, off when the file is loaded # DEF LIGHT PointLight { on FALSE location -3 2 2 } # The object to be lit, a simple dark blue ball # Shape { appearance Appearance { material Material { diffuseColor 0.0 0.0 0.4 shininess 1 } } geometry Sphere { radius 1 } } # Clicking on the green Light Switch (ON) # DEF lightONScript Script { eventIn SFBool lightONIsActive eventOut SFBool lightIsON eventOut SFInt32 lightSwitchPOS url [ "vrmlscript: function lightONIsActive(active) { lightIsON = TRUE; lightSwitchPOS = 1; }", "javascript: function lightONIsActive(active) { lightIsON = TRUE; lightSwitchPOS = 1; }" ] } # link activation of lightON to evenIn of lightONScript ROUTE LightSwitchONSensor.isActive TO lightONScript.lightONIsActive # # route effects to light and the light switch # ROUTE lightONScript.lightIsON TO LIGHT.set_on ROUTE lightONScript.lightSwitchPOS TO Switcher.whichChoice # # enable the off sensor (without this the 2 sensors will sabotage each) # I only wonder why this is enough !! # ROUTE lightONScript.lightIsON TO LightSwitchOFFSensor.enabled # Clicking on the red Light Switch (OFF) # DEF lightOFFScript Script { eventIn SFBool lightOFFIsActive eventOut SFBool lightIsON eventOut SFInt32 lightSwitchPOS url [ "vrmlscript: function lightOFFIsActive(active) { lightIsON = FALSE; lightSwitchPOS = 0; }", "javascript: function lightOFFIsActive(active) { lightIsON = FALSE; lightSwitchPOS = 0; }" ] } # link activation of lightOFF to evenIn of lightOFFScript # ROUTE LightSwitchOFFSensor.isActive TO lightOFFScript.lightOFFIsActive # # route effects to light and the light switch # ROUTE lightOFFScript.lightIsON TO LIGHT.set_on ROUTE lightOFFScript.lightSwitchPOS TO Switcher.whichChoice