diff --git a/engine/include/group.hpp b/engine/include/group.hpp index d8ecf25..6a2d1c4 100644 --- a/engine/include/group.hpp +++ b/engine/include/group.hpp @@ -34,7 +34,7 @@ class Group { void rotate(float angle, float x, float y, float z); - void drawGroup(bool lights, const Frustsum& frustsum); + void drawGroup(bool lights, const Frustsum& frustsum, bool normals); }; diff --git a/engine/include/model.hpp b/engine/include/model.hpp index 39fabdd..0dfee2f 100644 --- a/engine/include/model.hpp +++ b/engine/include/model.hpp @@ -44,6 +44,7 @@ class Model { void drawModel(); void setupModel(); bool loadTexture(); + void drawNormals(); std::vector getPoints(); diff --git a/engine/src/group.cpp b/engine/src/group.cpp index 923363c..375fd51 100644 --- a/engine/src/group.cpp +++ b/engine/src/group.cpp @@ -57,7 +57,7 @@ glm::mat4 applyTransformations(std::vector order, return matrix; } -void Group::drawGroup(bool lights, const Frustsum& frustsum) { +void Group::drawGroup(bool lights, const Frustsum& frustsum, bool normals) { glPushMatrix(); glm::mat4 matrix = applyTransformations(this->order, this->static_transformations, this->rotations, this->translates); @@ -70,11 +70,12 @@ void Group::drawGroup(bool lights, const Frustsum& frustsum) { if(model.bounding_sphere.isInsideFrustsum(frustsum, matrix)) { model.drawModel(); + if(normals) model.drawNormals(); } } for (Group& sub : this->subgroups) { - sub.drawGroup(lights, frustsum); + sub.drawGroup(lights, frustsum, normals); } glPopMatrix(); diff --git a/engine/src/main.cpp b/engine/src/main.cpp index 5ead8c0..2fa0331 100644 --- a/engine/src/main.cpp +++ b/engine/src/main.cpp @@ -26,6 +26,7 @@ float zoom = 1.0f; int axis = 1; int wireframe = 1; bool imgui = true; +bool normals = false; bool isDragging = false; int lastMouseX, lastMouseY; @@ -118,7 +119,7 @@ void renderScene(void) { drawLights(c.lights); } - c.group.drawGroup(lights, frustsum); + c.group.drawGroup(lights, frustsum, normals); frameCounter(); @@ -215,6 +216,9 @@ void processNormalKeys(unsigned char key, int x, int y) { case 'i': imgui = !imgui; break; + case 'n': + normals = !normals; + break; default: break; } diff --git a/engine/src/model.cpp b/engine/src/model.cpp index 865e748..a9c002e 100644 --- a/engine/src/model.cpp +++ b/engine/src/model.cpp @@ -203,4 +203,14 @@ void Model::drawModel() { glBindTexture(GL_TEXTURE_2D, 0); } +void Model::drawNormals() { + glBegin(GL_LINES); + for (const Vertex& point : this->vbo) { + glVertex3f(point.position.x, point.position.y, point.position.z); + glVertex3f(point.position.x + point.normal.x, point.position.y + point.normal.y, + point.position.z + point.normal.z); + } + glEnd(); + +} std::vector Model::getPoints() { return this->_points; }