add multiple samples per pixel
This commit is contained in:
parent
79772c0df4
commit
b0ce3eecec
5 changed files with 76 additions and 19 deletions
36
in_one_weekend/src/camera.zig
Normal file
36
in_one_weekend/src/camera.zig
Normal file
|
@ -0,0 +1,36 @@
|
|||
const Point3 = @import("vec3.zig").Point3;
|
||||
const Vec3 = @import("vec3.zig").Vec3;
|
||||
const Ray = @import("ray.zig").Ray;
|
||||
|
||||
pub const Camera = struct {
|
||||
origin: Point3,
|
||||
lowerLeftCorner: Point3,
|
||||
horizontal: Vec3,
|
||||
vertical: Vec3,
|
||||
|
||||
pub fn init() Camera {
|
||||
const aspectRatio = 16.0 / 9.0;
|
||||
const viewportHeight = 2.0;
|
||||
const viewportWidth = aspectRatio * viewportHeight;
|
||||
const focalLength = 1.0;
|
||||
|
||||
const origin = Vec3{};
|
||||
const horizontal = Vec3{ .x = viewportWidth };
|
||||
const vertical = Vec3{ .y = viewportHeight };
|
||||
const lowerLeftCorner = origin.sub(horizontal.div(2)).sub(vertical.div(2)).sub(Vec3{ .z = focalLength });
|
||||
|
||||
return Camera {
|
||||
.origin = origin,
|
||||
.horizontal = horizontal,
|
||||
.vertical = vertical,
|
||||
.lowerLeftCorner = lowerLeftCorner,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn getRay(self: Camera, u: f32, v: f32) Ray {
|
||||
return Ray{
|
||||
.origin = self.origin,
|
||||
.direction = self.lowerLeftCorner.add(self.horizontal.mul(u)).add(self.vertical.mul(v)).sub(self.origin),
|
||||
};
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue