<commit_before>#include "camera.h"
#include <math.h>

#include <glew.h>



using namespace GluonGraphics;

Camera::Camera()
{
    mFoV = 45.0f;
    mAspect = 1.0f;
    mDepthNear = -1000.0f;
    mDepthFar = 1000.0f;
    mPosition = QVector3D(0, 0, 100);
    mLookAt = QVector3D(0, 0, -1);
    mUp = QVector3D(0, 1, 0);
    mModelviewMatrixDirty = true;
    mProjectionMatrixDirty = true;
}

Camera::~Camera()
{
}

void Camera::setFoV(float fov)
{
    mFoV = fov;
    mProjectionMatrixDirty = true;
}

void Camera::setAspect(float aspect)
{
    mAspect = aspect;
    mProjectionMatrixDirty = true;
}

void Camera::setDepthRange(float near, float far)
{
    mDepthNear = near;
    mDepthFar = far;
    mProjectionMatrixDirty = true;
}

void Camera::setPosition(const QVector3D& pos)
{
    mPosition = pos;
    mModelviewMatrixDirty = true;
}

void Camera::setLookAt(const QVector3D& lookat)
{
    mLookAt = lookat;
    mModelviewMatrixDirty = true;
}

void Camera::setUp(const QVector3D& up)
{
    mUp = up;
    mModelviewMatrixDirty = true;
}

void Camera::setDirection(const QVector3D& dir)
{
    setLookAt(mPosition + dir);
}

void Camera::setViewport(int x, int y, int width, int height)
{
    mViewport[0] = x;
    mViewport[1] = y;
    mViewport[2] = width;
    mViewport[3] = height;
}

void Camera::applyPerspective()
{
    if (mProjectionMatrixDirty) {
        recalculateProjectionMatrix();
    }

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glMultMatrixd((GLdouble*)(mProjectionMatrix.data()));
    //glOrtho(, 5, -5, 5, mDepthNear, mDepthFar);
    glMatrixMode(GL_MODELVIEW);
}

void Camera::applyOrtho()
{
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    float left = mViewport[0] / 10.0f - mViewport[2] / 20.0f;
    float right = (mViewport[0] + mViewport[2]) / 20.0f;
    float top = mViewport[1] / 10.0f - mViewport[3] / 20.0f;
    float bottom = (mViewport[1] + mViewport[3]) / 20.0f;

    glOrtho(left, right, top, bottom, mDepthNear, mDepthFar);
    glMatrixMode(GL_MODELVIEW);
}

void Camera::applyView(bool reset)
{
    if (mModelviewMatrixDirty) {
        recalculateModelviewMatrix();
    }

    if (reset) {
        glLoadIdentity();
    }
    glMultMatrixd((GLdouble*)(mModelviewMatrix.data()));
}

void Camera::applyViewport()
{
    glViewport(mViewport[0], mViewport[1], mViewport[2], mViewport[3]);
}

void Camera::recalculateModelviewMatrix()
{
     // Code from Mesa project, src/glu/sgi/libutil/project.c
  mModelviewMatrixDirty = false;
  QVector3D forward = (mLookAt - mPosition).normalized();
  QVector3D side = QVector3D::crossProduct(forward,mUp).normalized();
  QVector3D up = QVector3D::crossProduct(side,forward);
  
  mModelviewMatrix.setToIdentity();
  mModelviewMatrix.setColumn(0,QVector4D(side.x(),side.y(),side.z(),0));
  mModelviewMatrix.setColumn(1,QVector4D(up.x(),up.y(),up.z(),0));
 mModelviewMatrix.setColumn(2,QVector4D(-forward.x(),-forward.y(),-forward.z(),0));
 mModelviewMatrix.translate(-mPosition);
	



}

void Camera::recalculateProjectionMatrix()
{
    // Code from Mesa project, src/glu/sgi/libutil/project.c
    mProjectionMatrixDirty = false;
    mProjectionMatrix.setToIdentity();

    float radians = mFoV / 2 * M_PI / 180;

    float deltaZ = mDepthFar - mDepthNear;
//    float sine = Eigen::ei_sin(radians);
     float sine = sin(radians);
    if ((deltaZ == 0) || (sine == 0) || (mAspect == 0)) {
        return;
    }
//    float cotangent = Eigen::ei_cos(radians) / sine;
      float cotangent = cos(radians) / sine;<commit_msg>Fix the coordinate system so that +y is up, +x is left and -z is into screen.<commit_after>#include "camera.h"
#include <math.h>

#include <glew.h>



using namespace GluonGraphics;

Camera::Camera()
{
    mFoV = 45.0f;
    mAspect = 1.0f;
    mDepthNear = -1000.0f;
    mDepthFar = 1000.0f;
    mPosition = QVector3D(0, 0, 100);
    mLookAt = QVector3D(0, 0, -1);
    mUp = QVector3D(0, 1, 0);
    mModelviewMatrixDirty = true;
    mProjectionMatrixDirty = true;
}

Camera::~Camera()
{
}

void Camera::setFoV(float fov)
{
    mFoV = fov;
    mProjectionMatrixDirty = true;
}

void Camera::setAspect(float aspect)
{
    mAspect = aspect;
    mProjectionMatrixDirty = true;
}

void Camera::setDepthRange(float near, float far)
{
    mDepthNear = near;
    mDepthFar = far;
    mProjectionMatrixDirty = true;
}

void Camera::setPosition(const QVector3D& pos)
{
    mPosition = pos;
    mModelviewMatrixDirty = true;
}

void Camera::setLookAt(const QVector3D& lookat)
{
    mLookAt = lookat;
    mModelviewMatrixDirty = true;
}

void Camera::setUp(const QVector3D& up)
{
    mUp = up;
    mModelviewMatrixDirty = true;
}

void Camera::setDirection(const QVector3D& dir)
{
    setLookAt(mPosition + dir);
}

void Camera::setViewport(int x, int y, int width, int height)
{
    mViewport[0] = x;
    mViewport[1] = y;
    mViewport[2] = width;
    mViewport[3] = height;
}

void Camera::applyPerspective()
{
    if (mProjectionMatrixDirty) {
        recalculateProjectionMatrix();
    }

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glMultMatrixd((GLdouble*)(mProjectionMatrix.data()));
    //glOrtho(, 5, -5, 5, mDepthNear, mDepthFar);
    glMatrixMode(GL_MODELVIEW);
}

void Camera::applyOrtho()
{
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    float left = mViewport[0] / 10.0f - mViewport[2] / 20.0f;
    float right = (mViewport[0] + mViewport[2]) / 20.0f;
    float top = mViewport[1] / 10.0f - mViewport[3] / 20.0f;
    float bottom = (mViewport[1] + mViewport[3]) / 20.0f;

    glOrtho(left, right, top, bottom, mDepthNear, mDepthFar);
    glMatrixMode(GL_MODELVIEW);
}

void Camera::applyView(bool reset)
{
    if (mModelviewMatrixDirty) {
        recalculateModelviewMatrix();
    }

    if (reset) {
        glLoadIdentity();
    }
    glMultMatrixd((GLdouble*)(mModelviewMatrix.data()));
}

void Camera::applyViewport()
{
    glViewport(mViewport[0], mViewport[1], mViewport[2], mViewport[3]);
}

void Camera::recalculateModelviewMatrix()
{
     // Code from Mesa project, src/glu/sgi/libutil/project.c
    mModelviewMatrixDirty = false;
    QVector3D forward = mLookAt.normalized();
    QVector3D side = -QVector3D::crossProduct(forward, mUp).normalized();
    QVector3D up = QVector3D::crossProduct(side,forward);

    mModelviewMatrix.setToIdentity();
    mModelviewMatrix.setColumn(0, QVector4D(side.x(),side.y(),side.z(),0));
    mModelviewMatrix.setColumn(1, QVector4D(up.x(),up.y(),up.z(),0));
    mModelviewMatrix.setColumn(2, QVector4D(-forward.x(),-forward.y(),-forward.z(),0));
    mModelviewMatrix.translate(mPosition);
}

void Camera::recalculateProjectionMatrix()
{
    // Code from Mesa project, src/glu/sgi/libutil/project.c
    mProjectionMatrixDirty = false;
    mProjectionMatrix.setToIdentity();

    float radians = mFoV / 2 * M_PI / 180;

    float deltaZ = mDepthFar - mDepthNear;
//    float sine = Eigen::ei_sin(radians);
     float sine = sin(radians);
    if ((deltaZ == 0) || (sine == 0) || (mAspect == 0)) {
        return;
    }
//    float cotangent = Eigen::ei_cos(radians) / sine;
      float cotangent = cos(radians) / sine;
{'fraction_non_alphanumeric': 0.14448348559381588, 'fraction_numerical': 0.025579761068165847, 'mean_word_length': 3.7032385988103105, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3055652', 'n_tokens_mistral': 2818, 'n_tokens_neox': 2676, 'n_words': 492}