// GetNodeInfoS.java: Applet to control the Get Node Info demo // inspired by the descent applet ../descent/* // Daniel.Schneider@tecfa.unige.ch 2/98 // hmm actually this applet doesn't do anything of interest besides // demoing how to to retrieve information from a VRML node. // The GetNodeInfo.java applet will add some usefule error checking to this. import java.awt.*; import java.applet.*; import java.awt.event.*; import vrml.external.field.*; import vrml.external.Node; import vrml.external.Browser; import vrml.external.exception.*; public class GetNodeInfoS extends Applet implements ActionListener{ // The Browser Browser browser = null; // Various UI widgets Button getInfoButton; TextArea output = null; // Various stuff in the VRML scene we hang on to Node entryVP = null; EventOutSFVec3f positionVP = null; EventOutSFRotation orientationVP = null; // Variables to store current position and orientation float[] currentPosition; float[] currentOrientation; /** Initialize the Applet */ public void init() { // Connect to the browser browser = Browser.getBrowser(this); // Add the output pane and the button to the Java Panel output = new TextArea(5, 60); add(output); add (getInfoButton = new Button("Where Am I ?")); // register the button for event handling getInfoButton.addActionListener(this); // Initialize some VRML stuff initScene(); } /** Get reference to stuff in the VRML scene */ public void initScene() { // Get the ViewPoints entryVP = browser.getNode("Entry"); System.out.println("ViewPoint Node " + entryVP + " found."); positionVP = (EventOutSFVec3f) entryVP.getEventOut("position_changed"); orientationVP = (EventOutSFRotation) entryVP.getEventOut("orientation_changed"); } /** Handle actions from AWT widgets */ public void actionPerformed (ActionEvent event) { Object clickedButton = event.getSource(); if (clickedButton == getInfoButton) { currentPosition = positionVP.getValue(); currentOrientation = orientationVP.getValue(); output.append("Entry ViewPoint is at" + " x=" + currentPosition [0] + " y=" + currentPosition [1] + " z=" + currentPosition [2] + "\n"); output.append("Entry Viewpoint Orientation is" + " x=" + currentOrientation [0] + " y=" + currentOrientation [1] + " z=" + currentOrientation [2] + " angle=" + currentOrientation [3] + "\n"); } } }