Node material = null;
material = browser.getNode("MAT");
Material {
exposedField SFFloat ambientIntensity 0.2 # [0,1]
exposedField SFColor diffuseColor 0.8 0.8 0.8 # [0,1]
[ .... ]
exposedField SFFloat transparency 0 # [0,1]
}
EventInSFColor diffuseColor = null;
diffuseColor = (EventInSFColor) material.getEventIn("set_diffuseColor");
float[] color = new float[3];
......
diffuseColor = (EventInSFColor) material.getEventIn("set_diffuseColor");
......
color[0] = 0.2f; color[1] = 0.2f; color[2] = 0.8f;
diffuseColor.setValue(color);
add(redButton = new Button("Red"));
redButton.addActionListener(this);
......
public void actionPerformed (ActionEvent event) {
Object clickedButton = event.getSource();
if (clickedButton == redButton) {
color[0] = 0.8f; color[1] = 0.2f; color[2] = 0.2f;
diffuseColor.setValue(color);
}
Node entryVP = null;
EventOutSFVec3f positionVP = null;
.....
entryVP = browser.getNode("Entry");
positionVP =(EventOutSFVec3f) entryVP.getEventOut("position_changed");
float[] currentPosition;
currentPosition = positionVP.getValue();
// et on fait quelque chose (ici écrire dans un textarea)
output.append("Entry ViewPoint is at" +
" x=" + currentPosition [0] +
" y=" + currentPosition [1] +
" z=" + currentPosition [2] + "\n");
Node[] scene = null;
scene = browser.createVrmlFromString(
"DEF Camera Viewpoint {\n" +
" position 0 0 5}\n" +
"DEF MySphere Transform {\n" +
" children [ \n" +
......
" ] \n" +
" } \n"
);
browser.replaceWorld(scene);
Group {
eventIn MFNode addChildren
eventIn MFNode removeChildren
exposedField MFNode children []
field SFVec3f bboxCenter 0 0 0 # (-,)
field SFVec3f bboxSize -1 -1 -1 # (0,) or -1,-1,-1
}
Node root = browser.getNode("ROOT");
// EventIns of the root node
EventInMFNode addChildren;
EventInMFNode removeChildren;
// Instantiate (get handle to) the EventIn objects
addChildren = (EventInMFNode) root.getEventIn("addChildren");
removeChildren = (EventInMFNode) root.getEventIn("removeChildren");
if (b == addButton) {
addChildren.setValue(shape);
}
else if (b == removeButton) {
removeChildren.setValue(shape);
}
// Shape group hierarchy
Node[] shape;
shape = browser.createVrmlFromString("Shape {\n" +
" appearance Appearance {\n" +
" material Material {\n" +
" diffuseColor 0.2 0.2 0.8\n" +
" }\n" +
" }\n" +
" geometry Sphere {}\n" +
"}\n");
Node sensor = browser.getNode("TOUCH");
// Get its isActive EventOut
isActive = (EventOutSFBool) sensor.getEventOut("isActive");
// Set up the callback
isActive.advise(this, isActive);
public void callback(EventOut who, double when, Object which) {
// retrieve the state of isActive (see above the advise function)
EventOutSFBool state = (EventOutSFBool) which;
// only deal with the event if isActive was true, else the ball would flip back
if (state.getValue() == true) {
System.out.println("callback(): EventOut=" + who
+ " state =" + state.getValue());
// Change the color and remember it
if (colorState == 1) {
diffuseColor.setValue(redColor);
colorState = 0;
}
else {
diffuseColor.setValue(greenColor);
colorState = 1;
} } }