home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-02-21 | 2.6 KB | 77 lines |
- // A "thing" -- a wrapper around a VRML object
-
- // Written by Bernie Roehl, January 1996
-
- import vrml.external.Browser;
- import vrml.external.Node;
- import vrml.external.field.*;
- import vrml.external.exception.*;
- import multi.*;
-
- public class Thing {
- protected Node transformNode;
- protected Node switchNode;
- protected EventInSFVec3f set_translation;
- protected EventInSFRotation set_rotation;
- protected EventInSFInt32 set_switch;
- protected EventInMFNode remove;
-
- public void setLocation(Vec3 loc) {
- float[] value = new float[3];
- value[0] = loc.getX();
- value[1] = loc.getY();
- value[2] = loc.getZ();
- set_translation.setValue(value);
- }
-
- public void setOrientation(Rotation ori) {
- float[] value = new float[4];
- value[0] = ori.getX();
- value[1] = ori.getY();
- value[2] = ori.getZ();
- value[3] = ori.getAngle();
- set_rotation.setValue(value);
- }
-
- public void setVisibility(boolean visible) {
- set_switch.setValue(visible ? 0 : -1);
- }
-
- public Thing(Browser browser, EventInMFNode add,
- EventInMFNode remove, String url)
- throws InvalidVrmlException, InvalidEventInException {
- Node[] nodes;
- EventInMFNode nodeIn;
- // create Transform node
- nodes = browser.createVrmlFromString("Transform { }");
- transformNode = nodes[0];
- add.setValue(nodes);
- // create Switch node
- nodes = browser.createVrmlFromString("Switch { whichChoice 0 }");
- switchNode = nodes[0];
- // put Switch into Transform
- nodeIn = (EventInMFNode) transformNode.getEventIn("addChildren");
- nodeIn.setValue(nodes);
- // create Inline node
- // here's the bug: if I use an Inline, the ProximitySensor that I'm using
- // to find the user's location stops working :-(
- // nodes = browser.createVrmlFromString("Inline { url \"" + url + "\" }");
- nodes = browser.createVrmlFromString("Shape { geometry Cylinder { } }");
- // put Inline into Switch
- nodeIn = (EventInMFNode) switchNode.getEventIn("choice");
- nodeIn.setValue(nodes);
- // get EventIns
- set_translation = (EventInSFVec3f) transformNode.getEventIn("translation");
- set_rotation = (EventInSFRotation) transformNode.getEventIn("rotation");
- set_switch = (EventInSFInt32) switchNode.getEventIn("whichChoice");
- System.out.println("Added new entity from url " + url);
- }
-
- public void finalize() {
- Node[] nodes = new Node[1];
- nodes[0] = transformNode;
- remove.setValue(nodes);
- }
- }
-
-