vec3 pos = position;
vec4 pos4;
float anim = time;

vec3 center = vec3(0.0, 0.0, 0.0);

float distToCenter2 = distance(center, endPosition);
float furthestAway = distance(center, lowestPoint);

float pct = distToCenter/furthestAway;

float transitionTime = 0.2;

// Figure out in what sequence the spheres should come flying.
float n = smoothstep(pct,pct+transitionTime,anim*(1.0+transitionTime));

n = smoothstep(0.0, 1.0, n);

//pos = pos + endPosition;

float Angle = n*10.0;

mat4 RotationMatrix = mat4( cos( Angle ), -sin( Angle ), 0.0, 0.0,
	sin( Angle ),  cos( Angle ), 0.0, 0.0,
	0.0, 0.0, 1.0, 0.0,
	0.0, 0.0, 0.0, 1.0 );



pos4 = vec4(pos, 1.0);
//pos4 = RotationMatrix * pos4;






pos4.y = pos4.y + ( endPosition.y*n + -150.0*(1.0-n) );



pos4.x = pos4.x + endPosition.x*n;
pos4.z = pos4.z + endPosition.z*n;

//float rotx = sin(time*100.0 + pos.x*10.0)*2.0;
//float rotz = cos(time*100.0 + pos.z*10.0)*2.0;

//pos.x = pos.x + (endPosition.x*smoothstep(0.0,1.0,n));
//pos.z = pos.z + (endPosition.z*smoothstep(0.0,1.0,n));

//pos.x = pos.x + (endPosition.x*n + rotx*(1.0-n));
//pos.z = pos.z + (endPosition.z*n + rotz*(1.0-n));

//pos4 = vec4(pos, 1.0);

//pos4 = RotationMatrix * pos4;

gl_Position = projectionMatrix * modelViewMatrix * pos4;

vColor = vec3(0.475, 0.221, 0.0);