From ae33503d0304e8efcde9532f7acc23773fc810a6 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Thu, 29 Mar 2012 15:41:58 +0000 Subject: Fix #30716: Clamp To Constraint Locks up Blender after a while. Issue was caused by object moved really far away (not just actually issue, it's just about long mouse gesture and X-axis orientation which projects position to quite large X-axis value) and for this location start offset from curve length was calculating iteratively which takes plenty of time for short curves. Replace iterative search of offset with formula which seems to be working in the same way and should be a bit more accurate. --- source/blender/blenkernel/intern/constraint.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) (limited to 'source/blender/blenkernel/intern/constraint.c') diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index 0126f1dc416..8177d09c7e3 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -3188,25 +3188,15 @@ static void clampto_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *ta /* find bounding-box range where target is located */ if (ownLoc[clamp_axis] < curveMin[clamp_axis]) { /* bounding-box range is before */ - offset= curveMin[clamp_axis]; - - while (ownLoc[clamp_axis] < offset) - offset -= len; - + offset = curveMin[clamp_axis] - ceil((curveMin[clamp_axis] - ownLoc[clamp_axis]) / len) * len; + /* now, we calculate as per normal, except using offset instead of curveMin[clamp_axis] */ curvetime = (ownLoc[clamp_axis] - offset) / (len); } else if (ownLoc[clamp_axis] > curveMax[clamp_axis]) { /* bounding-box range is after */ - offset= curveMax[clamp_axis]; - - while (ownLoc[clamp_axis] > offset) { - if ((offset + len) > ownLoc[clamp_axis]) - break; - else - offset += len; - } - + offset= curveMax[clamp_axis] + (int)((ownLoc[clamp_axis] - curveMax[clamp_axis]) / len) * len; + /* now, we calculate as per normal, except using offset instead of curveMax[clamp_axis] */ curvetime = (ownLoc[clamp_axis] - offset) / (len); } -- cgit v1.2.3