home *** CD-ROM | disk | FTP | other *** search
/ The Best of Windows 95.com 1996 September / WIN95_09962.iso / vrml / cp2b2x.exe / DATA.Z / origami.java < prev    next >
Text File  |  1996-06-21  |  3KB  |  118 lines

  1. /*-----------------------------------------------------------------------------
  2.  * Copyright(C) 1995,1996 Sony Corporation
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Sony Corporation;
  6.  * the contents of this file is not to be disclosed to third parties, copied
  7.  * or duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Sony Corporation.
  9.  *
  10.  * File:   origami.java
  11.  * Auther: sugino
  12.  *----------------------------------------------------------------------------*/
  13. import vrml.*;
  14.  
  15. public class origami extends Script {
  16.  
  17.     SFInt32     paperChild = (SFInt32) getEventOut("paperChild");
  18.     SFBool      timerOn    = (SFBool)  getEventOut("timerOn");
  19.     SFRotation  birdRotation = (SFRotation) getEventOut("birdRotation");
  20.  
  21.     SFTime      bgmStop  = (SFTime) getEventOut("bgmStop");
  22.     SFTime      bgmStart  = (SFTime) getEventOut("bgmStart");
  23.     SFTime      gusyaStop  = (SFTime) getEventOut("gusyaStop");
  24.     SFTime      gusyaStart  = (SFTime) getEventOut("gusyaStart");
  25.  
  26.     /* number of child  */
  27.     int max = 8;
  28.     /* current child no */
  29.     int current = 0;
  30.  
  31.     int xrollMax = 60;
  32.     int xroll = 0;
  33.  
  34.     int yrollMax = 60;
  35.     int yroll = 0;
  36.  
  37.     boolean rolling= false;
  38.  
  39.     final int rollingX = 1;
  40.     final int rollingY = 2;
  41.  
  42.     int rollmode = rollingX;
  43.  
  44.     float rotation[] = new float[4];
  45.  
  46.     float piV = (float)Math.PI/180.0f ;
  47.     float xaRad = (360.0f/(float)xrollMax);
  48.     float yaRad = (360.0f/(float)yrollMax);
  49.  
  50.     public void clicked (ConstSFBool press, ConstSFTime t) {
  51.         if(press.getValue()) return ;
  52.  
  53.     if(rolling) {
  54.         rolling=false;
  55.         bgmStop.setValue(t.getValue());
  56.     }
  57.     else {
  58.         rolling=true;
  59.             gusyaStart.setValue(t.getValue());
  60.         bgmStart.setValue(t.getValue());
  61.     }
  62.     timerOn.setValue(rolling);
  63.     nextChild(t);
  64.     }
  65.  
  66.     public void roll(ConstSFTime t, ConstSFTime now){
  67.  
  68.     rotation[0]=rotation[1]=rotation[2]=0.0f;
  69.     if(rollmode == rollingX){
  70.         if(xroll < xrollMax) {
  71.         xroll++;
  72.         }
  73.         else {
  74.         xroll = 0;
  75.         rollmode = rollingY;
  76.         }
  77.     }
  78.     else {
  79.         if(yroll < yrollMax) {
  80.         yroll++;
  81.         }
  82.         else {
  83.         yroll = 0;
  84.         nextChild(now);
  85.         rollmode = rollingX;
  86.         }
  87.     }    
  88.     if(rollmode == rollingX){
  89.         rotation[0]=1.0f;
  90.         rotation[3]= (piV*(xaRad*(float)xroll)) ;
  91.     }
  92.     else {
  93.         rotation[1]=1.0f;
  94.         rotation[3]= (piV*(yaRad*(float)yroll)) ;
  95.     }
  96.  
  97.     birdRotation.setValue(rotation);
  98.     }
  99.     void nextChild(ConstSFTime t){
  100.     gusyaStop.setValue(t.getValue()-3);    
  101.     gusyaStart.setValue(t.getValue());    
  102.     if(current < max-1) current++ ;
  103.     else {
  104.         current =0;
  105.         rolling = false;
  106.         timerOn.setValue(rolling);
  107.         bgmStop.setValue(t.getValue());
  108.     }
  109.     paperChild.setValue(current);
  110.     }    
  111. }
  112.  
  113.     
  114.  
  115.  
  116.  
  117.  
  118.