home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-09-25 | 3.2 KB | 143 lines |
- /*-----------------------------------------------------------------------------
- * Copyright(C) 1996 Sony Corporation. All rights reserved.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Sony Corporation;
- * the contents of this file is not to be disclosed to third parties, copied
- * or duplicated in any form, in whole or in part, without the prior written
- * permission of Sony Corporation.
- *
- * File: origami.java
- * Auther: sugino
- *----------------------------------------------------------------------------*/
- import vrml.*;
- import vrml.node.*;
- import vrml.field.*;
-
- public class origami extends Script {
-
- SFInt32 paperChild;
- SFBool timerOn ;
- SFRotation birdRotation;
-
- SFTime bgmStop ;
- SFTime bgmStart ;
- SFTime gusyaStop ;
- SFTime gusyaStart ;
-
- /* number of child */
- int max = 8;
- /* current child no */
- int current = 0;
-
- int xrollMax = 60;
- int xroll = 0;
-
- int yrollMax = 60;
- int yroll = 0;
-
- boolean rolling= false;
-
- final int rollingX = 1;
- final int rollingY = 2;
-
- int rollmode = rollingX;
-
- float rotation[] = new float[4];
-
- float piV = (float)Math.PI/180.0f ;
- float xaRad = (360.0f/(float)xrollMax);
- float yaRad = (360.0f/(float)yrollMax);
-
-
- public void initialize () {
- paperChild = (SFInt32) getEventOut("paperChild");
- timerOn = (SFBool) getEventOut("timerOn");
- birdRotation = (SFRotation) getEventOut("birdRotation");
-
- bgmStop = (SFTime) getEventOut("bgmStop");
- bgmStart = (SFTime) getEventOut("bgmStart");
- gusyaStop = (SFTime) getEventOut("gusyaStop");
- gusyaStart = (SFTime) getEventOut("gusyaStart");
- }
-
- public void processEvent (Event e){
- String name = e.getName();
-
- if(name.equals("clicked")){
- clicked ((ConstSFBool)e.getValue(),e.getTimeStamp());
- }
- if(name.equals("roll")){
- roll((ConstSFTime)e.getValue(), e.getTimeStamp());
- }
- }
-
- public void clicked (ConstSFBool press, double t) {
- if(press.getValue()) return ;
-
- if(rolling) {
- rolling=false;
- bgmStop.setValue(t);
- }
- else {
- rolling=true;
- gusyaStart.setValue(t);
- bgmStart.setValue(t);
- }
- timerOn.setValue(rolling);
- nextChild(t);
- }
-
- public void roll(ConstSFTime t, double now){
-
- rotation[0]=rotation[1]=rotation[2]=0.0f;
- if(rollmode == rollingX){
- if(xroll < xrollMax) {
- xroll++;
- }
- else {
- xroll = 0;
- rollmode = rollingY;
- }
- }
- else {
- if(yroll < yrollMax) {
- yroll++;
- }
- else {
- yroll = 0;
- nextChild(now);
- rollmode = rollingX;
- }
- }
- if(rollmode == rollingX){
- rotation[0]=1.0f;
- rotation[3]= (piV*(xaRad*(float)xroll)) ;
- }
- else {
- rotation[1]=1.0f;
- rotation[3]= (piV*(yaRad*(float)yroll)) ;
- }
-
- birdRotation.setValue(rotation);
- }
- void nextChild(double t){
- gusyaStop.setValue(t - 3);
- gusyaStart.setValue(t);
- if(current < max-1) current++ ;
- else {
- current =0;
- rolling = false;
- timerOn.setValue(rolling);
- bgmStop.setValue(t);
- }
- paperChild.setValue(current);
- }
- }
-
-
-
-
-
-
-