Use normals in glut render
This commit is contained in:
parent
d282b93298
commit
8c254dff15
1 changed files with 9 additions and 4 deletions
|
@ -78,7 +78,7 @@ void GlutRender::reshape(int wid, int hei) {
|
||||||
gluPerspective(45.0f, aspect, 0.1f, 100.0f);
|
gluPerspective(45.0f, aspect, 0.1f, 100.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlutRender::display_mesh(const Mesh& mesh) const {
|
void GlutRender::display_mesh(Mesh& mesh) const {
|
||||||
const Point& mesh_center = mesh.get_center();
|
const Point& mesh_center = mesh.get_center();
|
||||||
|
|
||||||
const std::vector<Point>& points = mesh.get_vertices();
|
const std::vector<Point>& points = mesh.get_vertices();
|
||||||
|
@ -88,10 +88,15 @@ void GlutRender::display_mesh(const Mesh& mesh) const {
|
||||||
Point p0 = face.pt(0, points) + mesh_center,
|
Point p0 = face.pt(0, points) + mesh_center,
|
||||||
p1 = face.pt(1, points) + mesh_center,
|
p1 = face.pt(1, points) + mesh_center,
|
||||||
p2 = face.pt(2, points) + mesh_center;
|
p2 = face.pt(2, points) + mesh_center;
|
||||||
|
Point n0 = mesh.get_normal(face[0]),
|
||||||
|
n1 = mesh.get_normal(face[1]),
|
||||||
|
n2 = mesh.get_normal(face[2]);
|
||||||
|
|
||||||
glColor3f(rand_color(), rand_color(), rand_color());
|
glColor3f(rand_color(), rand_color(), rand_color());
|
||||||
glVertex3f(p0[0], p0[1], p0[2]);
|
|
||||||
glVertex3f(p1[0], p1[1], p1[2]);
|
glNormal3f(n0[0], n0[1], n0[2]); glVertex3f(p0[0], p0[1], p0[2]);
|
||||||
glVertex3f(p2[0], p2[1], p2[2]);
|
glNormal3f(n1[0], n1[1], n1[2]); glVertex3f(p1[0], p1[1], p1[2]);
|
||||||
|
glNormal3f(n2[0], n2[1], n2[2]); glVertex3f(p2[0], p2[1], p2[2]);
|
||||||
}
|
}
|
||||||
glEnd();
|
glEnd();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue