Come closer ...
tested with
+
+
Today's topic is the ProximitySensor. This
sensor is triggered whenever the user enters or leaves the space described
by the sensor. Important fields are center and size which
define the origin (center) and the extent of the ProximitySensor.
Let's take our Hello World
file from the first tutorial and see how we can modify it for today's topic.
Add a ProximitySensor as a child to the sphere node of the
'Hello World' example:
DEF sphere Transform {
translation 0 0 0
children [
Shape { ... }
DEF comeCloser ProximitySensor {
center 0 0 0
size 4 4 4
}
]
}
Here we define a box centered at the origin with side lenghts of 4 units.
this is about twice the size of the sphere.
When a user walks or flies into the sphere this sensor triggers an
eventOut 'isActive' which can be used to ROUTE it to a
Script. I will use the 'touchBoxIsActive' script of the
touch me example and rename it
to 'comeCloserScript':
DEF comeCloserScript Script {
eventIn SFBool enterProximitySensorIsActive
eventOut SFBool bindView2
url "javascript:
function enterProximitySensorIsActive(active) {
bindView2 = TRUE;
}"
}
Again we ROUTE the eventOut 'isActive' from the
ProximitySensor to the eventIn 'enterProximitySensorIsActive'
of the Script 'comeCloserScript'. Upon triggering the Script
we are able to Route the eventOut of the Script
'comeCloserScript' to the eventIn 'set_bind' of 'view2':
ROUTE comeCloser.isActive TO comeCloserScript.enterProximitySensorIsActive
ROUTE comeCloserScript.bindView2 TO view2.set_bind
Please take a look at the final
Come closer source, then load
Come closer.wrl and move
towards the sphere. Right before you reach it you will be thrown back to the second
Viewpoint 'view2'. Play around with the size of the
ProximitySensor, e.g. make the sphere approachable from one side but
not from the other:
DEF comeCloser ProximitySensor {
center 2 0 0
size 4 4 4
}
This moves the 'proximity box' two units to the right which lets you come
close from the left but not from the right.
A ProximitySensor can be used to track a user's movements like
entering rooms, vehicles etc. You would set up a 'proximity' box whereever
you expect the user to go through and trigger events. The ProximitySensor
can also detect when a user leaves it's sensor space.

Copyright © 1996-98
Markus Roskothen. All rights reserved.