
#include "camera.h"

using namespace Eigen;

Camera::Camera()
{
    mViewMatrix.setIdentity();
    mProjectionMatrix.setIdentity();
}

void Camera::lookAt(const Eigen::Vector3f& position, const Eigen::Vector3f& target, const Eigen::Vector3f& up)
{
    // TODO calculer la matrice de vue : mViewMatrix
}

void Camera::setPerspective(float fovY, float aspect, float near, float far)
{
    float range = far - near;
    float invtan = 1./tan(fovY*0.5);

    mProjectionMatrix(0,0) = invtan / aspect;
    mProjectionMatrix(1,1) = invtan;
    mProjectionMatrix(2,2) = -(near + far) / range;
    mProjectionMatrix(3,2) = -1;
    mProjectionMatrix(2,3) = -2 * near * far / range;
    mProjectionMatrix(3,3) = 0;
}

Camera::~Camera()
{
}

const Matrix4f& Camera::viewMatrix() const
{
    return mViewMatrix;
}

const Matrix4f& Camera::projectionMatrix() const
{
    return mProjectionMatrix;
}
