// A method that calculates a steering force towards a target
// STEER = DESIRED MINUS VELOCITY
Vec2f Vehicle::seek( Vec2f target )
{
    Vec2f desired = target - mLocation;  // A vector pointing from the location to the target

    // Normalize desired and scale to maximum speed
    desired.normalize();
    desired *= mMaxSpeed;

    // Steering = Desired minus velocity
    Vec2f steer = desired - mVelocity;
    steer.limit( mMaxForce );  // Limit to maximum steering force

    return steer;
}
void VectorFlowField::update()
{
	if(! mChannel) return;
	
	if((timeline().getCurrentTime() - mPrevTime) > 0.01){
        
		float newX = mWindDirection.x*cos(mTheta) - mWindDirection.y*sin(mTheta);
		float newY = mWindDirection.x*sin(mTheta) + mWindDirection.y*cos(mTheta);
        
		mWindDirection.x = newX;
		mWindDirection.y = newY;
        
		mWindDirection.normalize();
        
        
		mPrevTime = timeline().getCurrentTime();
	}
    
	mParticleController->update(mChannel, mWindDirection);
	
    
	//Cloud stuff
	checkRespawn();
	
	//Cloud controllers
	if(!mCloudControllers->empty()){
		for(int i = 0; i < mCloudControllers->size(); i++){
			glPushMatrix();
			//Steer the cloud controller
			Vec2f desiredDir = mParticleController->flowLookUp((*mCloudControllers)[i]->mLoc);
			desiredDir = desiredDir * (*mCloudControllers)[i]->mMaxSpeed;
			Vec2f steer = desiredDir - (*mCloudControllers)[i]->mVel;
			steer.limit((*mCloudControllers)[i]->mMaxForce);
			(*mCloudControllers)[i]->applyForce(steer);
			
			//update its position
			(*mCloudControllers)[i]->update();
			glPopMatrix();
		}
	}
	
	//Cloud particles
	if(mCloudParticle !=NULL){
		glPushMatrix();
        mCloudParticle->updateGPUcloudControllers();
		mCloudParticle->update();
		glPopMatrix();
	}
}