import java.applet.Applet; import java.awt.*; import java.awt.event.*; import vrml.external.*; import vrml.external.field.*; import vrml.external.exception.*; public class EAITest extends Applet implements EventOutObserver { TextField eaiText; TextField renderText; Browser browser; EventInMFVec3f sphereCoord; int frames = 0; long lastTime = 0; float[][] spherePoints; float[][] kv1; public void init() { GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); setLayout(gridbag); c.anchor = GridBagConstraints.CENTER; c.fill = GridBagConstraints.NONE; c.weightx = .5f; c.weighty = .5f; eaiText = new TextField(25); add(eaiText, c); c.gridx = 1; renderText = new TextField(25); add(renderText, c); if (!getBrowser(this)) { System.out.println("ERROR: Browser not found."); return; } Node n = null; for (int i=0; i<120; i++) { try { n = browser.getNode("sphereCoord1"); } catch(Exception ex) { n = null; } if (n != null) break; try { Thread.sleep(500); } catch (InterruptedException ie) { } } // Coodinate node's point field sphereCoord = (EventInMFVec3f)n.getEventIn("point"); // default sphere coordinate points kv1 = ((EventOutMFVec3f)n.getEventOut("point")).getValue(); // place holder for interpolated coordinate points spherePoints = ((EventOutMFVec3f)n.getEventOut("point")).getValue(); // monitor Timer's fraction_changed field ((EventOutSFFloat)browser.getNode("Timer").getEventOut("fraction_changed")).advise(this, null); } public void callback(EventOut value, double time, Object route) { // every 30 times the callback is called, display frame rate information if (++frames == 30) { // calculate the elasped time and display the frame rate for the EAI callback long curr = System.currentTimeMillis(); eaiText.setText("EAI fps("+String.valueOf((float)frames/(float)(curr - lastTime)*1000)+")"); lastTime = curr; // query and display the browser's frame rate renderText.setText("rendering fps("+String.valueOf(browser.getCurrentFrameRate())+")"); frames = 0; } // interpolate based on Timer's fraction_changed float fraction = ((EventOutSFFloat)value).getValue(); // from 0 to .5 interpolate points from the default sphere to the wacky morph if (fraction < .5) interpolate(spherePoints, kv1, kv2, fraction*2); // from .5 to 1 interpolate points from the wacky morph back to the default sphere else interpolate(spherePoints, kv2, kv1, fraction*2-1f); // send interpolated points back out to VRML wrl sphereCoord.setValue(spherePoints); } public void interpolate(float[][] result, float[][] from, float[][] to, float t) { for (int i=0; i