mirror of
https://github.com/PixelGuys/Cubyz.git
synced 2025-09-09 03:59:53 -04:00
Move triangleAABB back to its original location
This commit is contained in:
parent
22b66021de
commit
2c42f9e688
@ -77,14 +77,15 @@ pub const collision = struct {
|
||||
pub fn join(self: AABB, other: AABB) AABB {
|
||||
return .{.min = @min(self.min, other.min), .max = @max(self.max, other.max)};
|
||||
}
|
||||
};
|
||||
|
||||
pub fn intersectsTriangle(self: AABB, triangle: [3]Vec3d) bool {
|
||||
pub fn triangleAABB(aabb: AABB, triangle: [3]Vec3d) bool {
|
||||
const X = 0;
|
||||
const Y = 1;
|
||||
const Z = 2;
|
||||
|
||||
const box_center = self.center();
|
||||
const box_extents = self.extent();
|
||||
const box_center = aabb.center();
|
||||
const box_extents = aabb.extent();
|
||||
|
||||
// Translate triangle as conceptually moving AABB to origin
|
||||
const v0 = triangle[0] - box_center;
|
||||
@ -177,7 +178,6 @@ pub const collision = struct {
|
||||
const max_p = @max(p0, @max(p1, p2));
|
||||
return @max(-max_p, min_p) <= r;
|
||||
}
|
||||
};
|
||||
|
||||
const Direction = enum(u2) {x = 0, y = 1, z = 2};
|
||||
|
||||
|
@ -204,12 +204,12 @@ pub const Model = struct {
|
||||
}
|
||||
|
||||
fn generateCollision(self: *Model, modelQuads: []QuadInfo) void {
|
||||
var grid: [meshGridSize][meshGridSize][meshGridSize]bool = undefined;
|
||||
var hollowGrid: [meshGridSize][meshGridSize][meshGridSize]bool = undefined;
|
||||
const voxelSize: Vec3f = @splat(1.0/@as(f32, meshGridSize));
|
||||
for(0..meshGridSize) |x| {
|
||||
for(0..meshGridSize) |y| {
|
||||
for(0..meshGridSize) |z| {
|
||||
grid[x][y][z] = false;
|
||||
hollowGrid[x][y][z] = false;
|
||||
const blockX = @as(f32, @floatFromInt(x))/meshGridSize;
|
||||
const blockY = @as(f32, @floatFromInt(y))/meshGridSize;
|
||||
const blockZ = @as(f32, @floatFromInt(z))/meshGridSize;
|
||||
@ -228,8 +228,9 @@ pub const Model = struct {
|
||||
@floatCast(quad.cornerVec(3) - shift),
|
||||
};
|
||||
|
||||
if(voxel.intersectsTriangle(triangle1) or voxel.intersectsTriangle(triangle2)) {
|
||||
grid[x][y][z] = true;
|
||||
|
||||
if(main.game.collision.triangleAABB(voxel, triangle1) or main.game.collision.triangleAABB(voxel, triangle2)) {
|
||||
hollowGrid[x][y][z] = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -237,6 +238,9 @@ pub const Model = struct {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var grid: [meshGridSize][meshGridSize][meshGridSize]bool = undefined;
|
||||
|
||||
var collision: std.ArrayList(AABB) = .init(main.globalAllocator.allocator);
|
||||
|
||||
for(0..meshGridSize) |x| {
|
||||
|
Loading…
x
Reference in New Issue
Block a user