class Crawler { // Description: // Crawler travels through the world, and probes for points // If the point-cloud provides points, Crawler will add lines // to the main drawable from it's current location to the points. // A Crawler will also drop points into the point cloud. static final int POINT_FREQUENCY = 400; // In Millis static final float CRAWLER_MAX_SPEED = 200; static final float CRAWLER_MAX_SPEED_SQ = CRAWLER_MAX_SPEED * CRAWLER_MAX_SPEED; PVector pos; PVector vel; float rad; color col; DrawPoint curPoint; PVector warp; float variance; Timer timer; Timer lifetime; Crawler( PVector position, PVector velocity, float radius, color colr) { pos = position; vel = velocity; rad = radius; col = color( red(colr), green(colr), blue(colr) ); curPoint = new DrawPoint( pos.get(), col, CRAWLER_COLOR ); warp = new PVector( .05, .05, .05 ); variance = 7; timer = new Timer( POINT_FREQUENCY ); lifetime = new Timer( (int)random( CRAWLER_LIFETIME_MIN, CRAWLER_LIFETIME_MAX) ); } void Update( GameTime time ) { timer.Update( time.Delta ); lifetime.Update( time.Delta ); vel.add(Heading() ); if( vel.dot(vel) > CRAWLER_MAX_SPEED_SQ ) { vel.normalize(); vel.mult( CRAWLER_MAX_SPEED ); } pos.add( PVector.mult( vel, time.DeltaF) ); curPoint.pos.set( pos ); if( timer.IsDone() ) { timer.Reset(); ArrayList points = new ArrayList(); cloud.GatherPoints( pos, rad, points ); cloud.AddPoint( curPoint ); curPoint = new DrawPoint( pos.get(), col, CRAWLER_COLOR ); for( int i = 0; i < points.size(); i++ ) { lines.Add( new DrawLine( curPoint, (DrawPoint)points.get(i)) ); } } } PVector Heading() { float seed = pos.x + pos.y + pos.z; float x = noise( (seed + pos.x) * warp.x ) * 2 - 1; float y = noise( (seed + pos.y) * warp.y ) * 2 - 1; float z = noise( (seed + pos.z) * warp.z ) * 2 - 1; x = random( -1, 1); y = random( -1, 1); z = random( -1, 1); PVector vec = new PVector( x, y, z ); //vec.normalize(); vec.mult( variance ); return vec; } boolean IsDead() { return lifetime.IsDone(); } }