<commit_before>/* Created on: Feb 2, 2016
 *     Author: T.Delame (<EMAIL>)
 */
# include "../../graphics-origin/application/camera.h"
# include "../../graphics-origin/tools/log.h"
namespace graphics_origin {
namespace application {

  camera::camera( QObject* parent )
    : QObject{ parent },
      m_fov{1.04}, m_ratio{1.0}, m_znear{0.05}, m_zfar{ 15},
      m_view{ glm::lookAt( gpu_vec3{3,0,0}, gpu_vec3{}, gpu_vec3{0,0,1})},
      m_projection{ glm::perspective( m_fov, m_ratio, m_znear, m_zfar ) }
  {}

  const gpu_mat4&
  camera::get_view_matrix() const
  {
    return m_view;
  }

  void
  camera::set_view_matrix( const gpu_mat4& view )
  {
    m_view = view;
  }

  gpu_vec3
  camera::get_position() const
  {
    return -gpu_vec3( m_view[3] ) * gpu_mat3( m_view );
  }

  QVector3D
  camera::qml_get_position() const
  {
    auto pos = get_position();
    return QVector3D( pos.x, pos.y, pos.z );
  }

  gpu_vec3
  camera::get_right() const
  {
    return gpu_vec3{ m_view[0][0], m_view[1][0], m_view[2][0] };
  }

  QVector3D
  camera::qml_get_right() const
  {
    auto right = get_right();
    return QVector3D( right.x, right.y, right.z );
  }

  gpu_vec3
  camera::get_up() const
  {
    return gpu_vec3{ m_view[0][1], m_view[1][1], m_view[2][1] };
  }

  QVector3D
  camera::qml_get_up() const
  {
    auto up = get_up();
    return QVector3D( up.x, up.y, up.z );
  }

  gpu_vec3
  camera::get_forward() const
  {
    return gpu_vec3{ -m_view[0][2], -m_view[1][2], -m_view[2][2] };
  }

  QVector3D
  camera::qml_get_forward() const
  {
    auto forward = get_forward();
    return QVector3D( forward.x, forward.y, forward.z );
  }

  void
  camera::set_position( const gpu_vec3& pos )
  {
    for( int i = 0; i < 3; ++ i )
      {
        m_view[3][i] = gpu_real(0);
        for( int j = 0; j < 3; ++ j )
          m_view[3][i] -= m_view[j][i] * pos[j];
      }
//
//    if( std::isnan( m_view[3][0] )
//     || std::isnan( m_view[3][1] )
//     || std::isnan( m_view[3][2] ) )
//    {
//        LOG( error, "IS NAN from " << pos );
//    }
  }

  void
  camera::qml_set_position( const QVector3D& pos )
  {
    for( int i = 0; i < 3; ++ i )
      {
        m_view[3][i] = gpu_real(0);
        for( int j = 0; j < 3; ++ j )
          m_view[3][i] -= m_view[j][i] * pos[j];
      }
  }

  void camera::set_right( const gpu_vec3& right )
  {
      gpu_vec3 minus_pos = gpu_vec3( m_view[3] ) * gpu_mat3( m_view );
      m_view[0][0] = right.x;
      m_view[1][0] = right.y;
      m_view[2][0] = right.z;
      m_view[3][0] = dot( right, minus_pos );
  }

  void camera::qml_set_right( const QVector3D& right )
  {
    set_right( gpu_vec3{ right[0], right[1], right[2] } );
  }

  void camera::set_up( const gpu_vec3& up )
  {
    gpu_vec3 minus_pos = gpu_vec3( m_view[3] ) * gpu_mat3( m_view );
    m_view[0][1] = up.x;
    m_view[1][1] = up.y;
    m_view[2][1] = up.z;
    m_view[3][1] = dot( up, minus_pos );
  }

  void camera::qml_set_up( const QVector3D& up )
  {
    set_up( gpu_vec3{ up[0], up[1], up[2] } );
  }

  void camera::set_forward( const gpu_vec3& forward )
  {
    gpu_vec3 pos = -gpu_vec3( m_view[3] ) * gpu_mat3( m_view );
    m_view[0][0] = -forward.x;
    m_view[1][0] = -forward.y;
    m_view[2][0] = -forward.z;
    m_view[3][0] = dot( forward, pos );
  }

  void camera::qml_set_forward( const QVector3D& forward )
  {
    set_forward( gpu_vec3{ forward[0], forward[1], forward[2] } );
  }

  const gpu_mat4&
  camera::get_projection_matrix() const
  {
    return m_projection;
  }

  qreal camera::get_fov() const
  {
    return m_fov;
  }
<commit_msg>fix a bug in the camera<commit_after>/* Created on: Feb 2, 2016
 *     Author: T.Delame (<EMAIL>)
 */
# include "../../graphics-origin/application/camera.h"
# include "../../graphics-origin/tools/log.h"
namespace graphics_origin {
namespace application {

  camera::camera( QObject* parent )
    : QObject{ parent },
      m_fov{1.04}, m_ratio{1.0}, m_znear{0.05}, m_zfar{ 15},
      m_view{ glm::lookAt( gpu_vec3{3,0,0}, gpu_vec3{}, gpu_vec3{0,0,1})},
      m_projection{ glm::perspective( m_fov, m_ratio, m_znear, m_zfar ) }
  {}

  const gpu_mat4&
  camera::get_view_matrix() const
  {
    return m_view;
  }

  void
  camera::set_view_matrix( const gpu_mat4& view )
  {
    m_view = view;
  }

  gpu_vec3
  camera::get_position() const
  {
    return -gpu_vec3( m_view[3] ) * gpu_mat3( m_view );
  }

  QVector3D
  camera::qml_get_position() const
  {
    auto pos = get_position();
    return QVector3D( pos.x, pos.y, pos.z );
  }

  gpu_vec3
  camera::get_right() const
  {
    return gpu_vec3{ m_view[0][0], m_view[1][0], m_view[2][0] };
  }

  QVector3D
  camera::qml_get_right() const
  {
    auto right = get_right();
    return QVector3D( right.x, right.y, right.z );
  }

  gpu_vec3
  camera::get_up() const
  {
    return gpu_vec3{ m_view[0][1], m_view[1][1], m_view[2][1] };
  }

  QVector3D
  camera::qml_get_up() const
  {
    auto up = get_up();
    return QVector3D( up.x, up.y, up.z );
  }

  gpu_vec3
  camera::get_forward() const
  {
    return gpu_vec3{ -m_view[0][2], -m_view[1][2], -m_view[2][2] };
  }

  QVector3D
  camera::qml_get_forward() const
  {
    auto forward = get_forward();
    return QVector3D( forward.x, forward.y, forward.z );
  }

  void
  camera::set_position( const gpu_vec3& pos )
  {
    for( int i = 0; i < 3; ++ i )
      {
        m_view[3][i] = gpu_real(0);
        for( int j = 0; j < 3; ++ j )
          m_view[3][i] -= m_view[j][i] * pos[j];
      }
  }

  void
  camera::qml_set_position( const QVector3D& pos )
  {
    for( int i = 0; i < 3; ++ i )
      {
        m_view[3][i] = gpu_real(0);
        for( int j = 0; j < 3; ++ j )
          m_view[3][i] -= m_view[j][i] * pos[j];
      }
  }

  void camera::set_right( const gpu_vec3& right )
  {
      gpu_vec3 minus_pos = gpu_vec3( m_view[3] ) * gpu_mat3( m_view );
      m_view[0][0] = right.x;
      m_view[1][0] = right.y;
      m_view[2][0] = right.z;
      m_view[3][0] = dot( right, minus_pos );
  }

  void camera::qml_set_right( const QVector3D& right )
  {
    set_right( gpu_vec3{ right[0], right[1], right[2] } );
  }

  void camera::set_up( const gpu_vec3& up )
  {
    gpu_vec3 minus_pos = gpu_vec3( m_view[3] ) * gpu_mat3( m_view );
    m_view[0][1] = up.x;
    m_view[1][1] = up.y;
    m_view[2][1] = up.z;
    m_view[3][1] = dot( up, minus_pos );
  }

  void camera::qml_set_up( const QVector3D& up )
  {
    set_up( gpu_vec3{ up[0], up[1], up[2] } );
  }

  void camera::set_forward( const gpu_vec3& forward )
  {
    gpu_vec3 pos = -gpu_vec3( m_view[3] ) * gpu_mat3( m_view );
    m_view[0][2] = -forward.x;
    m_view[1][2] = -forward.y;
    m_view[2][2] = -forward.z;
    m_view[3][2] = dot( forward, pos );
  }

  void camera::qml_set_forward( const QVector3D& forward )
  {
    set_forward( gpu_vec3{ forward[0], forward[1], forward[2] } );
  }

  const gpu_mat4&
  camera::get_projection_matrix() const
  {
    return m_projection;
  }

  qreal camera::get_fov() const
  {
    return m_fov;
  }

{'fraction_non_alphanumeric': 0.17433414043583534, 'fraction_numerical': 0.0387409200968523, 'mean_word_length': 2.7450666666666668, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 5, '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': '3275880', 'n_tokens_mistral': 3184, 'n_tokens_neox': 3083, 'n_words': 576}