Movable lens
This commit is contained in:
parent
41082f0764
commit
3d06a33548
33
src/camera.h
33
src/camera.h
@ -3,20 +3,33 @@
|
|||||||
|
|
||||||
class camera{
|
class camera{
|
||||||
public:
|
public:
|
||||||
camera(){
|
camera(
|
||||||
auto aspect_ratio = 16.0 / 9.0;
|
point3 lookfrom,
|
||||||
auto viewport_height = 2.0;
|
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 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);
|
origin = lookfrom;
|
||||||
horizontal = vec3(viewport_width, 0, 0);
|
horizontal = viewport_width * u;
|
||||||
vertical = vec3(0, viewport_height, 0);
|
vertical = viewport_height * v;
|
||||||
lower_left_corner = origin - horizontal/2 - vertical/2 - vec3(0,0,focal_length);
|
lower_left_corner = origin - horizontal/2 - vertical/2 - w;
|
||||||
}
|
}
|
||||||
|
|
||||||
ray get_ray(double u, double v) const {
|
ray get_ray(double s, double t) const {
|
||||||
return ray(origin, lower_left_corner + u * horizontal + v*vertical - origin);
|
return ray(origin, lower_left_corner + s * horizontal + t*vertical - origin);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -40,21 +40,20 @@ int main ()
|
|||||||
// World
|
// World
|
||||||
hittable_list world;
|
hittable_list world;
|
||||||
|
|
||||||
auto material_ground = make_shared<lambertian>(color(0.8,0.8, 0.0));
|
auto material_ground = make_shared<lambertian>(color(0.8, 0.8, 0.0));
|
||||||
auto material_center = make_shared<lambertian>(color(0.1, 0.2, 0.5));
|
auto material_center = make_shared<lambertian>(color(0.1, 0.2, 0.5));
|
||||||
auto material_left = make_shared<dielectric> (1.5);
|
auto material_left = make_shared<dielectric>(1.5);
|
||||||
auto material_right = make_shared<metal>(color(0.8,0.6,0.2), 0.0);
|
auto material_right = make_shared<metal>(color(0.8, 0.6, 0.2), 0.0);
|
||||||
|
|
||||||
|
|
||||||
world.add(make_shared<sphere>(point3(0,-100.5,-1), 100.0, material_ground));
|
world.add(make_shared<sphere>(point3( 0.0, -100.5, -1.0), 100.0, material_ground));
|
||||||
world.add(make_shared<sphere>(point3(0,0,-1), 0.5, material_center));
|
world.add(make_shared<sphere>(point3( 0.0, 0.0, -1.0), 0.5, material_center));
|
||||||
world.add(make_shared<sphere>(point3(-1.0, 0.0, -1), 0.5, material_left));
|
world.add(make_shared<sphere>(point3(-1.0, 0.0, -1.0), 0.5, material_left));
|
||||||
world.add(make_shared<sphere>(point3(-1.0, 0.0, -1), -0.4, material_left));
|
world.add(make_shared<sphere>(point3(-1.0, 0.0, -1.0), -0.45, material_left));
|
||||||
world.add(make_shared<sphere>(point3(1.0, 0.0, -1), 0.5, material_right));
|
world.add(make_shared<sphere>(point3( 1.0, 0.0, -1.0), 0.5, material_right));
|
||||||
|
|
||||||
|
|
||||||
// Camera
|
// Camera
|
||||||
camera cam;
|
camera cam(point3(-2,2,1), point3(0,0,-1), vec3(0,1,0), 20, aspect_ratio);
|
||||||
|
|
||||||
// Render
|
// Render
|
||||||
std::cout<< "P3\n" << image_width << ' ' << image_height << "\n255\n";
|
std::cout<< "P3\n" << image_width << ' ' << image_height << "\n255\n";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user