Simple example of Improv actor authored in Java



import vrml.external.field.*;
import vrml.external.Node;
import vrml.external.Browser;
import vrml.external.exception.*;
import netscape.javascript.JSObject;

import improv.actor.*;
import improv.actor.behavior.*;
import improv.event.*;
import improv.misc.NYUSplashScreen;
import improv.util.gui.*;
import improv.util.*;

import java.util.Hashtable;
import java.applet.Applet;

public final class demo extends Applet implements EventOutObserver,ImprovObserver
{
   
   private Actor actor;         // The actor
   private Hashtable actorTable;
   private EventOut time;
   private Applet applet;
   private boolean initialized = false;

   // The EventOuts.   These allow users to set filter values from the VRML scene.
   
   private LayerPanel panel;
   private ImprovEditor editor;
   private NYUSplashScreen splash = new NYUSplashScreen(this);
   int numActors = 0;

   // Stuff to get a handle to the VRML scene

   private JSObject win;    // The Netscape Window
   private Browser browser; // The VRML Browser

   // The vrml nodes

   private Node rootNode;
   private Node body;
   private Node head;
   private Node leftEyeStalk;
   private Node rightEyeStalk;
   private Node leftEye;
   private Node rightEye;
   private Node leftPupil;
   private Node rightPupil;
   private Node timeNode;

   // The VRML scene EventIns (which will be modified by the channel values)
   
   private EventInSFVec3f rootTransEI;
   private EventInSFRotation rootRotEI;
   private EventInSFRotation bodyRotEI;
   private EventInSFRotation headRotEI;
   private EventInSFRotation leftEyeStalkRotEI;
   private EventInSFRotation rightEyeStalkRotEI;
   private EventInSFRotation leftEyeRotEI;
   private EventInSFRotation rightEyeRotEI;
   private EventInSFVec3f leftPupilScaleEI;
   private EventInSFVec3f rightPupilScaleEI;   
   
   // The Improv channels

   private SFVec3fChannel rootTrans;
   private SFRotationChannel rootRot;
   private SFRotationChannel bodyRot;
   private SFRotationChannel headRot;
   private SFRotationChannel leftEyeStalkRot;
   private SFRotationChannel rightEyeStalkRot;
   private SFRotationChannel leftEyeRot;
   private SFRotationChannel rightEyeRot;
   private SFVec3fChannel leftPupilScale;
   private SFVec3fChannel rightPupilScale;

   // The Layers

   private Layer background,layer1,layer2;

   public void init() {
      browser = Browser.getBrowser(this);
      try {

         // Get Nodes from scene

         rootNode = browser.getNode("ROOT");
         body = browser.getNode("Body");         
         head = browser.getNode("Head");         
         leftEyeStalk = browser.getNode("LeftEyeStalk");         
         rightEyeStalk = browser.getNode("RightEyeStalk");         
         leftEye = browser.getNode("LeftEye");         
         rightEye = browser.getNode("RightEye");         
         leftPupil = browser.getNode("LeftPupil");         
         rightPupil = browser.getNode("RightPupil");

         // Create Actor

         actor = new Actor("Ned", splash);

         // Create Channels;

         rootTrans = new SFVec3fChannel("root translation");
         rootTransEI = (EventInSFVec3f)rootNode.getEventIn("set_translation");
         rootTrans.addObserver(this,rootTransEI);
         actor.addChannel(rootTrans);

         rootRot = new SFRotationChannel("root Rotation");
         rootRotEI = (EventInSFRotation)rootNode.getEventIn("set_rotation");
         rootRot.addObserver(this,rootRotEI);
         actor.addChannel(rootRot);

         bodyRot = new SFRotationChannel("body Rotation");
         bodyRotEI = (EventInSFRotation)body.getEventIn("set_rotation");
         bodyRot.addObserver(this,bodyRotEI);
         actor.addChannel(bodyRot);

         headRot = new SFRotationChannel("head Rotation");
         headRotEI = (EventInSFRotation)head.getEventIn("set_rotation");
         headRot.addObserver(this,headRotEI);
         actor.addChannel(headRot);

         leftEyeStalkRot = new SFRotationChannel("left eye stalk Rotation");
         leftEyeStalkRotEI = (EventInSFRotation)leftEyeStalk.getEventIn("set_rotation");
         leftEyeStalkRot.addObserver(this,leftEyeStalkRotEI);
         actor.addChannel(leftEyeStalkRot);

         rightEyeStalkRot = new SFRotationChannel("right eye stalk Rotation");
         rightEyeStalkRotEI = (EventInSFRotation)rightEyeStalk.getEventIn("set_rotation");
         rightEyeStalkRot.addObserver(this,rightEyeStalkRotEI);
         actor.addChannel(rootTrans);

         leftEyeRot = new SFRotationChannel("left eye Rotation");
         leftEyeRotEI = (EventInSFRotation)leftEye.getEventIn("set_rotation");
         leftEyeRot.addObserver(this,leftEyeRotEI);
         actor.addChannel(rightEyeStalkRot);

         rightEyeRot = new SFRotationChannel("right eye Rotation");
         rightEyeRotEI = (EventInSFRotation)rightEye.getEventIn("set_rotation");
         rightEyeRot.addObserver(this,rightEyeRotEI);
         actor.addChannel(rightEyeRot);

         leftPupilScale = new SFVec3fChannel("left pupil scale");
         leftPupilScaleEI = (EventInSFVec3f)leftPupil.getEventIn("set_scale");
         leftPupilScale.addObserver(this,leftPupilScaleEI);
         actor.addChannel(leftPupilScale);

         rightPupilScale = new SFVec3fChannel("right pupil scale");
         rightPupilScaleEI = (EventInSFVec3f)rightPupil.getEventIn("set_scale");
         rightPupilScale.addObserver(this,rightPupilScaleEI);
         actor.addChannel(rightPupilScale);

         // Add the layers
         
         State bg,def,lookLeft,lookRight,forward,eyesIn,eyesLeft,eyesRight;

// LAYER: Background

         background = actor.addLayer("Background");

   // STATE: Background

         bg = new State("Background");

         SFRotationFilter rot[] = new SFRotationFilter[7];

         rot[0] = new SFRotationFilter(rootRot,0,0,0);
         rot[1] = new SFRotationFilter(bodyRot,0,0,0);
         rot[2] = new SFRotationFilter(headRot,0,0,0);
         rot[3] = new SFRotationFilter(leftEyeStalkRot,0,0,0);
         rot[4] = new SFRotationFilter(rightEyeStalkRot,0,0,0);
         rot[5] = new SFRotationFilter(leftEyeRot,0,0,0);
         rot[6] = new SFRotationFilter(rightEyeRot,0,0,0);

         for(int i=0;i