tangled
alpha
login
or
join now
altagos.dev
/
rayray
this repo has no description
0
fork
atom
overview
issues
pulls
pipelines
added camera options
altagos.dev
2 years ago
6e9d1221
ec8102db
+11
-4
3 changed files
expand all
collapse all
unified
split
src
camera.zig
main.zig
rayray.zig
+8
-1
src/camera.zig
···
8
8
9
9
const Camera = @This();
10
10
11
11
+
pub const Options = struct {
12
12
+
image_width: usize,
13
13
+
aspect_ratio: f32,
14
14
+
};
15
15
+
11
16
image_height: usize,
12
17
image_width: usize,
13
18
aspect_ratio: f32,
···
27
32
28
33
image: zigimg.Image,
29
34
30
30
-
pub fn init(allocator: std.mem.Allocator, image_width: usize, aspect_ratio: f32) !Camera {
35
35
+
pub fn init(allocator: std.mem.Allocator, opts: Options) !Camera {
36
36
+
const image_width = opts.image_width;
37
37
+
const aspect_ratio = opts.aspect_ratio;
31
38
const image_height = @as(usize, @intFromFloat(@as(f32, @floatFromInt(image_width)) / aspect_ratio));
32
39
if (image_height < 1) return error.ImageWidthLessThanOne;
33
40
+1
-1
src/main.zig
···
33
33
const s = spall.trace(@src(), "Raytracer", .{});
34
34
35
35
// Raytracing part
36
36
-
var raytracer = try rayray.Raytracer.init(allocator, world);
36
36
+
var raytracer = try rayray.Raytracer.init(allocator, world, .{ .aspect_ratio = 16.0 / 9.0, .image_width = 400 });
37
37
defer raytracer.deinit();
38
38
39
39
const img = try raytracer.render();
+2
-2
src/rayray.zig
···
24
24
camera: Camera,
25
25
world: hittable.HittableList,
26
26
27
27
-
pub fn init(allocator: std.mem.Allocator, world: hittable.HittableList) !Self {
27
27
+
pub fn init(allocator: std.mem.Allocator, world: hittable.HittableList, camera_opts: Camera.Options) !Self {
28
28
return .{
29
29
.allocator = allocator,
30
30
-
.camera = try Camera.init(allocator, 400, 16.0 / 9.0),
30
30
+
.camera = try Camera.init(allocator, camera_opts),
31
31
.world = world,
32
32
};
33
33
}