static box_t get_box(const vec3_t *p0, const vec3_t *p1, const vec3_t *n, float r, const plane_t *plane) { mat4_t rot; box_t box; if (p1 == NULL) { box = bbox_from_extents(*p0, r, r, r); box = box_swap_axis(box, 2, 0, 1); return box; } if (r == 0) { box = bbox_grow(bbox_from_points(*p0, *p1), 0.5, 0.5, 0.5); // Apply the plane rotation. rot = plane->mat; rot.vecs[3] = vec4(0, 0, 0, 1); mat4_imul(&box.mat, rot); return box; } // Create a box for a line: int i; const vec3_t AXES[] = {vec3(1, 0, 0), vec3(0, 1, 0), vec3(0, 0, 1)}; box.mat = mat4_identity; box.p = vec3_mix(*p0, *p1, 0.5); box.d = vec3_sub(*p1, box.p); for (i = 0; i < 3; i++) { box.w = vec3_cross(box.d, AXES[i]); if (vec3_norm2(box.w) > 0) break; } if (i == 3) return box; box.w = vec3_mul(vec3_normalized(box.w), r); box.h = vec3_mul(vec3_normalized(vec3_cross(box.d, box.w)), r); return box; }
box_t block_get_box(const block_t *block, bool exact) { box_t ret; int x, y, z; int xmin = N, xmax = 0, ymin = N, ymax = 0, zmin = N, zmax = 0; if (!exact) return bbox_from_extents(block->pos, N / 2, N / 2, N / 2); BLOCK_ITER(x, y, z) { if (BLOCK_AT(block, x, y, z).a) { xmin = min(xmin, x); ymin = min(ymin, y); zmin = min(zmin, z); xmax = max(xmax, x); ymax = max(ymax, y); zmax = max(zmax, z); } } if (xmin > xmax) return box_null(); ret = bbox_from_points(vec3(xmin - 0.5, ymin - 0.5, zmin - 0.5), vec3(xmax + 0.5, ymax + 0.5, zmax + 0.5)); vec3_iadd(&ret.p, block->pos); vec3_isub(&ret.p, vec3(N / 2 - 0.5, N / 2 - 0.5, N / 2 - 0.5)); return ret; }