-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcamera.h
More file actions
27 lines (25 loc) · 896 Bytes
/
Copy pathcamera.h
File metadata and controls
27 lines (25 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#pragma once
#include "ray.h"
#include "randengine.h"
class camera {
public:
camera(const vec3 lookfrom, const vec3 lookat, const vec3 upv, const float_t vfov, const float_t aspect, const float_t aperture, const float_t dfocus) {
lensr = aperture * 0.5;
origin = lookfrom;
lf = make_unit(lookfrom - lookat);
lh = make_unit(cross(upv, lf));
lv = cross(lf, lh);
float_t hheight = tan((vfov*3.1415926535879)/360);
float_t hwidth = hheight * aspect;
bl = origin - hwidth * dfocus * lh - hheight * dfocus * lv - dfocus * lf;
hori = 2*hwidth*dfocus*lh;
vert = 2*hheight*dfocus*lv;
}
ray cast(float_t u, float_t v) const { const vec3 ric = lensr * randengine::randcirc();const vec3 offset = lh * ric.x() + lv * ric.y();return ray(origin+offset, (bl + u * hori + v * vert) - origin - offset); }
vec3 origin;
vec3 bl;
vec3 hori;
vec3 vert;
vec3 lf, lh, lv;
float_t lensr;
};