Skip to content

Commit

Permalink
Cleanup a bit extrude tool code
Browse files Browse the repository at this point in the history
Still too complicated, as is most face manipulation code for the moment.
Need to figure out a way to make this simpler.
  • Loading branch information
guillaumechereau committed Jul 21, 2024
1 parent 3fbb82e commit cb26e76
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions src/tools/extrude.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static int on_drag(gesture3d_t *gest)
volume_t *volume = goxel.image->active_layer->volume;
volume_t *tmp_volume;
float face_plane[4][4];
float n[3], pos[3], v[3], box[4][4];
float pos[3], v[3], box[4][4];
int pi[3];
float delta;

Expand All @@ -94,7 +94,6 @@ static int on_drag(gesture3d_t *gest)

volume_set(tool->volume_orig, volume);

// XXX: to remove: this is duplicated from selection tool.
volume_get_box(tool->volume, true, box);
mat4_mul(box, FACES_MATS[tool->snap_face], face_plane);
vec3_normalize(face_plane[0], v);
Expand All @@ -104,24 +103,15 @@ static int on_drag(gesture3d_t *gest)
}

volume_get_box(tool->volume, true, box);

// XXX: have some generic way to resize boxes, since we use it all the
// time!
mat4_mul(box, FACES_MATS[tool->snap_face], face_plane);
vec3_normalize(face_plane[2], n);
// XXX: Is there a better way to compute the delta??
vec3_sub(gest->pos, gest->snap_shape[3], v);
vec3_project(v, n, v);
delta = vec3_dot(n, v);
// render_box(&goxel.rend, &box, NULL, EFFECT_WIREFRAME);
vec3_project(gest->pos, gest->start_normal, pos);
vec3_sub(pos, gest->start_pos, v);
delta = vec3_dot(gest->start_normal, v);

// Skip if we didn't move.
if (round(delta) == tool->last_delta) goto end;
tool->last_delta = round(delta);

vec3_sub(gest->pos, gest->snap_shape[3], v);
vec3_project(v, n, v);
vec3_add(gest->snap_shape[3], v, pos);
pos[0] = round(pos[0]);
pos[1] = round(pos[1]);
pos[2] = round(pos[2]);
Expand All @@ -130,15 +120,15 @@ static int on_drag(gesture3d_t *gest)
tmp_volume = volume_copy(tool->volume);

if (delta >= 1) {
vec3_iaddk(face_plane[3], n, -0.5);
vec3_iaddk(face_plane[3], gest->start_normal, -0.5);
box_move_face(box, tool->snap_face, pos, box);
volume_extrude(tmp_volume, face_plane, box);
volume_merge(volume, tmp_volume, MODE_OVER, NULL);
}
if (delta < 0.5) {
box_move_face(box, FACES_OPPOSITES[tool->snap_face], pos, box);
vec3_imul(face_plane[2], -1.0);
vec3_iaddk(face_plane[3], n, -0.5);
vec3_iaddk(face_plane[3], gest->start_normal, -0.5);
volume_extrude(tmp_volume, face_plane, box);
volume_merge(volume, tmp_volume, MODE_SUB, NULL);
}
Expand Down

0 comments on commit cb26e76

Please sign in to comment.