Use normals for implicit surfaces

This commit is contained in:
Théophile Bastian 2018-02-13 14:47:34 +01:00
parent 8c254dff15
commit 36bc8e1b5c
3 changed files with 22 additions and 16 deletions

View file

@ -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

View file

@ -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) {

View file

@ -83,6 +83,26 @@ void GlutRender::display_mesh(Mesh& mesh) const {
const std::vector<Point>& 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,