Skip to content

Commit 4febda9

Browse files
authored
Merge pull request #184 from RayTracing/hollasch/hittable
Fix typo: hitable should be hittable
2 parents 490e87f + 507ee27 commit 4febda9

32 files changed

+356
-356
lines changed

books/RayTracingInOneWeekend.html

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@
398398
#include <iostream>
399399
#include "ray.h"
400400

401-
vec3 color(const ray& r, hitable *world, int depth) {
401+
vec3 color(const ray& r, hittable *world, int depth) {
402402
vec3 unit_direction = unit_vector(r.direction());
403403
float t = 0.5*(unit_direction.y() + 1.0);
404404
return (1.0-t)*vec3(1.0, 1.0, 1.0) + t*vec3(0.5, 0.7, 1.0);
@@ -617,11 +617,11 @@
617617
solution is the make an “abstract class” for anything a ray might hit and make both a sphere and a
618618
list of spheres just something you can hit. What that class should be called is something of a
619619
quandary -- calling it an “object” would be good if not for “object oriented” programming. “Surface”
620-
is often used, with the weakness being maybe we will want volumes. “Hitable” emphasizes the member
621-
function that unites them. I don’t love any of these but I will go with “hitable”.
620+
is often used, with the weakness being maybe we will want volumes. “hittable” emphasizes the member
621+
function that unites them. I don’t love any of these but I will go with “hittable”.
622622

623623
<div class='together'>
624-
This `hitable` abstract class will have a hit function that takes in a ray. Most ray tracers have
624+
This `hittable` abstract class will have a hit function that takes in a ray. Most ray tracers have
625625
found it convenient to add a valid interval for hits $t_{min}$ to $t_{max}$, so the hit only
626626
“counts” if $t_{min} < t < t_{max}$. For the initial rays this is positive $t$, but as we will see,
627627
it can help some details in the code to have an interval $t_{min}$ to $t_{max}$. One design question
@@ -631,8 +631,8 @@
631631
we’ll want motion blur at some point, so I’ll add a time input variable. Here’s the abstract class:
632632

633633
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
634-
#ifndef HITABLEH
635-
#define HITABLEH
634+
#ifndef HITTABLEH
635+
#define HITTABLEH
636636

637637
#include "ray.h"
638638

@@ -643,7 +643,7 @@
643643
vec3 normal;
644644
};
645645

646-
class hitable {
646+
class hittable {
647647
public:
648648
virtual bool hit(
649649
const ray& r, float t_min, float t_max, hit_record& rec) const = 0;
@@ -660,9 +660,9 @@
660660
#ifndef SPHEREH
661661
#define SPHEREH
662662

663-
#include "hitable.h"
663+
#include "hittable.h"
664664

665-
class sphere: public hitable {
665+
class sphere: public hittable {
666666
public:
667667
sphere() {}
668668
sphere(vec3 cen, float r) : center(cen), radius(r) {};
@@ -706,22 +706,22 @@
706706
And a list of objects:
707707

708708
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
709-
#ifndef HITABLELISTH
710-
#define HITABLELISTH
709+
#ifndef HITTABLELISTH
710+
#define HITTABLELISTH
711711

712-
#include "hitable.h"
712+
#include "hittable.h"
713713

714-
class hitable_list: public hitable {
714+
class hittable_list: public hittable {
715715
public:
716-
hitable_list() {}
717-
hitable_list(hitable **l, int n) {list = l; list_size = n; }
716+
hittable_list() {}
717+
hittable_list(hittable **l, int n) {list = l; list_size = n; }
718718
virtual bool hit(
719719
const ray& r, float tmin, float tmax, hit_record& rec) const;
720-
hitable **list;
720+
hittable **list;
721721
int list_size;
722722
};
723723

724-
bool hitable_list::hit(
724+
bool hittable_list::hit(
725725
const ray& r, float t_min, float t_max, hit_record& rec) const {
726726

727727
hit_record temp_rec;
@@ -747,12 +747,12 @@
747747
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
748748
#include <iostream>
749749
#include "sphere.h"
750-
#include "hitable_list.h"
750+
#include "hittable_list.h"
751751
#include "float.h"
752752

753753

754754
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
755-
vec3 color(const ray& r, hitable *world) {
755+
vec3 color(const ray& r, hittable *world) {
756756
hit_record rec;
757757
if (world->hit(r, 0.0, MAXFLOAT, rec)) {
758758
return 0.5*vec3(rec.normal.x()+1, rec.normal.y()+1, rec.normal.z()+1);
@@ -778,10 +778,10 @@
778778

779779

780780
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
781-
hitable *list[2];
781+
hittable *list[2];
782782
list[0] = new sphere(vec3(0,0,-1), 0.5);
783783
list[1] = new sphere(vec3(0,-100.5,-1), 100);
784-
hitable *world = new hitable_list(list,2);
784+
hittable *world = new hittable_list(list,2);
785785
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
786786

787787
for (int j = ny-1; j >= 0; j--) {
@@ -925,10 +925,10 @@
925925
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
926926
std::cout << "P3\n" << nx << " " << ny << "\n255\n";
927927

928-
hitable *list[2];
928+
hittable *list[2];
929929
list[0] = new sphere(vec3(0,0,-1), 0.5);
930930
list[1] = new sphere(vec3(0,-100.5,-1), 100);
931-
hitable *world = new hitable_list(list,2);
931+
hittable *world = new hittable_list(list,2);
932932

933933
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
934934
camera cam;
@@ -1022,7 +1022,7 @@
10221022
Then update the `color()` function to use the new random direction generator:
10231023

10241024
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
1025-
vec3 color(const ray& r, hitable *world, int depth) {
1025+
vec3 color(const ray& r, hittable *world, int depth) {
10261026
hit_record rec;
10271027
if (world->hit(r, 0.0, MAXFLOAT, rec)) {
10281028
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
@@ -1114,13 +1114,13 @@
11141114

11151115
<div class='together'>
11161116
The `hit_record` is to avoid a bunch of arguments so we can stuff whatever info we want in there.
1117-
You can use arguments instead; it’s a matter of taste. Hitables and materials need to know each
1117+
You can use arguments instead; it’s a matter of taste. Hittables and materials need to know each
11181118
other so there is some circularity of the references. In C++ you just need to alert the compiler
1119-
that the pointer is to a class, which the “class material” in the hitable class below does:
1119+
that the pointer is to a class, which the “class material” in the hittable class below does:
11201120

11211121
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
1122-
#ifndef HITABLEH
1123-
#define HITABLEH
1122+
#ifndef HITTABLEH
1123+
#define HITTABLEH
11241124
#include "ray.h"
11251125

11261126
class material;
@@ -1133,7 +1133,7 @@
11331133
material *mat_ptr;
11341134
};
11351135

1136-
class hitable {
1136+
class hittable {
11371137
public:
11381138
virtual bool hit(
11391139
const ray& r, float t_min, float t_max, hit_record& rec) const = 0;
@@ -1155,7 +1155,7 @@
11551155
within `hit_record`. See the lines below marked with **`/* NEW */`**.
11561156

11571157
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
1158-
class sphere: public hitable {
1158+
class sphere: public hittable {
11591159
public:
11601160
sphere() {}
11611161
sphere(vec3 cen, float r, material *m)
@@ -1265,7 +1265,7 @@
12651265
We need to modify the color function to use this:
12661266

12671267
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
1268-
vec3 color(const ray& r, hitable *world, int depth) {
1268+
vec3 color(const ray& r, hittable *world, int depth) {
12691269
hit_record rec;
12701270
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
12711271
if (world->hit(r, 0.001, MAXFLOAT, rec)) {
@@ -1301,12 +1301,12 @@
13011301

13021302

13031303
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
1304-
hitable *list[4];
1304+
hittable *list[4];
13051305
list[0] = new sphere(vec3(0,0,-1), 0.5, new lambertian(vec3(0.1, 0.2, 0.5)));
13061306
list[1] = new sphere(vec3(0,-100.5,-1), 100, new lambertian(vec3(0.8, 0.8, 0.0)));
13071307
list[2] = new sphere(vec3(1,0,-1), 0.5, new metal(vec3(0.8, 0.6, 0.2), 0.0));
13081308
list[3] = new sphere(vec3(-1,0,-1), 0.5, new metal(vec3(0.8, 0.8, 0.8)));
1309-
hitable *world = new hitable_list(list,4);
1309+
hittable *world = new hittable_list(list,4);
13101310
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
13111311

13121312
camera cam;
@@ -1677,7 +1677,7 @@
16771677
float R = cos(M_PI/4);
16781678
list[0] = new sphere(vec3(-R,0,-1), R, new lambertian(vec3(0, 0, 1)));
16791679
list[1] = new sphere(vec3( R,0,-1), R, new lambertian(vec3(1, 0, 0)));
1680-
hitable *world = new hitable_list(list,2);
1680+
hittable *world = new hittable_list(list,2);
16811681
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
16821682

16831683
gives:
@@ -1893,9 +1893,9 @@
18931893
First let’s make the image on the cover of this book -- lots of random spheres:
18941894

18951895
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
1896-
hitable *random_scene() {
1896+
hittable *random_scene() {
18971897
int n = 500;
1898-
hitable **list = new hitable*[n+1];
1898+
hittable **list = new hittable*[n+1];
18991899
list[0] = new sphere(vec3(0,-1000,0), 1000, new lambertian(vec3(0.5, 0.5, 0.5)));
19001900
int i = 1;
19011901
for (int a = -11; a < 11; a++) {
@@ -1929,7 +1929,7 @@
19291929
list[i++] = new sphere(vec3(-4, 1, 0), 1.0, new lambertian(vec3(0.4, 0.2, 0.1)));
19301930
list[i++] = new sphere(vec3(4, 1, 0), 1.0, new metal(vec3(0.7, 0.6, 0.5), 0.0));
19311931

1932-
return new hitable_list(list,i);
1932+
return new hittable_list(list,i);
19331933
}
19341934
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19351935
</div>
@@ -1965,7 +1965,7 @@
19651965
blog.
19661966

19671967
6. Volumes and media. Cool stuff and will challenge your software architecture. I favor making
1968-
volumes have the hitable interface and probabilistically have intersections based on density.
1968+
volumes have the hittable interface and probabilistically have intersections based on density.
19691969
Your rendering code doesn’t even have to know it has volumes with that method.
19701970

19711971
7. Parallelism. Run $N$ copies of your code on $N$ cores with different random seeds. Average the

0 commit comments

Comments
 (0)