Camera positioning and orienting
This commit is contained in:
parent
b8bdd91e40
commit
01d3166ae2
2 changed files with 13 additions and 10 deletions
|
@ -5,24 +5,27 @@
|
||||||
|
|
||||||
class camera {
|
class camera {
|
||||||
public:
|
public:
|
||||||
camera(double vfov /*vertical field-of-view in degrees*/, double aspect_ratio) {
|
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 theta = degrees_to_radians(vfov);
|
||||||
auto h = tan(theta / 2);
|
auto h = tan(theta / 2);
|
||||||
auto viewport_height = 2.0 * h;
|
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;
|
|
||||||
|
|
||||||
origin = point3(0, 0, 0);
|
auto w = unit_vector(lookfrom - lookat);
|
||||||
horizontal = vec3(viewport_width, 0.0, 0.0);
|
auto u = unit_vector(cross(vup, w));
|
||||||
vertical = vec3(0.0, viewport_height, 0.0);
|
auto v = cross(w, u);
|
||||||
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 {
|
ray get_ray(double s, double t) const {
|
||||||
return ray(origin,
|
return ray(origin,
|
||||||
lower_left_corner + u * horizontal + v * vertical - origin);
|
lower_left_corner + s*horizontal + t*vertical - origin);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -59,7 +59,7 @@ int main() {
|
||||||
|
|
||||||
// Camera
|
// Camera
|
||||||
|
|
||||||
camera cam(90, aspect_ratio);
|
camera cam(point3(-2,2,1), point3(0,0,-1), vec3(0,1,0), 90, aspect_ratio);
|
||||||
|
|
||||||
// Render
|
// Render
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue