diff --git a/L11/src/main.cpp b/L11/src/main.cpp index 50281b8..b0ac532 100644 --- a/L11/src/main.cpp +++ b/L11/src/main.cpp @@ -293,40 +293,40 @@ void render() 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); + 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::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); + 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(1.0, 0.0, 0.0); + glVertex3f(p.x, p.y, p.z); + glVertex3f(p.x + Tan.x, p.y + Tan.y, p.z + 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, 0.0, 1.0); + glVertex3f(p.x, p.y, p.z); + glVertex3f(p.x + Bin.x, p.y + Bin.y, p.z + 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(); + glBegin(GL_LINE_STRIP); + glColor3f(0.0, 1.0, 0.0); + glVertex3f(p.x, p.y, p.z); + glVertex3f(p.x + Norm.x, p.y + Norm.y, p.z + Norm.z); + glEnd(); } } @@ -366,6 +366,41 @@ void render() } 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(); } } diff --git a/L13/src/main.cpp b/L13/src/main.cpp index b8339a6..a87f52e 100644 --- a/L13/src/main.cpp +++ b/L13/src/main.cpp @@ -179,12 +179,125 @@ void buildTable() { // INSERT CODE HERE usTable.clear(); + int ncps = (int) cps.size(); + + glm::mat4 B = (type == CATMULL_ROM ? Bcr : Bb); + + glm::mat4 G; + + for(int c = 0; c < ncps - 3; c++) + { + G[0] = glm::vec4(cps[c], 0.0f); + G[1] = glm::vec4(cps[c + 1], 0.0f); + G[2] = glm::vec4(cps[c + 2], 0.0f); + G[3] = glm::vec4(cps[c + 3], 0.0f); + + if(c == 0) + { + usTable.push_back(make_pair(0.0f,0.0f)); + } + + for(int i = 0; i < 5; i++) + { + float ua = (float) i*0.2f; + float ub = (float) (i + 1.0f)*0.2f; + + glm::vec4 uVeca = glm::vec4(1.0, ua, ua*ua, ua*ua*ua); + glm::vec4 uVecb = glm::vec4(1.0, ub, ub*ub, ub*ub*ub); + + glm::vec4 Pua = G*(B*uVeca); + glm::vec4 Pub = G*(B*uVecb); + + glm::vec4 Pu = Pub - Pua; + + float sl = (ub - ua)/2.0f; + float sr = 0; + + float xj; + float wj; + + + for(int j = 0; j < 3; j++) + { + switch(j) + { + case 0: + xj = -1*sqrt(3.0f/5.0f); + wj = 5.0f/9.0f; + break; + case 1: + xj = 0; + wj = 8.0f/9.0f; + break; + case 2: + xj = sqrt(3.0f/5.0f); + wj = 5.0f/9.0f; + break; + default: + xj = 0; + wj = 0; + break; + } + + float up = ((((ub - ua)*xj)/2.0f) + ((ua + ub)/2.0f)); + + glm::vec4 uVecPrime(0.0f, 1.0f, 2.0f*up, 3.0f*up*up); + + glm::vec4 Pp = G*(B*uVecPrime); + + sr += (wj*(glm::length(Pp))); + } + + float s = usTable[usTable.size() - 1].second + sl * sr; + //float s = usTable[usTable.size() - 1].second + glm::length(Pu); + + usTable.push_back(make_pair(c + ub, s)); + } + } + //Testing + for(int i = 0; i < usTable.size(); i++) + { + cout << usTable[i].first << "\t" << usTable[i].second << endl; + } } float s2u(float s) { // INSERT CODE HERE - return 0.0f; + + float s0 = 0.0f; + float s1 = 0.0f; + + float u0 = 0.0f; + float u1 = 0.0f; + + if(usTable.size() < 2) + { + return 0.0f; + } + + for(unsigned int i = 1; i < usTable.size(); i++) + { + if(usTable[i].second > s) + { + s1 = usTable[i].second; + s0 = usTable[i - 1].second; + u0 = usTable[i].first; + u1 = usTable[i - 1].first; + break; + } + } + + if(s1 == 0.0f) + { + return 0.0f; + } + + float alpha = (s - s0)/(s1 - s0); + + float u = (1.0f - alpha)*u0 + alpha*u1; + + return u; } void render()