/* * Copyright(C) 1998, S.M.M for TECFA */ /* * No bullshit of anykind: use it as you want it. */ import vrml.field.*; import vrml.node.*; import vrml.*; public class TheMovingSands extends Script { private MFFloat height_changed; private SFInt32 wave_number; private SFFloat constant; private SFFloat amplitude; public void initialize() { height_changed = (MFFloat) getEventOut("height_changed"); wave_number = (SFInt32) getField("wave_number"); constant = (SFFloat) getField("constant"); amplitude = (SFFloat) getField("amplitude"); constant = new SFFloat(new Float(2*Math.PI*wave_number.getValue()).floatValue()); set_fraction(0); } public void processEvent(Event TheEvent) { String TheEventName; TheEventName = TheEvent.getName(); if(TheEventName.equals("set_fraction")) { set_fraction(((ConstSFFloat)TheEvent.getValue()).getValue()); } else { System.out.println("Problem accessing EventIn for script\n"); } } public void set_fraction(float fraction) { float otherconstant; otherconstant = new Float(Math.sin(2*Math.PI*fraction*amplitude.getValue())).floatValue(); for (int i = 0; i < 30; i++) { for (int j = 0; j < 30; j++) { height_changed.set1Value((i*30+j), otherconstant*(new Float(Math.sin(((new Float(i).floatValue())/29f)*constant.getValue())*Math.sin(((new Float(j).floatValue())/29f)*constant.getValue())).floatValue())); } } } }