home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-01-30 | 3.9 KB | 148 lines |
- /*
- * File : beebee.java
- * Version : 2.01 1997.01.29
- * Auther : cori co.
- *
- * (c)Copyright 1996 Sony Corporation. All rights reserved.
- */
-
- import vrml.*;
- import vrml.field.*;
- import vrml.node.*;
- import java.util.*;
- import vs.*;
- import java.lang.*;
-
- public class Beebee extends Script {
- final int X = 0;
- final int Y = 1;
- final int Z = 2;
- final int DEGREE = 3;
-
- SFVec3f BeeTranslation;
- SFRotation BeeRotation;
-
- float BeePosition[] = new float[3];
- float p_pos[] = new float[3];
- float n_pos[] = new float[3];
- float UserPosition[] = new float[3];
- float UserOrientation[] = new float[4];
-
- int BeeAngry = 0;
-
- public void initialize() {
- BeeTranslation =
- (SFVec3f) getEventOut( "BeeTranslation" );
- BeeRotation = (SFRotation)getEventOut( "BeeRotation" );
-
- BeePosition[X] = BeePosition[Y] = BeePosition[Z] = 0.0f;
- UserPosition[X] = 0.0f;
- UserPosition[Y] = 0.0f;
- UserPosition[Z] = 20.0f;
- UserOrientation[X] = UserOrientation[Z] = 0.0f;
- UserOrientation[Y] = 1.0f;
- UserOrientation[DEGREE] = 0.0f;
- }
-
- public void processEvent( Event e ) {
- String name = e.getName();
-
- try {
- if(name.equals("HoneycomTouchSensorIsActive"))
- HoneycomTouchSensorIsActive(e);
- else if(name.equals("PositionChanged"))
- ProximitySensorPositionChanged(e);
- else if(name.equals("OrientationChanged"))
- ProximitySensorOrientationChanged(e);
-
- else if(name.equals("BeeTimeSensorCycleTime"))
- BeeTimeSensorCycleTime(e);
- } catch (NullPointerException n) {
- System.out.println("Error! NullPointerException");
- } catch (Throwable t) {
- System.out.println("Error! Throwable");
- }
- }
-
- float randMinMax(float min, float max){
- float value, range;
- double rnd;
-
- range = max - min;
- rnd = Math.random();
- value = (float)(rnd * (double)range) + min;
- return value;
- }
-
- public void HoneycomTouchSensorIsActive ( Event e ){
- ConstSFBool mouse_down = (ConstSFBool)e.getValue();
-
- if (mouse_down.getValue()) return; /* mouseDown */
-
- if (BeeAngry > 0){
- BeeAngry = 0;
- }else{
- double rnd;
- BeeAngry = 300;
-
- if((rnd = Math.random())<0.5)
- BeePosition[X] += 3.0f*rnd;
- else
- BeePosition[X] -= 3.0f*rnd;
- if((rnd = Math.random())<0.5)
- BeePosition[Y] += 3.0f*rnd;
- else
- BeePosition[Y] -= 3.0f*rnd;
- if((rnd = Math.random())<0.5)
- BeePosition[Z] += 3.0f*rnd;
- else
- BeePosition[Z] -= 3.0f*rnd;
- }
- }
-
- public void ProximitySensorPositionChanged(Event e) {
- ((ConstSFVec3f)e.getValue()).getValue(UserPosition);
- }
-
- public void ProximitySensorOrientationChanged(Event e) {
- ((ConstSFRotation)e.getValue()).getValue(UserOrientation);
- }
-
- public void BeeTimeSensorCycleTime(Event e){
- float speed = 20.0f;
- float f = 0.2f;
- float distance;
- float accel;
-
- if (BeeAngry > 0){
- BeeAngry = BeeAngry - 1;
- p_pos[X] = UserPosition[X] - (float)Math.sin(UserOrientation[DEGREE]);
- p_pos[Y] = UserPosition[Y];
- p_pos[Z] = UserPosition[Z] - (float)Math.cos(UserOrientation[DEGREE]);
- }else{
- p_pos[X] = p_pos[Y] = p_pos[Z] = 0.0f;
- }
- distance = p_pos[X] - BeePosition[X];
- if(Math.abs(distance) < 0.3){
- accel = 2.0f;
- }else{
- accel = 4.0f;
- }
- n_pos[X] = BeePosition[X] + (distance/speed)+randMinMax(-accel*f, accel*f);
-
- distance = p_pos[Y] - BeePosition[Y];
- if(Math.abs(distance) < 0.3){
- accel = 2.0f;
- }else{
- accel = 4.0f;
- }
- n_pos[Y] = BeePosition[Y] + (distance/speed)+randMinMax(-accel*f, accel*f);
- n_pos[Z] = BeePosition[Z] + ((p_pos[Z] - BeePosition[Z])/speed)+randMinMax (-f, f);
-
- BeeTranslation.setValue(n_pos);
- BeeRotation.setValue(UserOrientation);
- BeePosition = n_pos;
- }
- }
-
-