/* * Created on 07-Aug-2004 by Ryan McNally */ package com.speckled.specksim.imp.motion; import java.util.Random; import com.ryanm.config.Configurator; import com.ryanm.config.ValueListener; import com.ryanm.config.imp.AbstractConfigurator; import com.ryanm.config.imp.AnnotatedConfigurator; import com.ryanm.config.imp.ConfigurableType; import com.speckled.specksim.Speck; import com.speckled.specksim.SpeckPosition; /** * Models a static field of randomly placed Specks. For a given rng * offset and speck index, the same position will always be given * * @author ryanm */ @ConfigurableType( "Static" ) public class StaticMovementModel extends AbstractMovementModel { /** * Used to generate the positions */ private Random random = new Random( 63127 ); private SpeckPosition skew = new SpeckPosition(); private AbstractConfigurator conf = null; /** * Builds a new StaticMovementModel */ public StaticMovementModel() { super( "Static" ); } @Override protected void initialise() { } @Override protected void deinitialise() { } @Override protected SpeckPosition computeLocation( Speck speck, float time, int speckIndex, int population ) { random.setSeed( ( speckIndex + 1 ) * rngSeedOffset ); // throw away the first couple random.nextDouble(); random.nextDouble(); SpeckPosition o = new SpeckPosition( random ); if( !skew.isZero() ) { SpeckPosition s = new SpeckPosition( skew ); o = SpeckPosition.add( o, s ); } return o; } @Override public Configurator getConfigurator() { if( conf == null ) { conf = AnnotatedConfigurator.buildConfigurator( this ); Configurator skewConf = new SpeckPosition.Configurator( "Skew", skew ); conf.addVariable( skewConf ); ValueListener valueListener = new ValueListener() { public void valueChanged( Configurator conf, String name ) { clearCache(); } }; conf.addValueListener( valueListener, true ); } return conf; } }