#ifndef FRUSTUM_H
#define FRUSTUM_H

#include "math/Matrix.h"
#include "math/Plane.h"
#include "utils/Array.h"
#include "utils/Size.h"
#include "utils/StringBuffer.h"

class Frustum final {
    Matrix projection;
    const Size& size;
    Array<Plane, 6> planes;

public:
    float fieldOfView;
    float nearClip;
    float farClip;

    Frustum(float fieldOfView, float nearClip, float farClip, const Size& size);
    Matrix& updateProjection();
    void updatePlanes(const Vector3& pos, const Vector3& right, const Vector3& up, const Vector3& front);

    bool isInside(const Vector3& pos) const;
    bool isInside(const Vector3& pos, float radius) const;

    template<int L>
    void toString(StringBuffer<L>& s) const {
        s.append("(fieldOfView = ").append(fieldOfView);
        s.append(", nearClip = ").append(nearClip);
        s.append(", farClip = ").append(farClip);
        s.append(", width = ").append(size.width);
        s.append(", height = ").append(size.height);
        s.append(')');
    }
};

#endif