Rename main.cpp file

This commit is contained in:
CJSatnarine
2024-07-08 18:41:45 -04:00
parent 8a50479e27
commit e1e2d4ac2a

81
main.cpp Normal file
View File

@@ -0,0 +1,81 @@
#include "rayTracer.h"
#include "bvh.h"
#include "camera.h"
#include "hittable.h"
#include "hittableList.h"
#include "material.h"
#include "sphere.h"
#include "texture.h"
int main(void) {
// World.
hittableList world;
auto checker = make_shared<checkerTexture>(0.32, colour(.2, .3, .1), colour(.9, .9, .9));
world.add(make_shared<sphere>(point3(0,-1000,0), 1000, make_shared<lambertian>(checker)));
// Code from the book.
auto ground_material = make_shared<lambertian>(colour(0.5, 0.5, 0.5));
world.add(make_shared<sphere>(point3(0,-1000,0), 1000, ground_material));
for (int a = -11; a < 11; a++) {
for (int b = -11; b < 11; b++) {
auto choose_mat = randomDouble();
point3 center(a + 0.9*randomDouble(), 0.2, b + 0.9*randomDouble());
if ((center - point3(4, 0.2, 0)).length() > 0.9) {
shared_ptr<material> sphere_material;
if (choose_mat < 0.8) {
// diffuse
auto albedo = colour::random() * colour::random();
sphere_material = make_shared<lambertian>(albedo);
world.add(make_shared<sphere>(center, 0.2, sphere_material));
} else if (choose_mat < 0.95) {
// metal
auto albedo = colour::random(0.5, 1);
auto fuzz = randomDouble(0, 0.5);
sphere_material = make_shared<metal>(albedo, fuzz);
world.add(make_shared<sphere>(center, 0.2, sphere_material));
auto center2 = center + vec3(0, randomDouble(0,.5), 0);
world.add(make_shared<sphere>(center, center2, 0.2, sphere_material));
} else {
// glass
sphere_material = make_shared<dielectric>(1.5);
world.add(make_shared<sphere>(center, 0.2, sphere_material));
}
}
}
}
auto material1 = make_shared<dielectric>(1.5);
world.add(make_shared<sphere>(point3(0, 1, 0), 1.0, material1));
auto material2 = make_shared<lambertian>(colour(0.4, 0.2, 0.1));
world.add(make_shared<sphere>(point3(-4, 1, 0), 1.0, material2));
auto material3 = make_shared<metal>(colour(0.7, 0.6, 0.5), 0.0);
world.add(make_shared<sphere>(point3(4, 1, 0), 1.0, material3));
world = hittableList(make_shared<bvh_node>(world));
// Camera.
camera cam;
cam.aspectRatio = 16.0 / 9.0;
cam.imageWidth = 400;
cam.samplesPerPixel = 100;
cam.maxDepth = 50;
cam.vFieldOfView = 20;
cam.lookFrom = point3(13,2,3);
cam.lookAt = point3(0,0,0);
cam.vUp = vec3(0,1,0);
cam.defocusAngle = 0.6;
cam.focusDistance = 10;
cam.render(world);
return 0;
}