Explanations on ex-script-touchcube.wrl and extouchcube.java [return]
The ex-scrip-touchcube.wrl program defines a cone and a cube.
The cube changes its color if touched (right mouse button)
according to the myColor interpolator node (ROUTES TS.touchtime
and myClock.fraction).
The cone is continuously rotating unless the cube has more than
50% of red. The rotation is accomplished by the ENGINE OrientationInterpolator
controled by XTIMER (ROUTE XTIMER.fraction).
The cone's stop is controlled by the script by means of the ROUTE
SC.isRed which receives its present value of the script program.
The script program has the following statements : [Java source]
- link to the vrml library :
- import vrml.*;
- import vrml.field.*;
- import vrml.node.*;
- routine name : public class extouchcube extends Script {
- parameters declaration
- private SFColor currentColor; // field
- private SFBool isRed; eventOut
- routine initialization part (currentColor and isRed)
- public void initialize() {
- currentColor = (SFColor) getField("currentColor");
- isRed = (SFBool) getEventOut("isRed");}
- routine main part : this part will be executed when colorIn event occurs
public void processEvent(Event e) {
- currentColor.setValue((ConstSFColor)e.getValue()) // get present color value
- public void eventsProcessed() { // set eventOut value (isRed parameter)
if (currentColor.getRed() >= 0.5) // red greather than 50%
isRed.setValue(false);
else isRed.setValue(true);
}
}
The following figure shows the events configuration :