diff options
Diffstat (limited to 'source/blender/editors/transform/transform_mode_resize.c')
-rw-r--r-- | source/blender/editors/transform/transform_mode_resize.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/source/blender/editors/transform/transform_mode_resize.c b/source/blender/editors/transform/transform_mode_resize.c index ebce32a598e..5fb46b30e0d 100644 --- a/source/blender/editors/transform/transform_mode_resize.c +++ b/source/blender/editors/transform/transform_mode_resize.c @@ -44,6 +44,39 @@ /** \name Transform Resize * \{ */ +static float ResizeBetween(TransInfo *t, const float p1[3], const float p2[3]) +{ + float d1[3], d2[3], len_d1; + + sub_v3_v3v3(d1, p1, t->center_global); + sub_v3_v3v3(d2, p2, t->center_global); + + if (t->con.applyRot != NULL && (t->con.mode & CON_APPLY)) { + mul_m3_v3(t->con.pmtx, d1); + mul_m3_v3(t->con.pmtx, d2); + } + + project_v3_v3v3(d1, d1, d2); + + len_d1 = len_v3(d1); + + /* Use 'invalid' dist when `center == p1` (after projecting), + * in this case scale will _never_ move the point in relation to the center, + * so it makes no sense to take it into account when scaling. see: T46503 */ + return len_d1 != 0.0f ? len_v3(d2) / len_d1 : TRANSFORM_DIST_INVALID; +} + +static void ApplySnapResize(TransInfo *t, float vec[3]) +{ + float point[3]; + getSnapPoint(t, point); + + float dist = ResizeBetween(t, t->tsnap.snapTarget, point); + if (dist != TRANSFORM_DIST_INVALID) { + copy_v3_fl(vec, dist); + } +} + static void applyResize(TransInfo *t, const int UNUSED(mval[2])) { float mat[3][3]; @@ -134,6 +167,8 @@ void initResize(TransInfo *t) { t->mode = TFM_RESIZE; t->transform = applyResize; + t->tsnap.applySnap = ApplySnapResize; + t->tsnap.distance = ResizeBetween; initMouseInputMode(t, &t->mouse, INPUT_SPRING_FLIP); |