home *** CD-ROM | disk | FTP | other *** search
/ Sony Community Place / circus2e.exe / DATA.Z / avatar.java < prev    next >
Text File  |  1996-09-25  |  7KB  |  246 lines

  1. //
  2. // avatar.java
  3. //    action, set avatar color, smooth move
  4. //
  5. // (c) Copyright 1996 Sony Corporation. All rights reserved.
  6.  
  7. import vs.*;
  8. import vrml.*;
  9. import vrml.field.*;
  10. import vrml.node.*;
  11.  
  12. public class avatar extends Script {
  13.     private SFFloat  value; 
  14.     private SFTime helloStart;
  15.     private SFTime smileStart;
  16.     private SFTime woooStart;
  17.     private SFTime waoStart;
  18.     private SFTime ummStart;
  19.     private SFTime sadStart;
  20.     private SFBool timerOn;
  21.     private SFTime timerStart;
  22.     private SFBool timerwOn;
  23.     private SFTime timerwStart;
  24.     private MFVec3f avatarTrans;
  25.     private SFVec3f avatarDirect;
  26.     private SFRotation avatarRot;
  27.  
  28.     private static String ActionList[] = {
  29.         "Hello",
  30.         "Smile",
  31.         "Wao",
  32.         "Umm",
  33.         "Wooo",
  34.         "Sad",
  35.         "Bye", 
  36.         "Sleep",
  37.         "Normal", };
  38.  
  39.    
  40.     private float tmpArray[][];
  41.     private double vector[];
  42.     private float dist[];
  43.     private double length;
  44.     private boolean start = true;
  45.     private float  key = 0.0f;
  46.     private int parity = 0;
  47.     private int flag = 0;
  48.     private int counter = 0;   
  49.  
  50.     // to change color
  51.     final int PARTS_MAX = 18;
  52.     SFColor newColor[] = new SFColor [ PARTS_MAX ];
  53.     final int cBase = '0';
  54.     final int COLOR_MAX = 18;
  55.  
  56.    
  57.    public void initialize() {
  58.     String str;
  59.  
  60.         value =  (SFFloat) getEventOut("value");
  61.         helloStart = (SFTime) getEventOut("helloStart");
  62.         smileStart = (SFTime) getEventOut("smileStart");
  63.         woooStart = (SFTime) getEventOut("woooStart");
  64.         waoStart = (SFTime) getEventOut("waoStart");
  65.         ummStart = (SFTime) getEventOut("ummStart");
  66.         sadStart = (SFTime) getEventOut("sadStart");
  67.         timerOn   = (SFBool) getEventOut("timerOn");
  68.         timerStart = (SFTime) getEventOut("timerStart");
  69.         timerwOn   = (SFBool) getEventOut("timerwOn");
  70.         timerwStart = (SFTime) getEventOut("timerwStart");
  71.         avatarTrans = (MFVec3f) getEventOut("avatarTrans");
  72.         avatarDirect = (SFVec3f) getEventOut("avatarDirect");
  73.         avatarRot = (SFRotation) getEventOut("avatarRot");
  74.  
  75.         tmpArray = new float[2][3];
  76.         vector = new double[3];
  77.         dist = new float[3];
  78.  
  79.     for( int i = 0; i < PARTS_MAX; i++ ){
  80.         str = "part" + i;
  81.         newColor[ i ] = (SFColor)getEventOut( str );
  82.     }
  83.    }
  84.  
  85.    public void timeOut(ConstSFTime t, double now) {
  86.        if(parity == 1) {
  87.            key = 0.0f;
  88.            value.setValue(key);
  89.            parity = 0;
  90.        } else if ( key == 0.0f) {
  91.            parity = 0;
  92.        } else {
  93.            parity = 1;
  94.        }      
  95.    }
  96.  
  97.    public void sonyAvatarPosture(ConstSFString action, double t){
  98.             String actionName = action.getValue();
  99.        if (actionName.equals( ActionList[0])) {
  100.            key = 0.04f;
  101.            value.setValue(key);
  102.            helloStart.setValue(t); 
  103.        } else if ( actionName.equals( ActionList[1])) {
  104.            key = 0.05f;
  105.            value.setValue(key);
  106.            smileStart.setValue(t); 
  107.        } else if ( actionName.equals( ActionList[2])) {
  108.            key = 0.07f;
  109.            value.setValue(key);
  110.            waoStart.setValue(t); 
  111.        } else if ( actionName.equals( ActionList[3])) {
  112.            key = 0.06f;
  113.            value.setValue(key);
  114.            woooStart.setValue(t); 
  115.        } else if ( actionName.equals( ActionList[4])) {
  116.            key = 0.08f;
  117.            value.setValue(key);
  118.            ummStart.setValue(t); 
  119.        } else if ( actionName.equals( ActionList[5])) {
  120.            key = 0.09f;
  121.            value.setValue(key);
  122.            sadStart.setValue(t); 
  123.        } else if ( actionName.equals( ActionList[6])) {
  124.            key = 0.12f;
  125.            value.setValue(key);
  126.        } else if ( actionName.equals( ActionList[7])) {
  127.            key = 0.13f;
  128.            value.setValue(key);
  129.        } else if ( actionName.equals( ActionList[8])) {
  130.            key = 0.0f;
  131.            value.setValue(key);
  132.        } else {
  133.            key = 0.0f;
  134.            value.setValue(key);
  135.        }
  136.        if (key == 0.13f ) {
  137.        } else {
  138.           timerStart.setValue(t);
  139.           timerOn.setValue(start);
  140.        }
  141.     }
  142.  
  143.     public void timewOut(ConstSFTime t, double now) {
  144.        if(counter == 1) {
  145.            flag = 0;
  146.        } else if (flag == 0) {
  147.            counter = 0;
  148.        } else {
  149.            counter = 1;
  150.        }     
  151.     }
  152.  
  153.     public void sonyAvatarVector(ConstMFVec3f avtPosition, double t){
  154.        avtPosition.getValue(tmpArray);
  155.  
  156.        vector[0] = (tmpArray[1][0] - tmpArray[0][0]);
  157.        vector[1] = (tmpArray[1][1] - tmpArray[0][1]);
  158.        vector[2] = (tmpArray[1][2] - tmpArray[0][2]);
  159.  
  160.        dist[0] = tmpArray[1][0];
  161.        dist[1] = tmpArray[1][1];
  162.        dist[2] = tmpArray[1][2];
  163.  
  164.        length = Math.sqrt(vector[0]*vector[0] + vector[1]*vector[1] + vector[2]*vector[2]);
  165.  
  166.        if (false) {
  167.           if (flag == 0) {
  168.              avatarTrans.setValue(tmpArray);
  169.              timerwStart.setValue(t);
  170.              timerwOn.setValue(start);
  171.              flag = 1;
  172.              counter = 0;
  173.           }
  174.        } else {
  175.           avatarDirect.setValue(dist);
  176.        }
  177.     }      
  178.  
  179.     public void sonyAvatarAttribute(ConstSFString action, double t){
  180.        String actionName = action.getValue();
  181.        String colorstr = actionName.substring(8);
  182.  
  183.        if (actionName.startsWith("sleep:1 ")) {
  184.            key = 0.13f;
  185.        } else {
  186.            key = 0.0f;
  187.        }
  188.        value.setValue(key);
  189.  
  190.     // set avater color
  191.     setcolor( colorstr );
  192.     }
  193.  
  194.     // set color to avater parts
  195.     public void setcolor ( String colorString ){
  196.     String str;
  197.     SFInt32 colorNo;
  198.     float f[] = new float[ 3 ];
  199.  
  200.     // decode
  201.     if ( colorString.length() < PARTS_MAX ){
  202.         // default color
  203.         System.out.println ( "default color "  );
  204.         
  205.     }
  206.     else{
  207.         System.out.println ( "set color: " + colorString  );
  208.         for ( int i = 0; i < PARTS_MAX; i++ ){
  209.             int decode = (int) colorString.charAt( i ) - cBase;
  210.  
  211.             // set diffuse color
  212.             if ( decode < COLOR_MAX ){
  213.                 f = GenerateColor.getSFColor( decode );
  214.                 newColor[ i ].setValue( f );
  215.             }
  216.         }
  217.     }
  218.     }
  219.  
  220.     public void processEvent(Event e) {
  221.        String name = e.getName();
  222.  
  223.        if (name.equals("sonyAvatarPosture")) {
  224.            sonyAvatarPosture((ConstSFString)e.getValue(), e.getTimeStamp());
  225.        } else if (name.equals("sonyAvatarVector")) {
  226.            sonyAvatarVector((ConstMFVec3f)e.getValue(), e.getTimeStamp());
  227.        } else if (name.equals("timeOut")) {
  228.            timeOut((ConstSFTime)e.getValue(), e.getTimeStamp());
  229.        } else if (name.equals("timewOut")) {
  230.            timewOut((ConstSFTime)e.getValue(), e.getTimeStamp());
  231.        } else if (name.equals("sonyAvatarAttribute")) {
  232.            sonyAvatarAttribute((ConstSFString)e.getValue(), e.getTimeStamp());
  233.        }
  234.  
  235.     }         
  236.  
  237. }
  238.  
  239.     
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.