1
0

feat: adjustable camera

This commit is contained in:
Rokas Puzonas 2022-03-13 20:45:12 +02:00
parent 4d2b7757d4
commit 0b5c3c20cb
3 changed files with 89293 additions and 89280 deletions

View File

@ -2,23 +2,35 @@
#define CAMERA_H
#include "rtweekend.h"
#include "vec3.h"
#include "ray.h"
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, // vertical field-of-view in degrees,
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;
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);
auto w = unit_vector(lookfrom - lookat);
auto u = unit_vector(cross(vup, w));
auto v = cross(w, u);
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:

178536
image.ppm

File diff suppressed because it is too large Load Diff

View File

@ -37,6 +37,7 @@ int main() {
const int max_depth = 32;
// World
auto R = cos(pi/4);
hittable_list world;
auto material_ground = make_shared<lambertian>(color(0.8, 0.8, 0.0));
@ -47,11 +48,11 @@ int main() {
world.add(make_shared<sphere>(point3( 0, -100.5, -1), 100, material_ground));
world.add(make_shared<sphere>(point3( 0, 0, -1), 0.5, material_center));
world.add(make_shared<sphere>(point3(-1, 0, -1), 0.5, material_left));
world.add(make_shared<sphere>(point3(-1, 0, -1), -0.4, material_left));
world.add(make_shared<sphere>(point3(-1, 0, -1), -0.45, material_left));
world.add(make_shared<sphere>(point3( 1, 0, -1), 0.5, material_right));
// Camera
camera cam;
camera cam(point3(-2, 2, 1), point3(0, 0, -1), vec3(0, 1, 0), 70, aspect_ratio);
// Render
std::cout<<"P3\n" <<image_width<<" "<<image_height<<"\n255\n";