//you main task will be here

//TODO (5 pts)
//
//x,v,dx,dv are arrays of size=flock.length
//each element of x,v,dx,dv is a 2d vector (x,y)
//
function Derive(flock,dog,level,x,v,dx,dv)
{
	//Call getForce
	
	//Compute derivative
}

//TODO (5 pts)
//
//h is step size = game.timestep
//input x,v,dx,dv are arrays of size=flock.length
//output nx, nv should also have size=flock.length
//each element is a 2d vector (x,y)
//
function Integrate(h,x,v, dx, dv, nx, nv)
{

}

//TODO (3 pts)
//implement Euler method
function EulerMethod(flock,dog,level,h,x,v,nx,nv)
{

}

//TODO (5 pts)
//implement Midpoint method
function MidpointMethod(flock,dog,level,h,x,v,nx,nv)
{

}

//TODO (7 pts)
//implement RK4 method
function RK4(flock,dog,level,h,x,v,nx,nv)
{

}

//TODO (5 pts)
//
// given the flock and current level, 
// return an vector of repulsive forces for each flock member
// 
function getObstaleForce(flock,level)
{
	var F=[]; //each element of F is a vector {x,y}
	
	//compute a repulsive force for each flock member if its projected trajectory
	//intersects an obstacle
	
	return F;
}

//TODO (5 pts)
//
// given the flock, return an vector of flocking forces for each flock member
// 
function getFlockForce(flock)
{
	var F=[]; //each element of F is a vector {x,y}
	//compute separation, coherence, and alignment forces.
	
	return F;
}

//TODO (5 pts)
//
// given the flock and dog
// return an vector of repulsive forces for each flock member
// 
function getDogForce(flock,dog)
{
	var F=[]; //each element of F is a vector {x,y}
	//compute a repulsive force for each flock member
	return F;
}

//TODO (5 pts)
//
// see herding for the definition of dog and flock
// 
function getForce(flock,dog,level)
{
	var F1=getFlockForce(flock);
	var F2=getDogForce(flock,dog);	
	var F3=getDogForce(flock,level);		
	//compute and return F1+F2+F3
}

//TODO (15 pts)
//
// check and handle collision between the old state (x,v) and
// the new state (nx,nv)
//
function handleCollision(flock, dog, level, h, x,v, nx, nv)
{
	//
	// for each flock member, check if the line between x and nx
	// intersects obstacles
	// 
	// if so, (1) compute the intersection point
	//        (2) compute the intersection time t'
	//        (3) update the velocity at time t'
	//        (4) simulate the rest of time (h-t')
	//
}

//TODO (5 pts)
//
//
//
function updateFlockState(flock,dog,level,h)
{
	//(1) build two state vectors  x=[], and v=[] from flock
	//(2) each element of x and v is a 2d vector {x,y}
	
	//(3) call one of the ODEs to get new states nx and nv
	
	//(4) handle collision between the old state and the new state. 

	//(5) save nx and nv to flock 
}

//TODO (10 pts)
//
// Given mouse position, compute dog's position using ODE
// since mouse control is not implemented in herding.js, you
// will need to implement a mouse event listener yourself
//
function updateDogState(dog,level,h,mouse)
{
	//similar to updateFlockState
}


