Skip to content

Commit

Permalink
stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
JulioJPinto committed May 27, 2024
1 parent 669f0b8 commit a86f44c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
25 changes: 25 additions & 0 deletions engine/include/frustsum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <math.h>
#include <iostream>
#include <glm/glm.hpp>
#include <GL/freeglut.h>
#include "Window.hpp"
#include "Camera.hpp"

Expand All @@ -29,6 +30,19 @@ struct Plane {
}


void drawPlane() {
// Draw the plane
glBegin(GL_QUADS);
glNormal3f(normal.x, normal.y, normal.z);
glVertex3f(point.x + 1000, point.y, point.z + 1000);
glVertex3f(point.x + 1000, point.y, point.z - 1000);
glVertex3f(point.x - 1000, point.y, point.z - 1000);
glVertex3f(point.x - 1000, point.y, point.z + 1000);
glEnd();
}



};

struct Frustsum {
Expand Down Expand Up @@ -61,6 +75,17 @@ struct Frustsum {
bottomFace.printPlane();
}

void drawFrustsum() {
if (on) {
nearFace.drawPlane();
farFace.drawPlane();
rightFace.drawPlane();
leftFace.drawPlane();
topFace.drawPlane();
bottomFace.drawPlane();
}
}

};


Expand Down
4 changes: 3 additions & 1 deletion engine/src/frustsum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Frustsum::Frustsum(const Camera& cam, float ratio, bool on) {
}

float aspect = ratio;
glm::vec3 front = glm::normalize(cam.lookAt - cam.position);
glm::vec3 front = cam.forward;
float fovRadians = glm::radians(static_cast<float>(cam.fov));

float halfHSide = cam.far * tanf(fovRadians * 0.5f);
Expand Down Expand Up @@ -51,6 +51,8 @@ Frustsum::Frustsum(const Camera& cam, float ratio, bool on) {
leftFace = { leftNormal, leftPoint };
topFace = { topNormal, topPoint };
bottomFace = { bottomNormal, bottomPoint };

drawFrustsum();
}


Expand Down
2 changes: 1 addition & 1 deletion engine/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ void renderScene(void) {
lookat.x , lookat.y, lookat.z,
camera.up.x, camera.up.y, camera.up.z);

Frustsum frustsum = Frustsum(camera, glutGet(GLUT_WINDOW_WIDTH) / glutGet(GLUT_WINDOW_HEIGHT), culling);
Frustsum frustsum = Frustsum(c.camera, c.window.width / c.window.height, culling);

fillMode();
drawAxis();
Expand Down
4 changes: 2 additions & 2 deletions imgui.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ Collapsed=0
[Window][Infos]
Pos=15,18
Size=325,139
Collapsed=0
Collapsed=1

[Window][Options]
Pos=15,169
Size=312,124
Collapsed=0
Collapsed=1

[Window][Models]
Pos=17,306
Expand Down

0 comments on commit a86f44c

Please sign in to comment.