diff --git a/src/camera.h b/src/camera.h index f6e4c0c..0593c28 100644 --- a/src/camera.h +++ b/src/camera.h @@ -3,20 +3,33 @@ class camera{ public: - camera(){ - auto aspect_ratio = 16.0 / 9.0; - auto viewport_height = 2.0; + camera( + point3 lookfrom, + point3 lookat, + vec3 vup, + double vfov , + double aspect_ratio + ){ + + + auto theta = degrees_to_radians(vfov); + auto h = tan(theta/2); + + auto viewport_height = 2.0 * h; auto viewport_width = aspect_ratio * viewport_height; - auto focal_length = 1.0; + + auto w = unit_vector(lookfrom - lookat); + auto u = unit_vector(cross(vup, w)); + auto v = cross(w,u); - origin = point3(0,0,0); - horizontal = vec3(viewport_width, 0, 0); - vertical = vec3(0, viewport_height, 0); - lower_left_corner = origin - horizontal/2 - vertical/2 - vec3(0,0,focal_length); + origin = lookfrom; + horizontal = viewport_width * u; + vertical = viewport_height * v; + lower_left_corner = origin - horizontal/2 - vertical/2 - w; } - ray get_ray(double u, double v) const { - return ray(origin, lower_left_corner + u * horizontal + v*vertical - origin); + ray get_ray(double s, double t) const { + return ray(origin, lower_left_corner + s * horizontal + t*vertical - origin); } private: diff --git a/src/program.cpp b/src/program.cpp index ce04180..8a76d43 100644 --- a/src/program.cpp +++ b/src/program.cpp @@ -40,21 +40,20 @@ int main () // World hittable_list world; - auto material_ground = make_shared(color(0.8,0.8, 0.0)); + auto material_ground = make_shared(color(0.8, 0.8, 0.0)); auto material_center = make_shared(color(0.1, 0.2, 0.5)); - auto material_left = make_shared (1.5); - auto material_right = make_shared(color(0.8,0.6,0.2), 0.0); - + auto material_left = make_shared(1.5); + auto material_right = make_shared(color(0.8, 0.6, 0.2), 0.0); - world.add(make_shared(point3(0,-100.5,-1), 100.0, material_ground)); - world.add(make_shared(point3(0,0,-1), 0.5, material_center)); - world.add(make_shared(point3(-1.0, 0.0, -1), 0.5, material_left)); - world.add(make_shared(point3(-1.0, 0.0, -1), -0.4, material_left)); - world.add(make_shared(point3(1.0, 0.0, -1), 0.5, material_right)); + world.add(make_shared(point3( 0.0, -100.5, -1.0), 100.0, material_ground)); + world.add(make_shared(point3( 0.0, 0.0, -1.0), 0.5, material_center)); + world.add(make_shared(point3(-1.0, 0.0, -1.0), 0.5, material_left)); + world.add(make_shared(point3(-1.0, 0.0, -1.0), -0.45, material_left)); + world.add(make_shared(point3( 1.0, 0.0, -1.0), 0.5, material_right)); // Camera - camera cam; + camera cam(point3(-2,2,1), point3(0,0,-1), vec3(0,1,0), 20, aspect_ratio); // Render std::cout<< "P3\n" << image_width << ' ' << image_height << "\n255\n";