<commit_before>#include "PerspectiveCamera.h"
#define _USE_MATH_DEFINES

#include <cmath>
PerspectiveCamera::PerspectiveCamera()
  : Camera() {
}

PerspectiveCamera::PerspectiveCamera(const Point3D& position, const uint32_t image_height, const uint32_t image_width, Renderer * renderer, const float fov)
  : Camera(position, image_height, image_width, renderer), m_fov(fov) {
  m_zoom = 1 / tan((fov/ 2) * 3.1415926535897 / 180);
}

PerspectiveCamera::~PerspectiveCamera() {

}

const Vector3D PerspectiveCamera::viewDirection(const Point3D& point) const {
  Vector3D view = point - m_position;
  view.normalize();
  return view;
}

// TODO: generic
const Point2D PerspectiveCamera::projectTransform(const Point3D& point_camera) const {
  // Perspective divide
  const Point2D point_projected = {
    (point_camera.x * m_near * m_zoom) / (point_camera.z * get_aspect()),
    (point_camera.y * m_near * m_zoom) / (point_camera.z * get_aspect())
  };

  return point_projected;
}

const Point3D PerspectiveCamera::projectTransformInv(const Point2D& point_projected, const double depth) const {
  const Point3D point_world = {
    (point_projected.x * depth * get_aspect()) / (m_near * m_zoom),
    (point_projected.y * depth * get_aspect()) / (m_near * m_zoom),
    depth
  };

  return point_world;
}<commit_msg>Added formula to normalize between [-1,1] in perspective divide<commit_after>#include "PerspectiveCamera.h"
#define _USE_MATH_DEFINES

#include <cmath>
PerspectiveCamera::PerspectiveCamera()
  : Camera() {
}

PerspectiveCamera::PerspectiveCamera(const Point3D& position, const uint32_t image_height, const uint32_t image_width, Renderer * renderer, const float fov)
  : Camera(position, image_height, image_width, renderer), m_fov(fov) {
  m_zoom = 1 / tan((fov/ 2) * 3.1415926535897 / 180);
}

PerspectiveCamera::~PerspectiveCamera() {

}

const Vector3D PerspectiveCamera::viewDirection(const Point3D& point) const {
  Vector3D view = point - m_position;
  view.normalize();
  return view;
}

// TODO: generic
const Point2D PerspectiveCamera::projectTransform(const Point3D& point_camera) const {
  // Perspective divide
  const double z_norm = ((m_far + m_near) / (m_far - m_near)) + 
                      (1 / point_camera.z) * ((2.0 * m_near*m_far) / (m_far - m_near));

  const Point2D point_projected = {
    (point_camera.x  * m_zoom) / (z_norm ),
    (point_camera.y  * m_zoom) / (z_norm )
  };

  return point_projected;
}

const Point3D PerspectiveCamera::projectTransformInv(const Point2D& point_projected, const double depth) const {
  const double z_norm = ((m_far + m_near) / (m_far - m_near)) + 
                      (1 / depth) * ((2 * m_near*m_far) / (m_far - m_near));

  const Point3D point_world = {
    (point_projected.x * z_norm ) / (m_zoom),
    (point_projected.y * z_norm ) / (m_zoom),
    depth
  };

  return point_world;
}
{'fraction_non_alphanumeric': 0.12076788830715532, 'fraction_numerical': 0.02547993019197208, 'mean_word_length': 4.287822878228782, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5077910', 'n_tokens_mistral': 1050, 'n_tokens_neox': 993, 'n_words': 220}