home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-10-16 | 2.3 KB | 85 lines |
- import vrml.*;
- import vrml.node.*;
- import vrml.field.*;
-
- public class open extends Script {
- SFTime triggerOpen;
- SFVec3f camMove;
- SFFloat sandFraction;
- SFFloat quakeFraction;
- SFFloat lionFraction;
- ConstSFVec3f personPosition;
- MFVec3f lionPath;
-
- float[][] lionPathA = new float[4][3];
-
- boolean first = true;
- int disaster = -1;
- java.util.Random r_g = new java.util.Random();
-
-
- public void initialize() {
- triggerOpen = (SFTime)getEventOut("triggerOpen");
- camMove = (SFVec3f)getEventOut("camMove");
- sandFraction = (SFFloat)getEventOut("sandFraction");
- lionFraction = (SFFloat)getEventOut("lionFraction");
- lionPath = (MFVec3f)getEventOut("lionPath");
- quakeFraction = (SFFloat)getEventOut("quakeFraction");
-
- lionPathA[1][0] = 12.0f;
- lionPathA[1][1] = 1.5f;
- lionPathA[1][2] = -18.0f;
- lionPathA[0][0] = 999f;
- lionPathA[0][1] = 999f;
- lionPathA[0][2] = 999f;
- lionPathA[3][0] = 999f;
- lionPathA[3][1] = 999f;
- lionPathA[3][2] = 999f;
-
- }
-
- public void processEvent(Event e) {
- if (e.getName().equals("tick")) {
- if (first == true) {
- triggerOpen.setValue((ConstSFTime)e.getValue());
- first = false;
- }
-
- }
- if (e.getName().equals("setDisaster")) {
- float roll = r_g.nextFloat();
- if (roll < 0.333) {
- disaster = 1;
- } else if (roll < 0.666) {
- disaster = 2;
- } else {
- disaster = 3;
- }
- }
- if (e.getName().equals("disasterFraction")) {
- if (disaster == 1)
- sandFraction.setValue((ConstSFFloat)e.getValue());
- if (disaster == 2) {
- lionFraction.setValue((ConstSFFloat)e.getValue());
- }
- if (disaster == 3) {
- quakeFraction.setValue((ConstSFFloat)e.getValue());
- }
- }
- if (e.getName().equals("sandInput")) {
- camMove.setValue((ConstSFVec3f)e.getValue());
- }
- if (e.getName().equals("quakeInput")) {
- camMove.setValue((ConstSFVec3f)e.getValue());
- }
- if (e.getName().equals("personMoved")) {
- personPosition = (ConstSFVec3f)e.getValue();
- lionPathA[2][0] = personPosition.getX();
- lionPathA[2][1] = 1.5f;
- lionPathA[2][2] = personPosition.getZ();
- lionPath.setValue(lionPathA);
- }
- }
-
- }
-