fix [#36947] "Edge Slide" bugs when "Even" is on
authorCampbell Barton <ideasman42@gmail.com>
Fri, 4 Oct 2013 05:53:02 +0000 (05:53 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 4 Oct 2013 05:53:02 +0000 (05:53 +0000)
was doing a linear interpolation between points on either side instead of interpolating along the edges.

source/blender/editors/transform/transform.c

index 87ef3d6742a0b7ced9b35eeda0ebd4059c852269..ce2f07f18130bed8c66b7c2e5fe3b84034e1201b 100644 (file)
@@ -4804,6 +4804,26 @@ static BMEdge *get_other_edge(BMVert *v, BMEdge *e)
        return NULL;
 }
 
+/* interpoaltes along a line made up of 2 segments (used for edge slide) */
+static void interp_line_v3_v3v3v3(float p[3], const float v1[3], const float v2[3], const float v3[3], const float t)
+{
+       float t_mid, t_delta;
+
+       /* could be pre-calculated */
+       t_mid = line_point_factor_v3(v2, v1, v3);
+
+       t_delta = t - t_mid;
+       if (fabsf(t_delta) < FLT_EPSILON) {
+               copy_v3_v3(p, v2);
+       }
+       else if (t_delta < 0.0f) {
+               interp_v3_v3v3(p, v1, v2, t / t_mid);
+       }
+       else {
+               interp_v3_v3v3(p, v2, v3, (t - t_mid) / (1.0f - t_mid));
+       }
+}
+
 static void len_v3_ensure(float v[3], const float length)
 {
        normalize_v3(v);
@@ -5716,20 +5736,16 @@ static void drawEdgeSlide(const struct bContext *C, TransInfo *t)
                /* Non-Prop mode */
                if (sld && sld->is_proportional == FALSE) {
                        View3D *v3d = CTX_wm_view3d(C);
-                       float marker[3];
-                       float v1[3], v2[3];
-                       float interp_v;
+                       float co_a[3], co_b[3], co_mark[3];
                        TransDataEdgeSlideVert *curr_sv = &sld->sv[sld->curr_sv_index];
+                       const float fac = (sld->perc + 1.0f) / 2.0f;
                        const float ctrl_size = UI_GetThemeValuef(TH_FACEDOT_SIZE) + 1.5f;
                        const float guide_size = ctrl_size - 0.5f;
                        const float line_size = UI_GetThemeValuef(TH_OUTLINE_WIDTH) + 0.5f;
                        const int alpha_shade = -30;
 
-                       add_v3_v3v3(v1, curr_sv->v_co_orig, curr_sv->dir_a);
-                       add_v3_v3v3(v2, curr_sv->v_co_orig, curr_sv->dir_b);
-
-                       interp_v = (sld->perc + 1.0f) / 2.0f;
-                       interp_v3_v3v3(marker, v2, v1, interp_v);
+                       add_v3_v3v3(co_a, curr_sv->v_co_orig, curr_sv->dir_a);
+                       add_v3_v3v3(co_b, curr_sv->v_co_orig, curr_sv->dir_b);
 
                        if (v3d && v3d->zbuf)
                                glDisable(GL_DEPTH_TEST);
@@ -5770,7 +5786,12 @@ static void drawEdgeSlide(const struct bContext *C, TransInfo *t)
                        UI_ThemeColorShadeAlpha(TH_SELECT, 255, alpha_shade);
                        glPointSize(guide_size);
                        bglBegin(GL_POINTS);
-                       bglVertex3fv(marker);
+#if 0
+                       interp_v3_v3v3(co_mark, co_b, co_a, fac);
+                       bglVertex3fv(co_mark);
+#endif
+                       interp_line_v3_v3v3v3(co_mark, co_b, curr_sv->v_co_orig, co_a, fac);
+                       bglVertex3fv(co_mark);
                        bglEnd();
 
 
@@ -5832,10 +5853,10 @@ static int doEdgeSlide(TransInfo *t, float perc)
                                add_v3_v3v3(co_b, sv->v_co_orig, sv->dir_b);
 
                                if (sld->flipped_vtx) {
-                                       interp_v3_v3v3(sv->v->co, co_b, co_a, fac);
+                                       interp_line_v3_v3v3v3(sv->v->co, co_b, sv->v_co_orig, co_a, fac);
                                }
                                else {
-                                       interp_v3_v3v3(sv->v->co, co_a, co_b, fac);
+                                       interp_line_v3_v3v3v3(sv->v->co, co_a, sv->v_co_orig, co_b, fac);
                                }
                        }
                }