diff options
author | Joshua Leung <aligorith@gmail.com> | 2007-07-29 15:15:37 +0400 |
---|---|---|
committer | Joshua Leung <aligorith@gmail.com> | 2007-07-29 15:15:37 +0400 |
commit | 6dcde0b5be6d87981fcdd27c924ec1c9e4965c96 (patch) | |
tree | f2bf5eee347605d887c3c83269ef80c49f80f07a /source | |
parent | ddbd9182d41b89f7bec11400a1949759dcfcf3fe (diff) |
More Constraints Bugfixes:
* Transform Constraint should now work in more cases. Somehow the old code (for location case) wasn't working correctly.
* ChildOf Constraint applied on objects, should now get the right 'inverse'/'offset' matrix set. It now uses the same code that is used by Blender's parenting method to do so.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/intern/constraint.c | 6 | ||||
-rw-r--r-- | source/blender/include/BIF_editconstraint.h | 4 | ||||
-rw-r--r-- | source/blender/src/buttons_object.c | 27 | ||||
-rw-r--r-- | source/blender/src/editconstraint.c | 40 |
4 files changed, 49 insertions, 28 deletions
diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index 2ab7bfb6049..55470d0117c 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -2623,8 +2623,12 @@ static void evaluate_constraint (bConstraint *constraint, float ownermat[][4], f } break; default: /* location */ + /* get new location */ for (i=0; i<3; i++) - loc[i] += (data->to_min[i] + (sval[data->map[i]] * (data->to_max[i] - data->to_min[i]))); + loc[i]= (data->to_min[i] + (sval[data->map[i]] * (data->to_max[i] - data->to_min[i]))); + + /* add original location back on (so that it can still be moved) */ + VecAddf(loc, ownermat[3], loc); break; } diff --git a/source/blender/include/BIF_editconstraint.h b/source/blender/include/BIF_editconstraint.h index 68327bdd684..f9ed4048fc7 100644 --- a/source/blender/include/BIF_editconstraint.h +++ b/source/blender/include/BIF_editconstraint.h @@ -65,5 +65,9 @@ void rename_constraint(struct Object *ob, struct bConstraint *con, char *newname char *buildmenu_pyconstraints(struct Text *con_text, int *pyconindex); void validate_pyconstraint_cb(void *arg1, void *arg2); +/* two special functions for ChildOf Constriant */ +void childof_const_setinv (void *conv, void *unused); +void childof_const_clearinv(void *conv, void *unused); + #endif diff --git a/source/blender/src/buttons_object.c b/source/blender/src/buttons_object.c index d2ca53743f7..db926e6b49c 100644 --- a/source/blender/src/buttons_object.c +++ b/source/blender/src/buttons_object.c @@ -478,33 +478,6 @@ void autocomplete_vgroup(char *str, void *arg_v) } } -/* ChildOf Constraint - set inverse */ -static void childof_const_setinv (void *conv, void *unused) -{ - bChildOfConstraint *data= (bChildOfConstraint *)conv; - Object *ob= OBACT; - bPoseChannel *pchan= NULL; - - if (ob && ob->pose) - pchan= get_active_posechannel(ob); - - // for now, try using constinv if available - if (pchan) - Mat4CpyMat4(data->invmat, pchan->constinv); - else if (ob) - Mat4CpyMat4(data->invmat, ob->constinv); - else - Mat4One(data->invmat); -} - -/* ChildOf Constraint - clear inverse */ -static void childof_const_clearinv (void *conv, void *unused) -{ - bChildOfConstraint *data= (bChildOfConstraint *)conv; - - Mat4One(data->invmat); -} - /* Helper function for draw constraint - draws constraint space stuff * This function should not be called if no menus are required * owner/target: -1 = don't draw menu; 0= not posemode, 1 = posemode diff --git a/source/blender/src/editconstraint.c b/source/blender/src/editconstraint.c index 4ef1b4e961a..907d2139e1e 100644 --- a/source/blender/src/editconstraint.c +++ b/source/blender/src/editconstraint.c @@ -1010,3 +1010,43 @@ char *buildmenu_pyconstraints(Text *con_text, int *pyconindex) return menustr; } + +/* ------------- Child-Of Constraint ------------------ */ + +/* ChildOf Constraint - set inverse callback */ +void childof_const_setinv (void *conv, void *unused) +{ + bChildOfConstraint *data= (bChildOfConstraint *)conv; + Object *ob= OBACT; + bPoseChannel *pchan= NULL; + + /* try to find a pose channel */ + if (ob && ob->pose) + pchan= get_active_posechannel(ob); + + /* calculate/set inverse matrix */ + if (pchan) { + /* for now, just use pchan->constinv. + * NOTE: bad hack... doesn't work in many cases + */ + Mat4CpyMat4(data->invmat, pchan->constinv); + } + else if (ob) { + /* use what_does_parent to find inverse - just like for normal parenting. + * NOTE: what_does_parent uses a static workob defined in object.c + */ + what_does_parent(ob); + Mat4Invert(data->invmat, workob.obmat); + } + else + Mat4One(data->invmat); +} + +/* ChildOf Constraint - clear inverse callback */ +void childof_const_clearinv (void *conv, void *unused) +{ + bChildOfConstraint *data= (bChildOfConstraint *)conv; + + /* simply clear the matrix */ + Mat4One(data->invmat); +} |