diff --git a/L11/.gitignore b/L11/.gitignore new file mode 100644 index 0000000..567609b --- /dev/null +++ b/L11/.gitignore @@ -0,0 +1 @@ +build/ diff --git a/L11/src/main.cpp b/L11/src/main.cpp index 5060de2..50281b8 100644 --- a/L11/src/main.cpp +++ b/L11/src/main.cpp @@ -201,7 +201,175 @@ void render() // INSERT CODE HERE - // Unbind the program + // Initialize B. + glm::mat4 B; + + // Initialize Frenet Frame variables + glm::vec3 p1; + glm::vec3 p2; + + glm::vec4 uVec1; + glm::vec4 uVec2; + + glm::vec3 Tan; + glm::vec3 Bin; + glm::vec3 Norm; + + // Provided code for using global time variable t + float kfloat; + float uu = std::modf(std::fmod(t*0.5f, ncps-3.0f), &kfloat); + int k = (int)std::floor(kfloat); + + if(type == BEZIER) + { + if(ncps > 3) + { + // Fill in B. + B[0] = glm::vec4(1.0f, 0.0f, 0.0f, 0.0f); + B[1] = glm::vec4(-3.0f, 3.0f, 0.0f, 0.0f); + B[2] = glm::vec4(3.0f, -6.0f, 3.0f, 0.0f); + B[3] = glm::vec4(-1.0f, 3.0f, -3.0f, 1.0f); + + // Initialize G. + glm::mat4 G; + + // Fill in G. + for(int i = 0; i < ncps/4; i++) + { + G[0] = glm::vec4(cps[i*4], 0.0f); + G[1] = glm::vec4(cps[i*4 + 1], 0.0f); + G[2] = glm::vec4(cps[i*4 + 2], 0.0f); + G[3] = glm::vec4(cps[i*4 + 3], 0.0f); + + // Create uVec. Draw curve. + glBegin(GL_LINE_STRIP); + for(float u = 0; u <= 1.0f; u += 0.01f) + { + glm::vec4 uVec(1.0f, u, u*u, u*u*u); + + glm::vec4 p = G*(B*uVec); + + glColor3f(0.1f, 0.1f, 1.0f); + glVertex3f(p.x, p.y, p.z); + } + glEnd(); + } + } + } + + if(type == CATMULL_ROM) + { + if(ncps > 3) + { + // Fill in B. + B[0] = glm::vec4(0.0f, 2.0f, 0.0f, 0.0f); + B[1] = glm::vec4(-1.0f, 0.0f, 1.0f, 0.0f); + B[2] = glm::vec4(2.0f, -5.0f, 4.0f, -1.0f); + B[3] = glm::vec4(-1.0f, 3.0f, -3.0f, 1.0f); + B = 0.5f*B; + + // Initialize G. + glm::mat4 G; + + // Fill in G. + for(int i = 0; i < ncps - 3; i++) + { + G[0] = glm::vec4(cps[i], 0.0f); + G[1] = glm::vec4(cps[i + 1], 0.0f); + G[2] = glm::vec4(cps[i + 2], 0.0f); + G[3] = glm::vec4(cps[i + 3], 0.0f); + + // Create uVec. Draw curve. + glBegin(GL_LINE_STRIP); + for(float u = 0; u <= 1.0f; u += 0.01f) + { + glm::vec4 uVec(1.0f, u, u*u, u*u*u); + + glm::vec3 p = G*(B*uVec); + + glColor3f(0.1f, 0.1f, 1.0f); + glVertex3f(p.x, p.y, p.z); + } + glEnd(); + } + + G[0] = glm::vec4(cps[k], 0.0f); + G[1] = glm::vec4(cps[k + 1], 0.0f); + G[2] = glm::vec4(cps[k + 2], 0.0f); + G[3] = glm::vec4(cps[k + 3], 0.0f); + + glm::vec4 uVec(1.0f, uu, uu*uu, uu*uu*uu); + + glm::vec3 p = G*(B*uVec); + + uVec1 = glm::vec4(0.0f, 1.0f, uu*2.0f, (uu*uu)*3.0f); + p1 = G*(B*uVec1); + uVec2 = glm::vec4(0.0f, 0.0f, 2.0f, uu*6.0f); + p2 = G*(B*uVec2); + Tan = glm::normalize(p1); + Bin = glm::normalize(glm::cross(p1, p2)); + Norm = glm::cross(Bin, Tan); + + glBegin(GL_LINE_STRIP); + glColor3f(1.0, 0.0, 0.0); + glVertex3f(p.x, p.y, p.z); + glVertex3f(Tan.x, Tan.y, Tan.z); + glEnd(); + + glBegin(GL_LINE_STRIP); + glColor3f(0.0, 0.0, 1.0); + glVertex3f(p.x, p.y, p.z); + glVertex3f(Bin.x, Bin.y, Bin.z); + glEnd(); + + glBegin(GL_LINE_STRIP); + glColor3f(0.0, 1.0, 0.0); + glVertex3f(p.x, p.y, p.z); + glVertex3f(Norm.x, Norm.y, Norm.z); + glEnd(); + + } + } + + if(type == BASIS) + { + if(ncps > 3) + { + // Fill in B. + B[0] = glm::vec4(1.0f, 4.0f, 1.0f, 0.0f); + B[1] = glm::vec4(-3.0f, 0.0f, 3.0f, 0.0f); + B[2] = glm::vec4(3.0f, -6.0f, 3.0f, 0.0f); + B[3] = glm::vec4(-1.0f, 3.0f, -3.0f, 1.0f); + B = (1.0f/6.0f)*B; + + // Initialize G. + glm::mat4 G; + + // Fill in G. + for(int i = 0; i < ncps - 3; i++) + { + G[0] = glm::vec4(cps[i], 0.0f); + G[1] = glm::vec4(cps[i + 1], 0.0f); + G[2] = glm::vec4(cps[i + 2], 0.0f); + G[3] = glm::vec4(cps[i + 3], 0.0f); + + // Create uVec. Draw curve. + glBegin(GL_LINE_STRIP); + for(float u = 0; u <= 1.0f; u += 0.01f) + { + glm::vec4 uVec(1.0f, u, u*u, u*u*u); + + glm::vec4 p = G*(B*uVec); + + glColor3f(0.1f, 0.1f, 1.0f); + glVertex3f(p.x, p.y, p.z); + } + glEnd(); + } + } + } + + // Unbind the program prog->unbind(); // Pop matrix stacks. diff --git a/L12/.gitignore b/L12/.gitignore new file mode 100644 index 0000000..567609b --- /dev/null +++ b/L12/.gitignore @@ -0,0 +1 @@ +build/ diff --git a/L13/.gitignore b/L13/.gitignore new file mode 100644 index 0000000..567609b --- /dev/null +++ b/L13/.gitignore @@ -0,0 +1 @@ +build/ diff --git a/L14/.gitignore b/L14/.gitignore new file mode 100644 index 0000000..567609b --- /dev/null +++ b/L14/.gitignore @@ -0,0 +1 @@ +build/ diff --git a/L15/.gitignore b/L15/.gitignore new file mode 100644 index 0000000..567609b --- /dev/null +++ b/L15/.gitignore @@ -0,0 +1 @@ +build/