Skip to content

Commit 93d0a8b

Browse files
committed
Fix typo: hitable should be hittable
1 parent 7a84b39 commit 93d0a8b

32 files changed

+356
-356
lines changed

books/RayTracingInOneWeekend.html

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

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

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

617617
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
618-
#ifndef HITABLEH
619-
#define HITABLEH
618+
#ifndef HITTABLEH
619+
#define HITTABLEH
620620

621621
#include "ray.h"
622622

@@ -627,7 +627,7 @@
627627
vec3 normal;
628628
};
629629

630-
class hitable {
630+
class hittable {
631631
public:
632632
virtual bool hit(
633633
const ray& r, float t_min, float t_max, hit_record& rec) const = 0;
@@ -644,9 +644,9 @@
644644
#ifndef SPHEREH
645645
#define SPHEREH
646646

647-
#include "hitable.h"
647+
#include "hittable.h"
648648

649-
class sphere: public hitable {
649+
class sphere: public hittable {
650650
public:
651651
sphere() {}
652652
sphere(vec3 cen, float r) : center(cen), radius(r) {};
@@ -690,22 +690,22 @@
690690
And a list of objects:
691691

692692
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
693-
#ifndef HITABLELISTH
694-
#define HITABLELISTH
693+
#ifndef HITTABLELISTH
694+
#define HITTABLELISTH
695695

696-
#include "hitable.h"
696+
#include "hittable.h"
697697

698-
class hitable_list: public hitable {
698+
class hittable_list: public hittable {
699699
public:
700-
hitable_list() {}
701-
hitable_list(hitable **l, int n) {list = l; list_size = n; }
700+
hittable_list() {}
701+
hittable_list(hittable **l, int n) {list = l; list_size = n; }
702702
virtual bool hit(
703703
const ray& r, float tmin, float tmax, hit_record& rec) const;
704-
hitable **list;
704+
hittable **list;
705705
int list_size;
706706
};
707707

708-
bool hitable_list::hit(
708+
bool hittable_list::hit(
709709
const ray& r, float t_min, float t_max, hit_record& rec) const {
710710

711711
hit_record temp_rec;
@@ -731,10 +731,10 @@
731731
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
732732
#include <iostream>
733733
#include "sphere.h"
734-
#include "hitable_list.h"
734+
#include "hittable_list.h"
735735
#include "float.h"
736736

737-
vec3 color(const ray& r, hitable *world) {
737+
vec3 color(const ray& r, hittable *world) {
738738
hit_record rec;
739739
if (world->hit(r, 0.0, MAXFLOAT, rec)) {
740740
return 0.5*vec3(rec.normal.x()+1, rec.normal.y()+1, rec.normal.z()+1);
@@ -754,10 +754,10 @@
754754
vec3 horizontal(4.0, 0.0, 0.0);
755755
vec3 vertical(0.0, 2.0, 0.0);
756756
vec3 origin(0.0, 0.0, 0.0);
757-
hitable *list[2];
757+
hittable *list[2];
758758
list[0] = new sphere(vec3(0,0,-1), 0.5);
759759
list[1] = new sphere(vec3(0,-100.5,-1), 100);
760-
hitable *world = new hitable_list(list,2);
760+
hittable *world = new hittable_list(list,2);
761761
for (int j = ny-1; j >= 0; j--) {
762762
for (int i = 0; i < nx; i++) {
763763
float u = float(i) / float(nx);
@@ -892,10 +892,10 @@
892892
int ny = 100;
893893
int ns = 100;
894894
std::cout << "P3\n" << nx << " " << ny << "\n255\n";
895-
hitable *list[2];
895+
hittable *list[2];
896896
list[0] = new sphere(vec3(0,0,-1), 0.5);
897897
list[1] = new sphere(vec3(0,-100.5,-1), 100);
898-
hitable *world = new hitable_list(list,2);
898+
hittable *world = new hittable_list(list,2);
899899
camera cam;
900900
for (int j = ny-1; j >= 0; j--) {
901901
for (int i = 0; i < nx; i++) {
@@ -982,7 +982,7 @@
982982
Then update the `color()` function to use the new random direction generator:
983983

984984
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
985-
vec3 color(const ray& r, hitable *world, int depth) {
985+
vec3 color(const ray& r, hittable *world, int depth) {
986986
hit_record rec;
987987
if (world->hit(r, 0.0, MAXFLOAT, rec)) {
988988
vec3 target = rec.p + rec.normal + random_in_unit_sphere();
@@ -1072,13 +1072,13 @@
10721072

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

10791079
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
1080-
#ifndef HITABLEH
1081-
#define HITABLEH
1080+
#ifndef HITTABLEH
1081+
#define HITTABLEH
10821082
#include "ray.h"
10831083

10841084
class material;
@@ -1091,7 +1091,7 @@
10911091
material *mat_ptr;
10921092
};
10931093

1094-
class hitable {
1094+
class hittable {
10951095
public:
10961096
virtual bool hit(
10971097
const ray& r, float t_min, float t_max, hit_record& rec) const = 0;
@@ -1113,7 +1113,7 @@
11131113
within `hit_record`. See the lines below marked with **`/* NEW */`**.
11141114

11151115
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
1116-
class sphere: public hitable {
1116+
class sphere: public hittable {
11171117
public:
11181118
sphere() {}
11191119
sphere(vec3 cen, float r, material *m)
@@ -1223,7 +1223,7 @@
12231223
We need to modify the color function to use this:
12241224

12251225
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
1226-
vec3 color(const ray& r, hitable *world, int depth) {
1226+
vec3 color(const ray& r, hittable *world, int depth) {
12271227
hit_record rec;
12281228
if (world->hit(r, 0.001, MAXFLOAT, rec)) {
12291229
ray scattered;
@@ -1254,12 +1254,12 @@
12541254
int ny = 100;
12551255
int ns = 100;
12561256
std::cout << "P3\n" << nx << " " << ny << "\n255\n";
1257-
hitable *list[4];
1257+
hittable *list[4];
12581258
list[0] = new sphere(vec3(0,0,-1), 0.5, new lambertian(vec3(0.1, 0.2, 0.5)));
12591259
list[1] = new sphere(vec3(0,-100.5,-1), 100, new lambertian(vec3(0.8, 0.8, 0.0)));
12601260
list[2] = new sphere(vec3(1,0,-1), 0.5, new metal(vec3(0.8, 0.6, 0.2), 0.0));
12611261
list[3] = new sphere(vec3(-1,0,-1), 0.5, new metal(vec3(0.8, 0.8, 0.8)));
1262-
hitable *world = new hitable_list(list,4);
1262+
hittable *world = new hittable_list(list,4);
12631263
camera cam;
12641264
for (int j = ny-1; j >= 0; j--) {
12651265
for (int i = 0; i < nx; i++) {
@@ -1598,7 +1598,7 @@
15981598
float R = cos(M_PI/4);
15991599
list[0] = new sphere(vec3(-R,0,-1), R, new lambertian(vec3(0, 0, 1)));
16001600
list[1] = new sphere(vec3( R,0,-1), R, new lambertian(vec3(1, 0, 0)));
1601-
hitable *world = new hitable_list(list,2);
1601+
hittable *world = new hittable_list(list,2);
16021602
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
16031603

16041604
gives:
@@ -1800,9 +1800,9 @@
18001800
First let’s make the image on the cover of this book -- lots of random spheres:
18011801

18021802
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
1803-
hitable *random_scene() {
1803+
hittable *random_scene() {
18041804
int n = 500;
1805-
hitable **list = new hitable*[n+1];
1805+
hittable **list = new hittable*[n+1];
18061806
list[0] = new sphere(vec3(0,-1000,0), 1000, new lambertian(vec3(0.5, 0.5, 0.5)));
18071807
int i = 1;
18081808
for (int a = -11; a < 11; a++) {
@@ -1836,7 +1836,7 @@
18361836
list[i++] = new sphere(vec3(-4, 1, 0), 1.0, new lambertian(vec3(0.4, 0.2, 0.1)));
18371837
list[i++] = new sphere(vec3(4, 1, 0), 1.0, new metal(vec3(0.7, 0.6, 0.5), 0.0));
18381838

1839-
return new hitable_list(list,i);
1839+
return new hittable_list(list,i);
18401840
}
18411841
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18421842
</div>
@@ -1872,7 +1872,7 @@
18721872
blog.
18731873

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

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

0 commit comments

Comments
 (0)