#include "GL_NormalRendererGeometry3DVisitor.h" #include using namespace std; namespace X3DTK { namespace GL { NormalRendererGeometry3DVisitor::NormalRendererGeometry3DVisitor() : Geometry3DVisitor() { // Enter function. define(Recorder::getEnterFunction(&NormalRendererGeometry3DVisitor::enterIndexedFaceSet)); } void NormalRendererGeometry3DVisitor::enterIndexedFaceSet(IndexedFaceSet *G) { // State variables assignation. NormalRendererStateVariables *stateVariables = Singleton::getInstance(); float coef = stateVariables->getNormalLength(); glColor3f(1.0f, 0.0f, 0.0f); glDisable(GL_LIGHTING); // Enumerating all the vertex formats. The method is simple: Get the normal vector of // vertex and drawing the line. // It is important to get a reference to the vertex array in order not to copy the datas. if ((G->getColor()) && (G->getTexCoord())) { const vector &vertexArray = G->T2F_C4F_N3F_V3F_vertexArray(); glBegin(GL_LINES); for (vector::const_iterator it = vertexArray.begin(); it != vertexArray.end(); ++it) { SFVec3f vertex = (*it).vertex; SFVec3f vnormal = vertex + coef*(*it).normal; glVertex3fv(vertex.f_data()); glVertex3fv(vnormal.f_data()); } glEnd(); } if ((G->getColor()) && (!G->getTexCoord())) { const vector &vertexArray = G->C4F_N3F_V3F_vertexArray(); glBegin(GL_LINES); for (vector::const_iterator it = vertexArray.begin(); it != vertexArray.end(); ++it) { SFVec3f vertex = (*it).vertex; SFVec3f vnormal = vertex + coef*(*it).normal; glVertex3fv(vertex.f_data()); glVertex3fv(vnormal.f_data()); } glEnd(); } if ((!G->getColor()) && (G->getTexCoord())) { const vector &vertexArray = G->T2F_N3F_V3F_vertexArray(); glBegin(GL_LINES); for (vector::const_iterator it = vertexArray.begin(); it != vertexArray.end(); ++it) { SFVec3f vertex = (*it).vertex; SFVec3f vnormal = vertex + coef*(*it).normal; glVertex3fv(vertex.f_data()); glVertex3fv(vnormal.f_data()); } glEnd(); } if ((!G->getColor()) && (!G->getTexCoord())) { const vector &vertexArray = G->N3F_V3F_vertexArray(); glBegin(GL_LINES); for (vector::const_iterator it = vertexArray.begin(); it != vertexArray.end(); ++it) { SFVec3f vertex = (*it).vertex; SFVec3f vnormal = vertex + coef*(*it).normal; glVertex3fv(vertex.f_data()); glVertex3fv(vnormal.f_data()); } glEnd(); } glEnable(GL_LIGHTING); } } }