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
9
const Camera = @This();
10
0
0
0
0
0
11
image_height: usize,
12
image_width: usize,
13
aspect_ratio: f32,
···
27
28
image: zigimg.Image,
29
30
-
pub fn init(allocator: std.mem.Allocator, image_width: usize, aspect_ratio: f32) !Camera {
0
0
31
const image_height = @as(usize, @intFromFloat(@as(f32, @floatFromInt(image_width)) / aspect_ratio));
32
if (image_height < 1) return error.ImageWidthLessThanOne;
33
···
8
9
const Camera = @This();
10
11
+
pub const Options = struct {
12
+
image_width: usize,
13
+
aspect_ratio: f32,
14
+
};
15
+
16
image_height: usize,
17
image_width: usize,
18
aspect_ratio: f32,
···
32
33
image: zigimg.Image,
34
35
+
pub fn init(allocator: std.mem.Allocator, opts: Options) !Camera {
36
+
const image_width = opts.image_width;
37
+
const aspect_ratio = opts.aspect_ratio;
38
const image_height = @as(usize, @intFromFloat(@as(f32, @floatFromInt(image_width)) / aspect_ratio));
39
if (image_height < 1) return error.ImageWidthLessThanOne;
40
+1
-1
src/main.zig
···
33
const s = spall.trace(@src(), "Raytracer", .{});
34
35
// Raytracing part
36
-
var raytracer = try rayray.Raytracer.init(allocator, world);
37
defer raytracer.deinit();
38
39
const img = try raytracer.render();
···
33
const s = spall.trace(@src(), "Raytracer", .{});
34
35
// Raytracing part
36
+
var raytracer = try rayray.Raytracer.init(allocator, world, .{ .aspect_ratio = 16.0 / 9.0, .image_width = 400 });
37
defer raytracer.deinit();
38
39
const img = try raytracer.render();
+2
-2
src/rayray.zig
···
24
camera: Camera,
25
world: hittable.HittableList,
26
27
-
pub fn init(allocator: std.mem.Allocator, world: hittable.HittableList) !Self {
28
return .{
29
.allocator = allocator,
30
-
.camera = try Camera.init(allocator, 400, 16.0 / 9.0),
31
.world = world,
32
};
33
}
···
24
camera: Camera,
25
world: hittable.HittableList,
26
27
+
pub fn init(allocator: std.mem.Allocator, world: hittable.HittableList, camera_opts: Camera.Options) !Self {
28
return .{
29
.allocator = allocator,
30
+
.camera = try Camera.init(allocator, camera_opts),
31
.world = world,
32
};
33
}