454

Writing program scripts with Java
Java script example code

import vrml.*;
import vrml.field.*;
import vrml.node.*;

public class bounce2
    extends Script
{
    private float bounceHeight;
    private SFVec3f value_changedObj;

    public void initialize( )
    {
        // Get the fields and eventOut
        SFFloat floatObj = (SFFloat) getField( "bounceHeight" );
        bounceHeight     = (float)   floatObj.getValue( );
        value_changedObj = (SFVec3f) getEventOut( "value_changed" );
    }

    public void processEvent( Event event )
    {
        ConstSFFloat flt = (ConstSFFloat) event.getValue( );
        float frac       = (float) flt.getValue( );

        float y = (float)(4.0 * bounceHeight * frac * (1.0 - frac));

        float[] changed = new float[3];
        changed[0] = (float)0.0;
        changed[1] = y;
        changed[2] = (float)0.0;
        value_changedObj.setValue( changed );
    }
}