Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2012-02-23 00:06:33 +0400
committerBastien Montagne <montagne29@wanadoo.fr>2012-02-23 00:06:33 +0400
commit6c0361dff78e69849c323561b99669042ae68f3f (patch)
treec2a5b8e44e2bcde320856b6ef794982ea9133e46 /source/blender/blenkernel/intern/constraint.c
parentbb5e545bf43da717066964d1ea05c3f8248777f2 (diff)
Armature pose evaluation: more factorization of code.
Now constraints' space conversion code also uses generic armature_mat_(pose_to_bone/bone_to_pose). Previous own function (constraint_pchan_diff_mat) was somewhat inconsistent too with Hinge/NoScale/LocalLocation options... As with previous similar changes, this might break some old rigs, in very specific cases (when constraint-evaluating an hinge/noscale/local_location bone in local space). In the same part of code, removed unnecessary matrices copying, mult_m4_m4m4 can take the same matrix as input and output, nowadays... Also found a bug-generator weakness in those armature_mat_ functions (if both input and output mat where the same, result was wrong, now systematically copying input mat, as done in LIB's matrix funcs). Finally, factorized offset bone matrix generation into its own small function too, as it is used in two different places in armature.c (pchan_to_pose_mat itself, and restpose's where_is_armature_bone). Note: I think all parts of blender's code related to that topic have now been tackled, but yet have to check BGE, it’s probably using that stuff too, one way or the other...
Diffstat (limited to 'source/blender/blenkernel/intern/constraint.c')
-rw-r--r--source/blender/blenkernel/intern/constraint.c41
1 files changed, 18 insertions, 23 deletions
diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c
index 833f14ff074..e8c6ec8d3ed 100644
--- a/source/blender/blenkernel/intern/constraint.c
+++ b/source/blender/blenkernel/intern/constraint.c
@@ -223,6 +223,7 @@ void constraints_clear_evalob (bConstraintOb *cob)
/* -------------- Space-Conversion API -------------- */
+#if 0 /* XXX Old code, does the same as one in armature.c, will remove it later. */
static void constraint_pchan_diff_mat(bPoseChannel *pchan, float diff_mat[4][4])
{
if (pchan->parent) {
@@ -265,7 +266,7 @@ static void constraint_pchan_diff_mat(bPoseChannel *pchan, float diff_mat[4][4])
copy_m4_m4(diff_mat, pchan->bone->arm_mat);
}
}
-
+#endif
/* This function is responsible for the correct transformations/conversions
* of a matrix from one space to another for constraint evaluation.
@@ -273,7 +274,6 @@ static void constraint_pchan_diff_mat(bPoseChannel *pchan, float diff_mat[4][4])
*/
void constraint_mat_convertspace (Object *ob, bPoseChannel *pchan, float mat[][4], short from, short to)
{
- float tempmat[4][4];
float diff_mat[4][4];
float imat[4][4];
@@ -290,8 +290,7 @@ void constraint_mat_convertspace (Object *ob, bPoseChannel *pchan, float mat[][4
{
/* world to pose */
invert_m4_m4(imat, ob->obmat);
- copy_m4_m4(tempmat, mat);
- mult_m4_m4m4(mat, imat, tempmat);
+ mult_m4_m4m4(mat, imat, mat);
/* use pose-space as stepping stone for other spaces... */
if (ELEM(to, CONSTRAINT_SPACE_LOCAL, CONSTRAINT_SPACE_PARLOCAL)) {
@@ -304,32 +303,31 @@ void constraint_mat_convertspace (Object *ob, bPoseChannel *pchan, float mat[][4
{
/* pose to world */
if (to == CONSTRAINT_SPACE_WORLD) {
- copy_m4_m4(tempmat, mat);
- mult_m4_m4m4(mat, ob->obmat, tempmat);
+ mult_m4_m4m4(mat, ob->obmat, mat);
}
/* pose to local */
else if (to == CONSTRAINT_SPACE_LOCAL) {
if (pchan->bone) {
+ armature_mat_pose_to_bone(pchan, mat, mat);
+#if 0 /* XXX Old code, will remove it later. */
constraint_pchan_diff_mat(pchan, diff_mat);
invert_m4_m4(imat, diff_mat);
-
- copy_m4_m4(tempmat, mat);
- mult_m4_m4m4(mat, imat, tempmat);
+ mult_m4_m4m4(mat, imat, mat);
/* override with local location */
if ((pchan->parent) && (pchan->bone->flag & BONE_NO_LOCAL_LOCATION)) {
armature_mat_pose_to_bone_ex(ob, pchan, pchan->pose_mat, tempmat);
copy_v3_v3(mat[3], tempmat[3]);
}
+#endif
}
}
/* pose to local with parent */
else if (to == CONSTRAINT_SPACE_PARLOCAL) {
if (pchan->bone) {
invert_m4_m4(imat, pchan->bone->arm_mat);
- copy_m4_m4(tempmat, mat);
- mult_m4_m4m4(mat, imat, tempmat);
+ mult_m4_m4m4(mat, imat, mat);
}
}
}
@@ -339,10 +337,12 @@ void constraint_mat_convertspace (Object *ob, bPoseChannel *pchan, float mat[][4
/* local to pose - do inverse procedure that was done for pose to local */
if (pchan->bone) {
/* we need the posespace_matrix = local_matrix + (parent_posespace_matrix + restpos) */
+ armature_mat_bone_to_pose(pchan, mat, mat);
+#if 0
constraint_pchan_diff_mat(pchan, diff_mat);
- copy_m4_m4(tempmat, mat);
- mult_m4_m4m4(mat, diff_mat, tempmat);
+ mult_m4_m4m4(mat, diff_mat, mat);
+#endif
}
/* use pose-space as stepping stone for other spaces */
@@ -357,8 +357,7 @@ void constraint_mat_convertspace (Object *ob, bPoseChannel *pchan, float mat[][4
/* local + parent to pose */
if (pchan->bone) {
copy_m4_m4(diff_mat, pchan->bone->arm_mat);
- copy_m4_m4(tempmat, mat);
- mult_m4_m4m4(mat, tempmat, diff_mat);
+ mult_m4_m4m4(mat, mat, diff_mat);
}
/* use pose-space as stepping stone for other spaces */
@@ -378,8 +377,7 @@ void constraint_mat_convertspace (Object *ob, bPoseChannel *pchan, float mat[][4
/* 'subtract' parent's effects from owner */
mult_m4_m4m4(diff_mat, ob->parent->obmat, ob->parentinv);
invert_m4_m4(imat, diff_mat);
- copy_m4_m4(tempmat, mat);
- mult_m4_m4m4(mat, imat, tempmat);
+ mult_m4_m4m4(mat, imat, mat);
}
else {
/* Local space in this case will have to be defined as local to the owner's
@@ -390,17 +388,15 @@ void constraint_mat_convertspace (Object *ob, bPoseChannel *pchan, float mat[][4
zero_v3(diff_mat[3]);
invert_m4_m4(imat, diff_mat);
- copy_m4_m4(tempmat, mat);
- mult_m4_m4m4(mat, imat, tempmat);
+ mult_m4_m4m4(mat, imat, mat);
}
}
else if (from==CONSTRAINT_SPACE_LOCAL && to==CONSTRAINT_SPACE_WORLD) {
/* check that object has a parent - otherwise this won't work */
if (ob->parent) {
/* 'add' parent's effect back to owner */
- copy_m4_m4(tempmat, mat);
mult_m4_m4m4(diff_mat, ob->parent->obmat, ob->parentinv);
- mult_m4_m4m4(mat, diff_mat, tempmat);
+ mult_m4_m4m4(mat, diff_mat, mat);
}
else {
/* Local space in this case will have to be defined as local to the owner's
@@ -410,8 +406,7 @@ void constraint_mat_convertspace (Object *ob, bPoseChannel *pchan, float mat[][4
normalize_m4(diff_mat);
zero_v3(diff_mat[3]);
- copy_m4_m4(tempmat, mat);
- mult_m4_m4m4(mat, diff_mat, tempmat);
+ mult_m4_m4m4(mat, diff_mat, mat);
}
}
}