From 36bc8e1b5c70a5849961a71095709c434f3992c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Bastian?= Date: Tue, 13 Feb 2018 14:47:34 +0100 Subject: [PATCH] Use normals for implicit surfaces --- Makefile | 2 +- MarchingCubes.cpp | 16 +--------------- render/GlutRender.cpp | 20 ++++++++++++++++++++ 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index 7a7570b..21818ce 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CXX=g++ -CXXFLAGS=-Wall -Wextra -O2 -std=c++14 +CXXFLAGS=$(ADD_FLAGS) -Wall -Wextra -O2 -std=c++14 CXXLIBS=-lGL -lGLU -lglut # In `TARGET`, list the names of the `main_[stuff].cpp` you'd like to compile diff --git a/MarchingCubes.cpp b/MarchingCubes.cpp index ea91bc1..3fbd372 100644 --- a/MarchingCubes.cpp +++ b/MarchingCubes.cpp @@ -89,22 +89,8 @@ bool MarchingCubes::march_at(double x, double y, double z, Mesh& output) { size_t vert_ids[3]; for(int i=0; i < 3; ++i) { -#ifdef DEBUG_DISPLAY_NORMAL - Point locVert = verts[i] + surface.getCenter(); Point normal = surface.normal_at(verts[i]); - Point outwards = locVert + normal; - Point inwards = locVert + ((-0.2) * normal); - glBegin(GL_LINES); - glColor3f(1., 0., 0.); - glVertex3f(locVert[0], locVert[1], locVert[2]); - glVertex3f(outwards[0], outwards[1], outwards[2]); - glColor3f(0., 0., 1.); - glVertex3f(locVert[0], locVert[1], locVert[2]); - glVertex3f(inwards[0], inwards[1], inwards[2]); - glEnd(); -#endif // DEBUG_DISPLAY_NORMAL - - vert_ids[i] = output.add_vertice(verts[i]); + vert_ids[i] = output.add_vertice(verts[i], normal); } for(int i=0; i < 3; ++i) { diff --git a/render/GlutRender.cpp b/render/GlutRender.cpp index 4e8742c..2310474 100644 --- a/render/GlutRender.cpp +++ b/render/GlutRender.cpp @@ -83,6 +83,26 @@ void GlutRender::display_mesh(Mesh& mesh) const { const std::vector& points = mesh.get_vertices(); +#ifdef DEBUG_DISPLAY_NORMAL + + glBegin(GL_LINES); + for(size_t vert_id=0; vert_id < points.size(); ++vert_id) { + const Point& pt = points[vert_id]; + Point normal = mesh.get_normal(vert_id); + Point locVert = pt + mesh.get_center(); + Point outwards = locVert + normal; + Point inwards = locVert + ((-0.2) * normal); + glColor3f(1., 0., 0.); + glVertex3f(locVert[0], locVert[1], locVert[2]); + glVertex3f(outwards[0], outwards[1], outwards[2]); + glColor3f(0., 0., 1.); + glVertex3f(locVert[0], locVert[1], locVert[2]); + glVertex3f(inwards[0], inwards[1], inwards[2]); + } + glEnd(); +#endif // DEBUG_DISPLAY_NORMAL + + glBegin(GL_TRIANGLES); for(const Face& face: mesh.get_faces()) { Point p0 = face.pt(0, points) + mesh_center,