#include "BasicDrawer.h" #include using namespace std; namespace X3DTK { namespace MESH { void BasicDrawer::drawVertices(Mesh *M) { glDisable(GL_LIGHTING); glColor3f(1.0f, 0.9f, 0.8f); glPointSize(1.0f); // Getting the vertices. const Mesh::MFVertex &vertices = M->getVertices(); glBegin(GL_POINTS); // iterating the points. for (Mesh::MFVertex::const_iterator v = vertices.begin(), end = vertices.end() ; v != end; ++v) glVertex3fv((*v)->data().getPoint()); glEnd(); } void BasicDrawer::drawEdges(Mesh *M) { glDisable(GL_LIGHTING); // Getting the edges. const Mesh::MFEdge &edges = M->getEdges(); glBegin(GL_LINES); // iterating the edges. for (Mesh::MFEdge::const_iterator e = edges.begin(), end = edges.end() ; e != end; ++e) { // drawing in blue color if the edge is a boundary. if ((*e)->isBoundary()) glColor3f(0.3, 0.3, 0.9); else glColor3f(0.7, 0.7, 0.7); // Getting the extremities of the edge. glVertex3fv((*e)->getFromVertex()->data().getPoint()); glVertex3fv((*e)->getToVertex()->data().getPoint()); } glEnd(); } void BasicDrawer::drawFaces(Mesh *M) { glEnable(GL_LIGHTING); // Getting the properties of the Mesh. bool hasColor = M->data().hasColor(); // Getting the faces. const Mesh::MFFace &faces = M->getFaces(); // iterating the faces. for (Mesh::MFFace::const_iterator f = faces.begin(), end = faces.end() ; f != end; ++f) { glBegin(GL_POLYGON); // getting the edges of the face. const SFFace::MFEdge &edges = (*f)->getEdges(); // iterating the edges to iterate the vertices of the face. for (SFFace::MFEdge::const_iterator e = edges.begin(), end = edges.end() ; e != end; ++e) { // Getting the vertex. SFVertex *v = (*e)->getFromVertex(); // setting the normal of the vertex. glNormal3fv(v->data().getNormalOfFace(*f)); // setting the color of the vertex. if (hasColor) glColor4fv(v->data().getColorOfFace(*f)); else glColor4f(0.8f, 0.8f, 0.8f, 1.0f); // Getting the point data. glVertex3fv(v->data().getPoint()); } glEnd(); } } } }