Part 3: Flip that Switch, Widgets with VRML
Make that Switch Look Better
 More of this Feature
• Part 2: Flip It
 
 Join The Discussion
"Have certain sites increased revenue because of 3D features?"
AHEDSTROM
 
 Related Resources
• VRML Repository
• Web3D Consortium
 

Dateline: 10/04/00

down and up
Toggle light on and then off.

When last we left out intrepid widget builder we had a perfectly good toggle behavior. The visuals were really crap, so let's improve it a bit. Our goal is to create an actual physical switch that animates up and down just like a real light switch.

First we need to create the physical geometry, then we need to animate it, and finally we need to connect up that geometry with the toggle behavior. First the geometry.

The Geometry

DEF BOXGEOM Transform {
	   translation 0 0 -4
	   scale 1 1 1
	   children	[
		   DEF ELMO TouchSensor {}
		   Shape {
               appearance Appearance {
                     material DEF WHITE Material {
                              diffuseColor 1 1 1
                     }
               }
	
               geometry Box { size 0.4 2.0 0.2}
           }
		]
	}

Now we animate it. To animate we set up a TimeSensor that controls an OrientationInterpolator. Following is the code fragment plus the ROUTEs.

DEF CLOCK TimeSensor {
	cycleInterval 1.5
	startTime -1
	loop FALSE
	enabled TRUE
}
DEF ROTATOR OrientationInterpolator {
	key [ 0.0, 0.50, 1.0 ]
	keyValue [
		1 0 0 0.4,
		1 0 0 1.4,
		1 0 0 2.5
	]
}
ROUTE ToggleScript.value_changed TO	CLOCK.enabled
ROUTE ELMO.touchTime TO CLOCK.set_startTime
ROUTE CLOCK.fraction_changed TO ROTATOR.set_fraction
ROUTE ROTATOR.value_changed TO BOXGEOM.set_rotation

Next page > Flip It > Page 1, 2