Skip to content

Commit

Permalink
Add degrees_to_radians() utility function
Browse files Browse the repository at this point in the history
Resolves #217
  • Loading branch information
Steve Hollasch committed Oct 22, 2019
1 parent 522a200 commit 6833c58
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/InOneWeekend/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class camera {
camera(vec3 lookfrom, vec3 lookat, vec3 vup, double vfov, double aspect, double aperture, double focus_dist) {
// vfov is top to bottom in degrees
lens_radius = aperture / 2;
auto theta = vfov*pi/180;
auto theta = degrees_to_radians(vfov);
auto half_height = tan(theta/2);
auto half_width = aspect * half_height;
origin = lookfrom;
Expand Down
8 changes: 6 additions & 2 deletions src/TheNextWeek/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ vec3 random_in_unit_disk() {
class camera {
public:
// new: add t0 and t1
camera(vec3 lookfrom, vec3 lookat, vec3 vup, double vfov, double aspect, double aperture, double focus_dist, double t0, double t1) { // vfov is top to bottom in degrees
camera(
vec3 lookfrom, vec3 lookat, vec3 vup,
double vfov, // vfov is top to bottom in degrees
double aspect, double aperture, double focus_dist, double t0, double t1
) {
time0 = t0;
time1 = t1;
lens_radius = aperture / 2;
auto theta = vfov*pi/180;
auto theta = degrees_to_radians(vfov);
auto half_height = tan(theta/2);
auto half_width = aspect * half_height;
origin = lookfrom;
Expand Down
2 changes: 1 addition & 1 deletion src/TheNextWeek/hittable.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class rotate_y : public hittable {
};

rotate_y::rotate_y(hittable *p, double angle) : ptr(p) {
auto radians = (pi / 180.) * angle;
auto radians = degrees_to_radians(angle);
sin_theta = sin(radians);
cos_theta = cos(radians);
hasbox = ptr->bounding_box(0, 1, bbox);
Expand Down
2 changes: 1 addition & 1 deletion src/TheRestOfYourLife/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class camera {
time0 = t0;
time1 = t1;
lens_radius = aperture / 2;
auto theta = vfov*pi/180;
auto theta = degrees_to_radians(vfov);
auto half_height = tan(theta/2);
auto half_width = aspect * half_height;
origin = lookfrom;
Expand Down
2 changes: 1 addition & 1 deletion src/TheRestOfYourLife/hittable.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class rotate_y : public hittable {
};

rotate_y::rotate_y(hittable *p, double angle) : ptr(p) {
auto radians = (pi / 180.) * angle;
auto radians = degrees_to_radians(angle);
sin_theta = sin(radians);
cos_theta = cos(radians);
hasbox = ptr->bounding_box(0, 1, bbox);
Expand Down
6 changes: 5 additions & 1 deletion src/common/rtweekend.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@

// Constants

const double pi = 3.1415926535897932385;
const double infinity = std::numeric_limits<double>::infinity();
const double pi = 3.1415926535897932385;

// Utility Functions

inline double degrees_to_radians(double degrees) {
return degrees * pi / 180.0;
}

inline double clamp(double x, double min, double max) {
if (x < min) return min;
if (x > max) return max;
Expand Down

0 comments on commit 6833c58

Please sign in to comment.