From ca914b32fabdc5bb3e2782d91cc323205d0714fd Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 5 Mar 2023 17:55:51 +0900 Subject: 6.2 --- src/main.zig | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/main.zig') diff --git a/src/main.zig b/src/main.zig index 00bc7e6..4a667f9 100644 --- a/src/main.zig +++ b/src/main.zig @@ -244,6 +244,19 @@ fn generateRandomScene(rng: Random, allocator: anytype) !Hittable { return .{ .list = .{ .objects = hittable_objects } }; } +fn generateEarthScene(allocator: anytype) !Hittable { + var hittable_objects = ArrayList(Hittable).init(allocator); + + const earth_texture = try Texture.makeImage(allocator, "assets/sekaichizu.png"); + var earth_surface = try allocator.create(Material); + + earth_surface.* = .{ .diffuse = .{ .albedo = earth_texture } }; + + try hittable_objects.append(makeSphere(.{ .x = 0, .y = 0, .z = 0 }, 2, earth_surface)); + + return .{ .list = .{ .objects = hittable_objects } }; +} + pub fn main() !void { var gpa = std.heap.GeneralPurposeAllocator(.{}){}; const allocator = gpa.allocator(); @@ -259,7 +272,7 @@ pub fn main() !void { const samples_per_pixel = 50; const max_depth = 50; - const scene = 3; + const scene = 4; // World var world: Hittable = undefined; @@ -284,6 +297,11 @@ pub fn main() !void { lookFrom = .{ .x = 13, .y = 2, .z = 3 }; lookAt = .{ .x = 0, .y = 0, .z = 0 }; vFov = 20.0; + } else if (scene == 4) { + world = try generateEarthScene(allocator); + lookFrom = .{ .x = 13, .y = 2, .z = 3 }; + lookAt = .{ .x = 0, .y = 0, .z = 0 }; + vFov = 20.0; } defer world.deinit(allocator); -- cgit v1.2.3-70-g09d2