|
|
Constraints
By defining constraints (limits) to the transformation of an object, you can control how the object can be interacted with. PlaneSensors, SphereSensors, and CylinderSensorsRecall that PlaneSensors, SphereSensors and CylinderSensors can be used to directly manipulate objects. You can constrain the effect of these sensors by setting exposedFields for these sensors. The PlaneSensor has minPosition and maxPosition exposedFields that are used to specify the X and Y translation limits. For example:
PlaneSensor {
minPosition -1 -1
maxPosition 1 1
}
The CylinderSensor has maxAngle and minAngle exposedFields that limit how far you can rotate the virtual cylinder.
#VRML V2.0 utf8
Group {
children [
DEF GreenBox Transform {
children [
Shape {
appearance Appearance {
material Material {
diffuseColor 0.0 1.0 0.0
}
}
geometry Box {
}
}
]
},
DEF Drag CylinderSensor {
maxAngle 1.571
minAngle 0.0
}
]
}
ROUTE Drag.rotation_changed TO GreenBox.set_rotation
The SphereSensor has no built-in constraints, so to constrain a SphereSensor, you need to use a Script. Adding Constraints using ScriptsArbitrarily complex contraints can be implemented using Script nodes. For example, a SphereSensor's rotation_changed value can be routed to a Transform group via a Script node instead of directly, and the Script can then determine what values are permitted to be passed on to the Transform group. Scripts can also be used to determine when to enable/disable sensors, adding further constraints to the user's interaction with the virtual environment. For example, clicking on a button shape could cause a script to enable a PlaneSensor, allowing another shape to be moved around, while clicking on the button again could lock the shape in position by disabling the PlaneSensor. |
|
|
Michael Louka, October 10, 2001 |