// This is the file interp.java import vrml.*; import vrml.node.*; import vrml.field.*; import java.lang.Math; public class interp extends Script { private ConstSFFloat set_fraction; // set_fraction as a ConstSFFloat, private float frac; // same thing as a Java float. private MFVec3f value_changed; // value_changed eventOut as MFVec3f, private float vals[][]; // same thing as a Java float array. // This function gets a handle to the value_changed eventOut // and sets up the array that will be converted to it. public void initialize() { value_changed = (MFVec3f) getEventOut("value_changed"); vals = new float[37][3]; } public void processEvent(Event e){ set_fraction = (ConstSFFloat) e.getValue(); // Get set_fraction eventIn frac = set_fraction.getValue(); // Convert it from SFFloat to java float // Compute the array entries as before (0.3f means 0.3 as a float, // 0.3 by itself means double). for (int i = 0; i < 37; i++) { vals[i][0] = 0.23f * i - 4.23f; vals[i][1] = 0.0f; vals[i][2] = (float)Math.sin((i/9.0f - frac*2.0f) * 3.14f); } vals[0][0] = -4.1f; vals[4][2] = (vals[5][2] + vals[4][2])/2.0f; vals[3][2] = vals[4][2]; vals[2][2] = vals[3][2]; vals[1][2] = vals[2][2]; vals[0][2] = vals[1][2]; value_changed.setValue(vals); // Save the vals array in the eventOut } }