Program Listing for File ViewFrustumCulling.ixx#
↰ Return to documentation for file (Src/GraphicsEngineOpenGL/scene/ViewFrustumCulling.ixx)
module;
#include <glad/glad.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <memory>
#include <vector>
#include "host_device/GlobalValues.hpp"
export module kataglyphis.opengl.view_frustum_culling;
import kataglyphis.shared.scene.camera;
import kataglyphis.opengl.aabb;
import kataglyphis.opengl.texture;
export class ViewFrustumCulling
{
public:
ViewFrustumCulling();
bool is_inside(GLfloat aspect_ratio,
const Camera &main_camera,
AABB &bounding_box,
const glm::mat4 &model);
void render_view_frustum() const;
~ViewFrustumCulling();
private:
// render view frustum
unsigned int VBO, VAO, EBO;
unsigned int m_drawCount;
// we get that as input
GLfloat near_plane, far_plane, fov, ratio;
// calculate as soon as we become params
GLfloat tan, near_height, near_width, far_height, far_width;
glm::vec3 dir, near_center, far_center;
// all corners of the frustum
// near plane
glm::vec3 near_top_left, near_top_right, near_bottom_left, near_bottom_right;
// far plane
glm::vec3 far_top_left, far_top_right, far_bottom_left, far_bottom_right;
// planes in Hesse normal form
// layout: [0]: near plane, [1] far plane, [2] front, [3] bottom, [4]: left,
// [5]: right
struct frustum_plane
{
glm::vec3 normal;
glm::vec3 position;
};
frustum_plane frustum_planes[NUM_FRUSTUM_PLANES];
void init(const std::vector<glm::vec3> &frustum_corner);
bool corners_outside_plane(const std::vector<glm::vec3> &aabb_corners, frustum_plane plane, GLuint outcode_pattern);
static GLfloat plane_point_distance(frustum_plane plane, glm::vec3 corner);
void update_frustum_param(GLfloat cam_near,
GLfloat cam_far,
GLfloat cam_fov,
GLfloat aspect_ratio,
const Camera &main_camera);
};