diff options
author | alaric <alaric@netmythos.org> | 2024-04-07 23:49:26 -0700 |
---|---|---|
committer | alaric <alaric@netmythos.org> | 2024-04-07 23:49:26 -0700 |
commit | fedb9bef8dfc447b3e52294896f65954d896c12e (patch) | |
tree | 3b1c4ddfdab16bda506db7dd2db2fe2c0e2a2451 | |
parent | de6948de605bb8b74052f2afd73b361abbdf8d50 (diff) | |
download | menger-fedb9bef8dfc447b3e52294896f65954d896c12e.tar.gz menger-fedb9bef8dfc447b3e52294896f65954d896c12e.zip |
-rw-r--r-- | UNLICENSE | 24 | ||||
-rw-r--r-- | src/shell.html | 3 | ||||
-rw-r--r-- | src/wasm_msponge.zig | 24 |
3 files changed, 38 insertions, 13 deletions
diff --git a/UNLICENSE b/UNLICENSE new file mode 100644 index 0000000..68a49da --- /dev/null +++ b/UNLICENSE @@ -0,0 +1,24 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to <http://unlicense.org/> diff --git a/src/shell.html b/src/shell.html index ecbf8fb..b6eabf5 100644 --- a/src/shell.html +++ b/src/shell.html @@ -16,10 +16,9 @@ #app-canvas { display: flex; flex-grow: 1; - width: 1280px; + max-width: 1280px; max-height: 720px; height: 100%; - border: solid 1px black; } </style> </head> diff --git a/src/wasm_msponge.zig b/src/wasm_msponge.zig index 943fd38..1827e34 100644 --- a/src/wasm_msponge.zig +++ b/src/wasm_msponge.zig @@ -158,7 +158,7 @@ fn setupSubdividedCube(divisions: u32, condFn: *const fn (u32, u32, u32) bool) v const m_offsets = subdividedCube(divisions, condFn); const m_ptr: [*]const f32 = @ptrCast(m_offsets); const m_len = m_offsets.len * 3; - wasm.print("{d} cubes generated", .{m_offsets.len}); + wasm.print("{d} cubes generated, scaled to {d}", .{ m_offsets.len, base_scale }); webgl.bufferData(.array_buffer, m_ptr[0..m_len], .dynamic_draw); cube_count = @intCast(m_offsets.len); current_depth = divisions; @@ -169,17 +169,16 @@ fn subdividedCube(divisions: u32, condFn: *const fn (u32, u32, u32) bool) []cons base_scale = 1.0 / @as(f32, @floatFromInt(cubes_per_side)); var len: u32 = 0; + const step = 1; + const start = @as(f32, @floatFromInt(@divFloor(cubes_per_side, 2))) * -step; for (0..cubes_per_side) |z| { + const zp: f32 = @as(f32, @floatFromInt(z)) * step + start; for (0..cubes_per_side) |y| { + const yp: f32 = @as(f32, @floatFromInt(y)) * step + start; for (0..cubes_per_side) |x| { + const xp: f32 = @as(f32, @floatFromInt(x)) * step + start; if (condFn(x, y, z)) { - const c: @Vector(3, f32) = .{ - @floatFromInt(x), - @floatFromInt(y), - @floatFromInt(z), - }; - const adj: @Vector(3, f32) = @splat(@as(f32, @floatFromInt(cubes_per_side)) / 3.0); - offsets[len] = c - adj; + offsets[len] = .{ xp, yp, zp }; len += 1; } } @@ -263,9 +262,12 @@ export fn update(delta_time: f32) void { const screen_dims = webgl.getScreenSize(); const aspect = screen_dims[0] / screen_dims[1]; const proj = perspectiveMatrix(degToRad(60), aspect, 1, 2000); - const tlate = Mat4.translation(.{ 0, 0, -225 }); - const rot = Mat4.yRotation(timer).multiply(Mat4.xRotation(0)).multiply(Mat4.zRotation(0)); - const s: f32 = 150 * base_scale; + const center_tlate = Mat4.translation(.{ 0, 0, 0 }); + _ = center_tlate; + const tlate = Mat4.translation(.{ 0, 0, -2 }); + //const rot = Mat4.yRotation(timer).multiply(Mat4.xRotation(0)).multiply(Mat4.zRotation(0)); + const rot = Mat4.yRotation(degToRad(45)).multiply(Mat4.xRotation(timer * 0.25)).multiply(Mat4.yRotation(timer)); + const s: f32 = (1.5 + (@sin(timer) + 1) * 0.5 / 2) * base_scale; const scale = Mat4.scale(.{ s, s, s }); const model = scale.multiply(rot.multiply(tlate)); const final_mat = model.multiply(proj); |