diff --git a/L07/resources/vert.glsl b/L07/resources/vert.glsl index 9d6ef91..bee4a2c 100644 --- a/L07/resources/vert.glsl +++ b/L07/resources/vert.glsl @@ -5,11 +5,16 @@ uniform mat4 MV; attribute vec4 aPos; // In object space attribute vec3 aNor; // In object space varying vec3 color; +uniform float t; void main() { - gl_Position = P * MV * aPos; + vec4 temp = aPos; + temp.z = (cos(20*aPos.x + t) + sin(20*aPos.y + t))/20.0; + gl_Position = P * MV * temp; vec3 l = vec3(0.0, 0.0, 1.0); // In camera space - vec4 n = MV * vec4(aNor, 0.0); + vec3 tempn = aNor; + tempn.z = (cos(20*aPos.x + t) + sin(20*aPos.y + t))/20.0; + vec4 n = MV * vec4(tempn, 0.0); color = vec3((n.x*l.x + n.y*l.y + n.z*l.z), (n.x*l.x + n.y*l.y + n.z*l.z), (n.x*l.x + n.y*l.y + n.z*l.z)); } diff --git a/L07/src/main.cpp b/L07/src/main.cpp index 8f15ced..183f3ad 100644 --- a/L07/src/main.cpp +++ b/L07/src/main.cpp @@ -28,6 +28,7 @@ shared_ptr camera; shared_ptr prog; map bufIDs; int indCount; +float t = glfwGetTime(); bool keyToggles[256] = {false}; // only for English keyboards! @@ -104,6 +105,7 @@ static void init() prog->addAttribute("aNor"); prog->addUniform("MV"); prog->addUniform("P"); + prog->addUniform("t"); camera = make_shared(); camera->setInitDistance(2.0f); @@ -261,7 +263,9 @@ static void render() camera->applyProjectionMatrix(P); MV->pushMatrix(); camera->applyViewMatrix(MV); - + + t = glfwGetTime(); + prog->bind(); glUniformMatrix4fv(prog->getUniform("P"), 1, GL_FALSE, value_ptr(P->topMatrix())); glEnableVertexAttribArray(prog->getAttribute("aPos")); @@ -277,6 +281,7 @@ static void render() glBindBuffer(GL_ARRAY_BUFFER, 0); glDisableVertexAttribArray(prog->getAttribute("aNor")); glDisableVertexAttribArray(prog->getAttribute("aPos")); + glUniform1f(prog->getUniform("t"), t); prog->unbind(); MV->popMatrix();