diff options
author | Joshua Leung <aligorith@gmail.com> | 2008-12-19 14:45:46 +0300 |
---|---|---|
committer | Joshua Leung <aligorith@gmail.com> | 2008-12-19 14:45:46 +0300 |
commit | c752ec9fc458f6fd1fc0ae7a156d33bf86e73eff (patch) | |
tree | 8f559ef2cd1ce8a1c4ccee72096f34b1caf3c46f /source/blender/blenkernel/intern/constraint.c | |
parent | 242695011e71a358f466d4f78df3b9c66d739a64 (diff) |
2.5
Merged 'backend' changes from AnimSys2. Many of these changes are necessary for the Dopesheet and other changes I'm currently still stabilising. Those will come in due course.
Diffstat (limited to 'source/blender/blenkernel/intern/constraint.c')
-rw-r--r-- | source/blender/blenkernel/intern/constraint.c | 66 |
1 files changed, 38 insertions, 28 deletions
diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index b8bfb002075..cbdcfa56ff2 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -69,6 +69,7 @@ #include "BPY_extern.h" #endif + #ifdef HAVE_CONFIG_H #include <config.h> #endif @@ -3021,44 +3022,53 @@ static void clampto_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *ta float len= (curveMax[clamp_axis] - curveMin[clamp_axis]); float offset; - /* 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; - - /* 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; + /* check to make sure len is not so close to zero that it'll cause errors */ + if (IS_EQ(len, 0) == 0) { + /* 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; + + /* 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; + } + + /* now, we calculate as per normal, except using offset instead of curveMax[clamp_axis] */ + curvetime = (ownLoc[clamp_axis] - offset) / (len); + } + else { + /* as the location falls within bounds, just calculate */ + curvetime = (ownLoc[clamp_axis] - curveMin[clamp_axis]) / (len); } - - /* now, we calculate as per normal, except using offset instead of curveMax[clamp_axis] */ - curvetime = (ownLoc[clamp_axis] - offset) / (len); } else { - /* as the location falls within bounds, just calculate */ - curvetime = (ownLoc[clamp_axis] - curveMin[clamp_axis]) / (len); + /* as length is close to zero, curvetime by default should be 0 (i.e. the start) */ + curvetime= 0.0f; } } else { /* no cyclic, so position is clamped to within the bounding box */ if (ownLoc[clamp_axis] <= curveMin[clamp_axis]) - curvetime = 0.0; + curvetime = 0.0f; else if (ownLoc[clamp_axis] >= curveMax[clamp_axis]) - curvetime = 1.0; - else + curvetime = 1.0f; + else if ( IS_EQ((curveMax[clamp_axis] - curveMin[clamp_axis]), 0) == 0 ) curvetime = (ownLoc[clamp_axis] - curveMin[clamp_axis]) / (curveMax[clamp_axis] - curveMin[clamp_axis]); + else + curvetime = 0.0f; } /* 3. position on curve */ |