EXAMPLE
(click to run):
The following illustrates a simple example of a VisibilitySensor.
Two TimeSensors are used to move a Cylinder: one gives it a large
motion and one gives it a small motion. A VisibilitySensor is
used to disable the small-motion TimeSensor when the object is
out of view:
#VRML V2.0 utf8
DEF T1 Transform { # Large motion transform
children [
DEF VS VisibilitySensor {
# Must be big enough to enclose object
#plus small motion:
size 1.6 4.6 1.6
}
DEF T2 Transform { # Small motion transform
children [
Shape {
appearance Appearance { material Material { } }
geometry Cylinder { }
}
]
}
]
}
DEF TS1 TimeSensor { # Large motion TimeSensor
loop TRUE
cycleInterval 50
}
DEF PI1 PositionInterpolator { # Gross movement
key [ 0, .1, .2, .3, .4, .5, .6, .7, .8, .9, 1 ]
keyValue [ 0 0 -30, -10 5 -20, -20 0 -10, -30 -5 10,
-20 7 20, -10 4 10, 0 6 20, 20 4 0, 30 2 -20,
10 0 -20, 0 0 -30 ]
}
ROUTE TS1.fraction_changed TO PI1.set_fraction
ROUTE PI1.value_changed TO T1.set_translation
DEF TS2 TimeSensor { # Small motion
loop TRUE
cycleInterval 5
}
DEF PI2 PositionInterpolator { # Fine movement
key [ 0, .2, .4, .6, .8, 1 ]
keyValue [ 0 0 0, 0 1 0, 0 2 0, 0 3 0, 0 1.8 0, 0 0 0 ]
}
DEF OI OrientationInterpolator { # More fine movement:
# One full rotation requires at least 4 keyframes to avoid
# indeterminate rotation:
key [ 0, .33, .66, 1 ]
keyValue [ 1 0 0 0, 1 0 0 2.09, 1 0 0 4.19, 1 0 0 0 ]
}
DEF V Viewpoint {
description "Initial View"
position 0 1.6 15
}
ROUTE TS2.fraction_changed TO PI2.set_fraction
ROUTE TS2.fraction_changed TO OI.set_fraction
ROUTE PI2.value_changed TO T2.set_translation
ROUTE OI.value_changed TO T2.set_rotation
# Only perform fine motion when cylinder is visible:
ROUTE VS.isActive TO TS2.set_enabled
|