Skip to content

Commit

Permalink
add normals toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
JulioJPinto committed May 25, 2024
1 parent 2c48dc1 commit 7c42169
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion engine/include/group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

};

Expand Down
1 change: 1 addition & 0 deletions engine/include/model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class Model {
void drawModel();
void setupModel();
bool loadTexture();
void drawNormals();

std::vector<Vertex> getPoints();

Expand Down
5 changes: 3 additions & 2 deletions engine/src/group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ glm::mat4 applyTransformations(std::vector<Transformations> 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);
Expand All @@ -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();
Expand Down
6 changes: 5 additions & 1 deletion engine/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -118,7 +119,7 @@ void renderScene(void) {
drawLights(c.lights);
}

c.group.drawGroup(lights, frustsum);
c.group.drawGroup(lights, frustsum, normals);

frameCounter();

Expand Down Expand Up @@ -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;
}
Expand Down
10 changes: 10 additions & 0 deletions engine/src/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vertex> Model::getPoints() { return this->_points; }

0 comments on commit 7c42169

Please sign in to comment.