Skip to content

Commit

Permalink
Clean up C++ implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Zentrik committed Sep 16, 2023
1 parent e521e6b commit ee16bfb
Show file tree
Hide file tree
Showing 31 changed files with 311 additions and 11,898 deletions.
37 changes: 0 additions & 37 deletions c++/RayTracerC++.sln

This file was deleted.

195 changes: 0 additions & 195 deletions c++/RayTracerC++.vcxproj

This file was deleted.

51 changes: 0 additions & 51 deletions c++/RayTracerC++.vcxproj.filters

This file was deleted.

4 changes: 0 additions & 4 deletions c++/RayTracerC++.vcxproj.user

This file was deleted.

90 changes: 45 additions & 45 deletions c++/camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,49 @@
#include "header.hpp"

class camera {
private:
point3 origin;
point3 lower_left_corner;
vec3 horizontal;
vec3 vertical;
vec3 u, v, w;
float lens_radius;

public:
camera(
point3 lookfrom,
point3 lookat,
vec3 vup,
float vfov, // vertical field-of-view in degrees
float aspect_ratio,
float aperture,
float focus_dist
) {
auto theta = degrees_to_radians(vfov);
auto h = tan(theta/2);
auto viewport_height = 2.0 * h;
auto viewport_width = aspect_ratio * viewport_height;

w = normalised(lookfrom - lookat);
u = normalised(cross(vup, w));
v = cross(w, u);

origin = lookfrom;
horizontal = focus_dist * viewport_width * u;
vertical = focus_dist * viewport_height * v;
lower_left_corner = origin - horizontal/2 - vertical/2 - focus_dist*w;

lens_radius = aperture / 2;
}


ray get_ray(float s, float t, random_series &Series) const {
vec3 rd = lens_radius * uniform_random_in_unit_disk(Series);
vec3 offset = u * rd.x() + v * rd.y();

return ray(
origin + offset,
lower_left_corner + s*horizontal + t*vertical - origin - offset
);
}
private:
point3 origin;
point3 lower_left_corner;
vec3 horizontal;
vec3 vertical;
vec3 u, v, w;
float lens_radius;

public:
camera(
point3 lookfrom,
point3 lookat,
vec3 vup,
float vfov, // vertical field-of-view in degrees
float aspect_ratio,
float aperture,
float focus_dist
) {
auto theta = degrees_to_radians(vfov);
auto h = tanf(theta/2);
auto viewport_height = 2 * h;
auto viewport_width = aspect_ratio * viewport_height;

w = normalised(lookfrom - lookat);
u = normalised(cross(vup, w));
v = cross(w, u);

origin = lookfrom;
horizontal = focus_dist * viewport_width * u;
vertical = focus_dist * viewport_height * v;
lower_left_corner = origin - horizontal/2 - vertical/2 - focus_dist*w;

lens_radius = aperture / 2;
}


ray get_ray(float s, float t, RNG& rng) const {
vec3 rd = lens_radius * uniform_random_in_unit_disk(rng);
vec3 offset = u * rd.x + v * rd.y;

return ray(
origin + offset,
normalised(lower_left_corner + s*horizontal + t*vertical - origin - offset)
);
}
};
Loading

0 comments on commit ee16bfb

Please sign in to comment.