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; }
static void do_move(layer_t *layer, const float mat[4][4]) { float m[4][4]; mat4_set_identity(m); // Change referential to the mesh origin. // XXX: maybe this should be done in mesh_move directy?? mat4_itranslate(m, -0.5, -0.5, -0.5); mat4_imul(m, mat); mat4_itranslate(m, +0.5, +0.5, +0.5); if (layer->base_id || layer->image) { mat4_mul(mat, layer->mat, layer->mat); layer->base_mesh_key = 0; } else { mesh_move(layer->mesh, m); if (!box_is_null(layer->box)) { mat4_mul(mat, layer->box, layer->box); box_get_bbox(layer->box, layer->box); } } goxel_update_meshes(goxel, -1); }