/************************************************************ * draw ************************************************************/ void Mesh::drawSmooth() { glBegin(GL_TRIANGLES); for (unsigned int i = 0;i<triangles.size();++i) { Vec3Df col = this->materials[triangleMaterials[i]].Kd(); glColor3fv(col.pointer()); for (int v = 0; v < 3; v++) { glNormal3f(vertices[triangles[i].v[v]].n[0], vertices[triangles[i].v[v]].n[1], vertices[triangles[i].v[v]].n[2]); glVertex3f(vertices[triangles[i].v[v]].p[0], vertices[triangles[i].v[v]].p[1], vertices[triangles[i].v[v]].p[2]); } } glEnd(); }
void Mesh::draw() { glBegin(GL_TRIANGLES); for (unsigned int i = 0;i<triangles.size();++i) { unsigned int triMat = triangleMaterials.at(i); Vec3Df col = this->materials.at(triMat).Kd(); glColor3fv(col.pointer()); Vec3Df edge01 = vertices[triangles[i].v[1]].p - vertices[triangles[i].v[0]].p; Vec3Df edge02 = vertices[triangles[i].v[2]].p - vertices[triangles[i].v[0]].p; Vec3Df n = Vec3Df::crossProduct(edge01, edge02); n.normalize(); glNormal3f(n[0], n[1], n[2]); for (int v = 0; v < 3; v++) { glVertex3f(vertices[triangles[i].v[v]].p[0], vertices[triangles[i].v[v]].p[1], vertices[triangles[i].v[v]].p[2]); } } glEnd(); }