vr2-6-06.wrl
[ VRML source code ]
#VRML V2.0 utf8
#vr2-6-06.wrl
Group {
children [
DEF LampTouch TouchSensor {}
Group {
children [
#Control Pad
Transform {
rotation 1 0 0 1.57079
children Shape {
appearance Appearance {
material DEF PadColor1 Material {
diffuseColor 0.7 0.7 0.7
}
}
geometry Cylinder {
radius 3
height 1
}
}
}
Transform {
translation 8 0 0
rotation 1 0 0 1.57079
children Shape {
appearance Appearance {
material DEF PadColor2 Material {
diffuseColor 0.7 0.7 0.7
}
}
geometry Cylinder {
radius 3
height 1
}
}
}
Transform {
translation 4 1 0
children Shape {
appearance Appearance {
material DEF PadColor3 Material {
diffuseColor 0.7 0.7 0.7
}
}
geometry Box { size 8 4 1 }
}
}
#Arrow Button
Transform {
translation 0 0 0.6
children Shape {
appearance Appearance {
material Material {
diffuseColor 1 0 1
}
}
geometry Box { size 2 0.7 0.2 }
}
}
Transform {
translation 0 0 0.6
children Shape {
appearance Appearance {
material Material {
diffuseColor 1 0 1
}
}
geometry Box { size 0.7 2 0.2 }
}
}
#button
Transform {
translation 9 1.5 0.6
scale 1 1 0.3
children Shape {
appearance Appearance {
material Material {
diffuseColor 0.7 0.1 0.1
}
}
geometry Sphere { radius 0.5 }
}
}
Transform {
translation 8 1 0.6
scale 1 1 0.3
children Shape {
appearance Appearance {
material Material {
diffuseColor 0.7 0.1 0.1
}
}
geometry Sphere { radius 0.5 }
}
}
Transform {
translation 7 0.5 0.6
scale 1 1 0.3
children Shape {
appearance Appearance {
material Material {
diffuseColor 0.7 0.1 0.1
}
}
geometry Sphere { radius 0.5 }
}
}
Transform {
translation 9 0 0.6
scale 1 1 0.3
children Shape {
appearance Appearance {
material Material {
diffuseColor 0.1 0.7 0.1
}
}
geometry Sphere { radius 0.5 }
}
}
Transform {
translation 8 -0.5 0.6
scale 1 1 0.3
children Shape {
appearance Appearance {
material Material {
diffuseColor 0.1 0.7 0.1
}
}
geometry Sphere { radius 0.5 }
}
}
Transform {
translation 7 -1 0.6
scale 1 1 0.3
children Shape {
appearance Appearance {
material Material {
diffuseColor 0.1 0.7 0.1
}
}
geometry Sphere { radius 0.5 }
}
}
#switch
Transform {
translation 3 0 0.6
scale 1 0.4 0.3
children Shape {
appearance Appearance {
material Material {
diffuseColor 0.7 0.7 0.1
}
}
geometry Sphere { radius 0.5 }
}
}
Transform {
translation 5 0 0.6
scale 1 0.4 0.3
children Shape {
appearance Appearance {
material Material {
diffuseColor 0.7 0.7 0.1
}
}
geometry Sphere { radius 0.5 }
}
}
#cable
Transform {
translation 4 4 0
children Shape {
appearance Appearance {
material Material {
diffuseColor 0.7 0.7 0.7
}
}
geometry Cylinder {
radius 0.2
height 2
}
}
}
#LR button
Transform {
translation -0.5 3 0
scale 1 0.4 0.4
rotation 0 0 1 0.2
children Shape {
appearance Appearance {
material Material {
diffuseColor 0.1 0.7 0.7
}
}
geometry Sphere { radius 1 }
}
}
Transform {
translation 8.5 3 0
scale 1 0.4 0.4
rotation 0 0 1 -0.2
children Shape {
appearance Appearance {
material Material {
diffuseColor 0.1 0.7 0.7
}
}
geometry Sphere { radius 1 }
}
}
]
}
DEF LampSwitch Script {
eventIn SFBool isActive
eventOut SFColor color
field SFColor OnColor 1 1 0
field SFColor OffColor 0.7 0.7 0.7
url "LampSwitch.class"
}
]
}
ROUTE LampTouch.isActive TO LampSwitch.isActive
ROUTE LampSwitch.color TO PadColor1.set_diffuseColor
ROUTE LampSwitch.color TO PadColor2.set_diffuseColor
ROUTE LampSwitch.color TO PadColor3.set_diffuseColor
[ Java source code ]
//LampSwitch.java
import vrml.*;
import vrml.field.*;
import vrml.node.*;
public class LampSwitch extends Script {
SFColor OnColor;
SFColor OffColor;
SFColor color;
public void initialize() {
color=(SFColor) getEventOut("color");
OnColor=(SFColor) getField("OnColor");
OffColor=(SFColor) getField("OffColor");
}
public void processEvent(Event e) {
if(e.getName().equals("isActive")){
ConstSFBool v=(ConstSFBool)e.getValue();
if(v.getValue()) color.setValue(OnColor);
else color.setValue(OffColor);
}
}
}