#include "BasicDrawer.h" #include using namespace std; namespace X3DTK { namespace MESH { void BasicDrawer::drawFaces(MyMesh *M) { glEnable(GL_LIGHTING); // Getting the faces. const MyMesh::MFFace &faces = M->getFaces(); // iterating the faces. for (MyMesh::MFFace::const_iterator f = faces.begin(), end = faces.end() ; f != end; ++f) { glBegin(GL_POLYGON); // getting the edges of the face. const MySFFace::MFEdge &edges = (*f)->getEdges(); // iterating the edges to iterate the vertices of the face. for (MySFFace::MFEdge::const_iterator e = edges.begin(), end = edges.end() ; e != end; ++e) { // Getting the vertex. MySFVertex *v = (*e)->getFromVertex(); // setting the normal of the vertex. glNormal3fv(v->data().getNormalOfFace(*f)); // setting the color of the vertex depending on the distance. glColor3fv(getColor(v->data().getDistance())); // Getting the point data. glVertex3fv(v->data().getPoint()); } glEnd(); } } SFColor BasicDrawer::getColor(float level) const { float r, g, b; float f, q, V, S, t, v; int i; v = 4.0f*(1.0f - level); i = (int)floorf(v); f = v - i; q = 1.0f - f; t = f; V = 1.0f; S = 0.0f; switch(i) { case 0 : r = V; g = t; b = S; break; case 1 : r = q; g = V; b = S; break; case 2 : r = S; g = V; b = t; break; case 3 : r = S; g = q; b = V; break; case 4 : r = t; g = S; b = V; break; default : r = 0.0f; g = 0.0f; b = 0.0f; break; } return SFColor(r, g, b); } } }