Use normals for implicit surfaces
This commit is contained in:
parent
8c254dff15
commit
36bc8e1b5c
3 changed files with 22 additions and 16 deletions
2
Makefile
2
Makefile
|
@ -1,5 +1,5 @@
|
||||||
CXX=g++
|
CXX=g++
|
||||||
CXXFLAGS=-Wall -Wextra -O2 -std=c++14
|
CXXFLAGS=$(ADD_FLAGS) -Wall -Wextra -O2 -std=c++14
|
||||||
CXXLIBS=-lGL -lGLU -lglut
|
CXXLIBS=-lGL -lGLU -lglut
|
||||||
|
|
||||||
# In `TARGET`, list the names of the `main_[stuff].cpp` you'd like to compile
|
# In `TARGET`, list the names of the `main_[stuff].cpp` you'd like to compile
|
||||||
|
|
|
@ -89,22 +89,8 @@ bool MarchingCubes::march_at(double x, double y, double z, Mesh& output) {
|
||||||
|
|
||||||
size_t vert_ids[3];
|
size_t vert_ids[3];
|
||||||
for(int i=0; i < 3; ++i) {
|
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 normal = surface.normal_at(verts[i]);
|
||||||
Point outwards = locVert + normal;
|
vert_ids[i] = output.add_vertice(verts[i], 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]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i=0; i < 3; ++i) {
|
for(int i=0; i < 3; ++i) {
|
||||||
|
|
|
@ -83,6 +83,26 @@ void GlutRender::display_mesh(Mesh& mesh) const {
|
||||||
|
|
||||||
const std::vector<Point>& points = mesh.get_vertices();
|
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);
|
glBegin(GL_TRIANGLES);
|
||||||
for(const Face& face: mesh.get_faces()) {
|
for(const Face& face: mesh.get_faces()) {
|
||||||
Point p0 = face.pt(0, points) + mesh_center,
|
Point p0 = face.pt(0, points) + mesh_center,
|
||||||
|
|
Loading…
Reference in a new issue