diff --git a/stim/visualization/gl_network.h b/stim/visualization/gl_network.h index a08d5b8..562a16e 100644 --- a/stim/visualization/gl_network.h +++ b/stim/visualization/gl_network.h @@ -45,16 +45,32 @@ public: ///render cylinder based on points from the top/bottom hat ///@param C1 set of points from one of the hat - void renderCylinder(std::vector< stim::vec3 > C1, std::vector< stim::vec3 > C2, stim::vec3 n1, stim::vec3 n2) { + void renderCylinder(std::vector< stim::vec3 > C1, std::vector< stim::vec3 > C2) { glBegin(GL_QUAD_STRIP); - for (unsigned i = 0; i < C1.size(); i++) { // for every point on the circle - glNormal3f(n1[0], n1[1], n1[2]); + for (unsigned i = 0; i < C1.size() - 1; i++) { // for every point on the circle + stim::vec3 v1; + stim::vec3 v2; + stim::vec3 v3; + stim::vec3 v4; + + v1 = C2[i + 1] - C1[i + 1]; + v2 = C1[i] - C1[i + 1]; + v3 = C1[i] - C2[i]; + v4 = C2[i + 1] - C2[i]; + + stim::vec3 n1 = v1.cross(v2); + stim::vec3 n2 = v3.cross(v4); + stim::vec3 normal = n1 + n2; + normal = normal.norm(); glVertex3f(C1[i][0], C1[i][1], C1[i][2]); - glNormal3f(n2[0], n2[1], n2[2]); glVertex3f(C2[i][0], C2[i][1], C2[i][2]); + glNormal3f(normal[0], normal[1], normal[2]); // set normal vector for lighting + //glNormal3f(n1[0], n1[1], n1[2]); + //glVertex3f(C1[i][0], C1[i][1], C1[i][2]); + //glNormal3f(n2[0], n2[1], n2[2]); + //glVertex3f(C2[i][0], C2[i][1], C2[i][2]); } glEnd(); - //glFlush(); } ///render the vertex as sphere based on glut build-in function @@ -104,6 +120,7 @@ public: yy[3] = radius * std::sin(angle_z) * std::sin(angle_xy + step_xy); zz[3] = radius * std::cos(angle_z); + for (unsigned k = 0; k < 4; k++) { glVertex3f(x + xx[k], y + yy[k], z + zz[k]); // draw the floor plane } @@ -167,19 +184,38 @@ public: stim::circle C2 = E[e].circ(p); C1.set_R(2*radius); // re-scale the circle to the same C2.set_R(2*radius); - std::vector< stim::vec3 >Cp1 = C1.glpoints(20);// get 20 points on the circle plane - std::vector< stim::vec3 >Cp2 = C2.glpoints(20); - stim::vec3 n1 = C1.n(); // get the normal vector - stim::vec3 n2 = C2.n(); + std::vector< stim::vec3 > Cp1 = C1.glpoints(20);// get 20 points on the circle plane + std::vector< stim::vec3 > Cp2 = C2.glpoints(20); glBegin(GL_QUAD_STRIP); - for (unsigned i = 0; i < Cp1.size(); i++) { // for every point on the circle(+1 means closing the circle) + for (unsigned i = 0; i < Cp1.size() - 1; i++) { + stim::vec3 v1; + stim::vec3 v2; + stim::vec3 v3; + stim::vec3 v4; + v1 = Cp2[i + 1] - Cp1[i + 1]; + v2 = Cp1[i] - Cp1[i + 1]; + v3 = Cp1[i] - Cp2[i]; + v4 = Cp2[i + 1] - Cp2[i]; + + stim::vec3 n1 = v1.cross(v2); + stim::vec3 n2 = v3.cross(v4); + stim::vec3 normal = n1; + normal = normal.norm(); + glTexCoord1f(E[e].r(p - 1)); - glNormal3f(n1[0], n1[1], n1[2]); // set normal vector for lighting glVertex3f(Cp1[i][0], Cp1[i][1], Cp1[i][2]); glTexCoord1f(E[e].r(p)); - glNormal3f(n2[0], n2[1], n2[2]); glVertex3f(Cp2[i][0], Cp2[i][1], Cp2[i][2]); + glNormal3f(normal[0], normal[1], normal[2]); // set normal vector for lighting } + //for (unsigned i = 0; i < Cp1.size(); i++) { // for every point on the circle(+1 means closing the circle) + // glTexCoord1f(E[e].r(p - 1)); + // glNormal3f(n1[0], n1[1], n1[2]); // set normal vector for lighting + // glVertex3f(Cp1[i][0], Cp1[i][1], Cp1[i][2]); + // glTexCoord1f(E[e].r(p)); + // glNormal3f(n2[0], n2[1], n2[2]); + // glVertex3f(Cp2[i][0], Cp2[i][1], Cp2[i][2]); + //} glEnd(); } // set the texture coordinate based on the specified magnitude index } @@ -187,16 +223,10 @@ public: size_t num = V[n].e[0].size(); // store the number of outgoing edge of that vertex if (num != 0) { // if it has outgoing edge unsigned idx = V[n].e[0][0]; // find the index of first outgoing edge of that vertex - stim::circle C = E[idx].circ(0); - stim::vec3 normal = C.n(); - glNormal3f(normal[0], normal[1], normal[2]);// for every ball, we only have one normal vector glTexCoord1f(E[idx].r(0)); // bind the texture as metric of first point on that edge } else { unsigned idx = V[n].e[1][0]; // find the index of first incoming edge of that vertex - stim::circle C = E[idx].circ(E[idx].size()-1); - stim::vec3 normal = C.n(); - glNormal3f(normal[0], normal[1], normal[2]);// for every ball, we only have one normal vector glTexCoord1f(E[idx].r(E[idx].size() - 1)); // bind the texture as metric of last point on that edge } renderBall(V[n][0], V[n][1], V[n][2], 2*radius, 20, 20); @@ -270,9 +300,7 @@ public: C2.set_R(2*radius); std::vector< stim::vec3 >Cp1 = C1.glpoints(20); std::vector< stim::vec3 >Cp2 = C2.glpoints(20); - stim::vec3 n1 = C1.n(); // get the normal vector - stim::vec3 n2 = C2.n(); - renderCylinder(Cp1, Cp2, n1, n2); + renderCylinder(Cp1, Cp2); } } else { @@ -284,9 +312,7 @@ public: C2.set_R(2*radius); std::vector< stim::vec3 >Cp1 = C1.glpoints(20); std::vector< stim::vec3 >Cp2 = C2.glpoints(20); - stim::vec3 n1 = C1.n(); // get the normal vector - stim::vec3 n2 = C2.n(); - renderCylinder(Cp1, Cp2, n1, n2); + renderCylinder(Cp1, Cp2); } } } @@ -311,15 +337,9 @@ public: else { // if it is the terminal vertex if (V[n].e[0].size() != 0) { unsigned idx = V[n].e[0][0]; // find the index of first incoming edge of that vertex - stim::circle C = E[idx].circ(0); - stim::vec3 normal = C.n(); - glNormal3f(normal[0], normal[1], normal[2]);// for every ball, we only have one normal vector } else { unsigned idx = V[n].e[1][0]; // find the index of first incoming edge of that vertex - stim::circle C = E[idx].circ(E[idx].size() - 1); - stim::vec3 normal = C.n(); - glNormal3f(normal[0], normal[1], normal[2]);// for every ball, we only have one normal vector } glColor3f(0.6, 0.6, 0.6); // more white gray renderBall(V[n][0], V[n][1], V[n][2], 3*radius, 20, 20); -- libgit2 0.21.4