#version 400

layout(location = 0) in vec3 VertexPosition;

uniform float Time; // The animation time
uniform float K; // Wavenumber
uniform float Velocity; // Wave's velocity
uniform float Amp; // Wave's amplitude

uniform mat4 MVP;
uniform mat4 ViewMatrix;
uniform mat4 ModelViewMatrix;

out vec3 Position;
out vec3 Normal;

void main()
{
  vec4 pos = vec4(VertexPosition, 1.0);

  // Translate the y coordinate
  float u = K * (pos.x - Velocity * Time);
  pos.y = Amp * sin( u );

  // Compute the normal vector
  vec4 n = normalize(vec4(-K*Amp*cos( u ), 1.0,0.0,0.0));

  vec4 n4 = ModelViewMatrix * n;
  vec4 v4 = ModelViewMatrix * pos;
  Normal = vec3(n4);
  Position = vec3(v4);
  gl_Position = MVP * pos;
}
