Skip to content

Commit d7c98ae

Browse files
committed
Listing 54 A new scene with quads
1 parent 60d9c47 commit d7c98ae

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

src/TheNextWeek/main.cc

+37-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "hittable.h"
1717
#include "hittable_list.h"
1818
#include "material.h"
19+
#include "quad.h"
1920
#include "sphere.h"
2021
#include "texture.h"
2122

@@ -155,11 +156,46 @@ void perlin_spheres() {
155156
cam.render(world);
156157
}
157158

159+
void quads() {
160+
hittable_list world;
161+
162+
// Materials
163+
auto left_red = make_shared<lambertian>(color(1.0, 0.2, 0.2));
164+
auto back_green = make_shared<lambertian>(color(0.2, 1.0, 0.2));
165+
auto right_blue = make_shared<lambertian>(color(0.2, 0.2, 1.0));
166+
auto upper_orange = make_shared<lambertian>(color(1.0, 0.5, 0.0));
167+
auto lower_teal = make_shared<lambertian>(color(0.2, 0.8, 0.8));
168+
169+
// Quads
170+
world.add(make_shared<quad>(point3(-3,-2, 5), vec3(0, 0,-4), vec3(0, 4, 0), left_red));
171+
world.add(make_shared<quad>(point3(-2,-2, 0), vec3(4, 0, 0), vec3(0, 4, 0), back_green));
172+
world.add(make_shared<quad>(point3( 3,-2, 1), vec3(0, 0, 4), vec3(0, 4, 0), right_blue));
173+
world.add(make_shared<quad>(point3(-2, 3, 1), vec3(4, 0, 0), vec3(0, 0, 4), upper_orange));
174+
world.add(make_shared<quad>(point3(-2,-3, 5), vec3(4, 0, 0), vec3(0, 0,-4), lower_teal));
175+
176+
camera cam;
177+
178+
cam.aspect_ratio = 1.0;
179+
cam.image_width = 400;
180+
cam.samples_per_pixel = 100;
181+
cam.max_depth = 50;
182+
183+
cam.vfov = 80;
184+
cam.lookfrom = point3(0,0,9);
185+
cam.lookat = point3(0,0,0);
186+
cam.vup = vec3(0,1,0);
187+
188+
cam.defocus_angle = 0;
189+
190+
cam.render(world);
191+
}
192+
158193
int main() {
159-
switch (4) {
194+
switch (5) {
160195
case 1: bouncing_spheres(); break;
161196
case 2: checkered_spheres(); break;
162197
case 3: earth(); break;
163198
case 4: perlin_spheres(); break;
199+
case 5: quads(); break;
164200
}
165201
}

0 commit comments

Comments
 (0)