#include <cmath>

#include "client/math/Frustum.h"

Frustum::Frustum(float fovY, float nearClip, float farClip) : fovY(fovY), nearClip(nearClip), farClip(farClip) {
}

void Frustum::setProjection(Matrix& m, int width, int height) {
    float tan = tanf((0.5f * fovY) * M_PI / 180.0f);
    float q = 1.0f / tan;
    float aspect = (float) width / height;

    m.set(0, q / aspect);
    m.set(1, 0.0f);
    m.set(2, 0.0f);
    m.set(3, 0.0f);
    m.set(4, 0.0f);
    m.set(5, q);
    m.set(6, 0.0f);
    m.set(7, 0.0f);
    m.set(8, 0.0f);
    m.set(9, 0.0f);
    m.set(10, (nearClip + farClip) / (nearClip - farClip));
    m.set(11, -1.0f);
    m.set(12, 0.0f);
    m.set(13, 0.0f);
    m.set(14, (2.0f * nearClip * farClip) / (nearClip - farClip));
    m.set(15, 0.0f);
}