import vrml.*;
import vrml.node.*;
import vrml.field.*;

public class ChangePosition extends Script {
  SFVec3f newPosition;
  Node me;
  float [] current_position = new float [3];
  
  public void initialize() {
    SFNode sf_me;

    sf_me = (SFNode) getField("me");
    me = (Node) sf_me.getValue();
    newPosition = (SFVec3f) getEventOut("newValue");
  }
  
  public void processEvent(Event e) {
    
    System.out.println("CubeChangePosition received event : " +
		       e.getName());
    
    if (e.getName().equals("execute")) {
      ConstSFBool v = (ConstSFBool) e.getValue();
      if (v.getValue()) {
	((SFVec3f) 
	 me.getExposedField("translation")).getValue(current_position);
	current_position[0] = current_position[0] + 2.0f;
	newPosition.setValue(current_position);
      }
    }
  }
}
