Fix formatting

This commit is contained in:
codemob-dev 2025-07-28 17:15:30 -04:00
parent 436d792544
commit a658bcf5b9
2 changed files with 34 additions and 37 deletions

View File

@ -66,8 +66,8 @@ pub const collision = struct {
pub fn intersects(self: AABB, other: AABB) bool { pub fn intersects(self: AABB, other: AABB) bool {
var i: usize = 0; var i: usize = 0;
while (i < 3) : (i += 1) { while(i < 3) : (i += 1) {
if (self.max[i] < other.min[i] or self.min[i] > other.max[i]) { if(self.max[i] < other.min[i] or self.min[i] > other.max[i]) {
return false; return false;
} }
} }
@ -88,10 +88,10 @@ pub const collision = struct {
const model = block.mode().model(block).model(); const model = block.mode().model(block).model();
const pos = Vec3d{@floatFromInt(x), @floatFromInt(y), @floatFromInt(z)}; const pos = Vec3d{@floatFromInt(x), @floatFromInt(y), @floatFromInt(z)};
const entityAABB = AABB {.min = entityPosition - entityBoundingBoxExtent, .max = entityPosition + entityBoundingBoxExtent}; const entityAABB = AABB{.min = entityPosition - entityBoundingBoxExtent, .max = entityPosition + entityBoundingBoxExtent};
for(model.collision) |relativeBlockAABB| { for(model.collision) |relativeBlockAABB| {
const blockAABB = AABB {.min = relativeBlockAABB.min + pos, .max = relativeBlockAABB.max + pos}; const blockAABB = AABB{.min = relativeBlockAABB.min + pos, .max = relativeBlockAABB.max + pos};
if(blockAABB.intersects(entityAABB)) { if(blockAABB.intersects(entityAABB)) {
const dotMin = vec.dot(directionVector, blockAABB.min); const dotMin = vec.dot(directionVector, blockAABB.min);
const dotMax = vec.dot(directionVector, blockAABB.max); const dotMax = vec.dot(directionVector, blockAABB.max);
@ -336,9 +336,9 @@ pub const collision = struct {
fn isBlockIntersecting(block: Block, posX: i32, posY: i32, posZ: i32, center: Vec3d, extent: Vec3d) bool { fn isBlockIntersecting(block: Block, posX: i32, posY: i32, posZ: i32, center: Vec3d, extent: Vec3d) bool {
const model = block.mode().model(block).model(); const model = block.mode().model(block).model();
const position = Vec3d{@floatFromInt(posX), @floatFromInt(posY), @floatFromInt(posZ)}; const position = Vec3d{@floatFromInt(posX), @floatFromInt(posY), @floatFromInt(posZ)};
const entityAABB = AABB {.min = center - extent, .max = center + extent}; const entityAABB = AABB{.min = center - extent, .max = center + extent};
for(model.collision) |relativeBlockAABB| { for(model.collision) |relativeBlockAABB| {
const blockAABB = AABB {.min = position + relativeBlockAABB.min, .max = position + relativeBlockAABB.max}; const blockAABB = AABB{.min = position + relativeBlockAABB.min, .max = position + relativeBlockAABB.max};
if(blockAABB.intersects(entityAABB)) { if(blockAABB.intersects(entityAABB)) {
return true; return true;
} }

View File

@ -216,20 +216,20 @@ pub const Model = struct {
return false; return false;
} }
const f = 1.0 / a; const f = 1.0/a;
const s = ray_origin - v0; const s = ray_origin - v0;
const u = f * vec.dot(s, h); const u = f*vec.dot(s, h);
if(u < 0.0 or u > 1.0) { if(u < 0.0 or u > 1.0) {
return false; return false;
} }
const q = vec.cross(s, edge1); const q = vec.cross(s, edge1);
const v = f * vec.dot(ray_direction, q); const v = f*vec.dot(ray_direction, q);
if(v < 0.0 or u + v > 1.0) { if(v < 0.0 or u + v > 1.0) {
return false; return false;
} }
const t = f * vec.dot(edge2, q); const t = f*vec.dot(edge2, q);
return t > epsilon; return t > epsilon;
} }
@ -239,13 +239,13 @@ pub const Model = struct {
for(0..meshGridSize) |y| { for(0..meshGridSize) |y| {
for(0..meshGridSize) |z| { for(0..meshGridSize) |z| {
grid[x][y][z] = false; grid[x][y][z] = false;
const blockX = (@as(f32, @floatFromInt(x)) + 0.5) / meshGridSize; const blockX = (@as(f32, @floatFromInt(x)) + 0.5)/meshGridSize;
const blockY = (@as(f32, @floatFromInt(y)) + 0.5) / meshGridSize; const blockY = (@as(f32, @floatFromInt(y)) + 0.5)/meshGridSize;
const blockZ = (@as(f32, @floatFromInt(z)) + 0.5) / meshGridSize; const blockZ = (@as(f32, @floatFromInt(z)) + 0.5)/meshGridSize;
const pos = Vec3f{blockX, blockY, blockZ}; const pos = Vec3f{blockX, blockY, blockZ};
// Fences have weird models, so this is necesarry to make them work // Fences have weird models, so this is necesarry to make them work
for(Neighbor.iterable)|neighbor| { for(Neighbor.iterable) |neighbor| {
const dir: Vec3f = @floatFromInt(neighbor.relPos()); const dir: Vec3f = @floatFromInt(neighbor.relPos());
var signed_intersections: i32 = 0; var signed_intersections: i32 = 0;
@ -289,7 +289,7 @@ pub const Model = struct {
for(0..meshGridSize) |z| { for(0..meshGridSize) |z| {
if(grid[x][y][z]) { if(grid[x][y][z]) {
var boxMin = Vec3i{@intCast(x), @intCast(y), @intCast(z)}; var boxMin = Vec3i{@intCast(x), @intCast(y), @intCast(z)};
var boxMax = Vec3i{@intCast(x+1), @intCast(y+1), @intCast(z+1)}; var boxMax = Vec3i{@intCast(x + 1), @intCast(y + 1), @intCast(z + 1)};
for(Neighbor.iterable) |neighbor| { for(Neighbor.iterable) |neighbor| {
while(canExpand(&grid, boxMin, boxMax, neighbor)) { while(canExpand(&grid, boxMin, boxMax, neighbor)) {
if(neighbor.isPositive()) { if(neighbor.isPositive()) {
@ -301,20 +301,17 @@ pub const Model = struct {
} }
setAll(&grid, boxMin, boxMax, false); setAll(&grid, boxMin, boxMax, false);
const minBlockX = @as(f32, @floatFromInt(boxMin[0])) / meshGridSize; const minBlockX = @as(f32, @floatFromInt(boxMin[0]))/meshGridSize;
const minBlockY = @as(f32, @floatFromInt(boxMin[1])) / meshGridSize; const minBlockY = @as(f32, @floatFromInt(boxMin[1]))/meshGridSize;
const minBlockZ = @as(f32, @floatFromInt(boxMin[2])) / meshGridSize; const minBlockZ = @as(f32, @floatFromInt(boxMin[2]))/meshGridSize;
const min = Vec3f{minBlockX, minBlockY, minBlockZ}; const min = Vec3f{minBlockX, minBlockY, minBlockZ};
const maxBlockX = @as(f32, @floatFromInt(boxMax[0])) / meshGridSize; const maxBlockX = @as(f32, @floatFromInt(boxMax[0]))/meshGridSize;
const maxBlockY = @as(f32, @floatFromInt(boxMax[1])) / meshGridSize; const maxBlockY = @as(f32, @floatFromInt(boxMax[1]))/meshGridSize;
const maxBlockZ = @as(f32, @floatFromInt(boxMax[2])) / meshGridSize; const maxBlockZ = @as(f32, @floatFromInt(boxMax[2]))/meshGridSize;
const max = Vec3f{maxBlockX, maxBlockY, maxBlockZ}; const max = Vec3f{maxBlockX, maxBlockY, maxBlockZ};
self.collision[i] = AABB { self.collision[i] = AABB{.min = min, .max = max};
.min = min,
.max = max
};
i += 1; i += 1;
} }
} }
@ -328,9 +325,9 @@ pub const Model = struct {
if(max[0] > meshGridSize or max[1] > meshGridSize or max[2] > meshGridSize or min[0] < 0 or min[1] < 0 or min[2] < 0) { if(max[0] > meshGridSize or max[1] > meshGridSize or max[2] > meshGridSize or min[0] < 0 or min[1] < 0 or min[2] < 0) {
return false; return false;
} }
for(@intCast(min[0])..@intCast(max[0]))|x| { for(@intCast(min[0])..@intCast(max[0])) |x| {
for(@intCast(min[1])..@intCast(max[1]))|y| { for(@intCast(min[1])..@intCast(max[1])) |y| {
for(@intCast(min[2])..@intCast(max[2]))|z| { for(@intCast(min[2])..@intCast(max[2])) |z| {
if(!grid[x][y][z]) { if(!grid[x][y][z]) {
return false; return false;
} }
@ -341,9 +338,9 @@ pub const Model = struct {
} }
fn setAll(grid: *[meshGridSize][meshGridSize][meshGridSize]bool, min: Vec3i, max: Vec3i, value: bool) void { fn setAll(grid: *[meshGridSize][meshGridSize][meshGridSize]bool, min: Vec3i, max: Vec3i, value: bool) void {
for(@intCast(min[0])..@intCast(max[0]))|x| { for(@intCast(min[0])..@intCast(max[0])) |x| {
for(@intCast(min[1])..@intCast(max[1]))|y| { for(@intCast(min[1])..@intCast(max[1])) |y| {
for(@intCast(min[2])..@intCast(max[2]))|z| { for(@intCast(min[2])..@intCast(max[2])) |z| {
grid[x][y][z] = value; grid[x][y][z] = value;
} }
} }
@ -352,12 +349,12 @@ pub const Model = struct {
fn canExpand(grid: *const [meshGridSize][meshGridSize][meshGridSize]bool, min: Vec3i, max: Vec3i, dir: Neighbor) bool { fn canExpand(grid: *const [meshGridSize][meshGridSize][meshGridSize]bool, min: Vec3i, max: Vec3i, dir: Neighbor) bool {
return switch(dir) { return switch(dir) {
.dirUp => allTrue(grid, Vec3i{ min[0], min[1], max[2] }, Vec3i{ max[0], max[1], max[2] + 1 }), .dirUp => allTrue(grid, Vec3i{min[0], min[1], max[2]}, Vec3i{max[0], max[1], max[2] + 1}),
.dirDown => allTrue(grid, Vec3i{ min[0], min[1], min[2] - 1 }, Vec3i{ max[0], max[1], min[2] }), .dirDown => allTrue(grid, Vec3i{min[0], min[1], min[2] - 1}, Vec3i{max[0], max[1], min[2]}),
.dirPosX => allTrue(grid, Vec3i{ max[0], min[1], min[2] }, Vec3i{ max[0] + 1, max[1], max[2] }), .dirPosX => allTrue(grid, Vec3i{max[0], min[1], min[2]}, Vec3i{max[0] + 1, max[1], max[2]}),
.dirNegX => allTrue(grid, Vec3i{ min[0] - 1, min[1], min[2] }, Vec3i{ min[0], max[1], max[2] }), .dirNegX => allTrue(grid, Vec3i{min[0] - 1, min[1], min[2]}, Vec3i{min[0], max[1], max[2]}),
.dirPosY => allTrue(grid, Vec3i{ min[0], max[1], min[2] }, Vec3i{ max[0], max[1] + 1, max[2] }), .dirPosY => allTrue(grid, Vec3i{min[0], max[1], min[2]}, Vec3i{max[0], max[1] + 1, max[2]}),
.dirNegY => allTrue(grid, Vec3i{ min[0], min[1] - 1, min[2] }, Vec3i{ max[0], min[1], max[2] }), .dirNegY => allTrue(grid, Vec3i{min[0], min[1] - 1, min[2]}, Vec3i{max[0], min[1], max[2]}),
}; };
} }