#ifndef FRUSTUM_HPP
#define FRUSTUM_HPP
#include "Constants.hpp"
#include "Primitive.hpp"
#include <vector>
namespace wren {
class Camera;
class Frustum {
public:
enum FrustumPlane {
FRUSTUM_PLANE_LEFT,
FRUSTUM_PLANE_RIGHT,
FRUSTUM_PLANE_BOTTOM,
FRUSTUM_PLANE_TOP,
FRUSTUM_PLANE_NEAR,
FRUSTUM_PLANE_FAR
};
enum FrustumCorner {
FRUSTUM_CORNER_NEAR_TOP_LEFT,
FRUSTUM_CORNER_NEAR_TOP_RIGHT,
FRUSTUM_CORNER_NEAR_BOTTOM_LEFT,
FRUSTUM_CORNER_NEAR_BOTTOM_RIGHT,
FRUSTUM_CORNER_FAR_TOP_LEFT,
FRUSTUM_CORNER_FAR_TOP_RIGHT,
FRUSTUM_CORNER_FAR_BOTTOM_LEFT,
FRUSTUM_CORNER_FAR_BOTTOM_RIGHT,
FRUSTUM_CORNER_COUNT
};
Frustum() = default;
explicit Frustum(const glm::mat4 &matrix);
const primitive::Plane &plane(FrustumPlane plane) const { return mPlanes[plane]; }
const std::vector<glm::vec3> &corners() const { return mCorners; }
const primitive::Aabb &aabb() const { return mAabb; }
void recomputeFromMatrix(const glm::dmat4 &matrix);
bool isInside(const primitive::Aabb &aabb) const;
bool isInside(const primitive::Sphere &sphere) const;
private:
void computeCornersFromInverseMatrix(const glm::mat4 &matrix);
void computeAabb() { mAabb = primitive::Aabb(mCorners); }
std::array<primitive::Plane, 6> mPlanes; std::vector<glm::vec3> mCorners; primitive::Aabb mAabb;
};
}
#endif