== Constraints - Important Bugfix ==
authorJoshua Leung <aligorith@gmail.com>
Tue, 24 Jul 2007 05:08:55 +0000 (05:08 +0000)
committerJoshua Leung <aligorith@gmail.com>
Tue, 24 Jul 2007 05:08:55 +0000 (05:08 +0000)
I've finally fixed the bug with the Constraint Space Conversion. It was a single matrix multiplication in the wrong order (for local->pose).

Also, there is more code added for the space conversion process when bones have 'hinge' on. (NOTE: this stuff for hinge bones may still not work really nice yet)

source/blender/blenkernel/BKE_constraint.h
source/blender/blenkernel/intern/constraint.c

index 6a11159645c5c1a8079dd9dffa972c48fb33b314..02084b497165e0f49adcedfa5d368bb08e18b23c 100644 (file)
@@ -25,7 +25,7 @@
  *
  * The Original Code is: all of this file.
  *
- * Contributor(s): none yet.
+ * Contributor(s): 2007 - Joshua Leung (major recode)
  *
  * ***** END GPL/BL DUAL LICENSE BLOCK *****
  */
index ad1e4d10cd32b025869f64dfd38fe1c21e07b4fa..95359a22711a306f30fa3db67c63e735ecf0e1c8 100644 (file)
@@ -1017,9 +1017,30 @@ static void constraint_mat_convertspace (Object *ob, bPoseChannel *pchan, float
                                                        VECCOPY(offs_bone[3], pchan->bone->head);
                                                        offs_bone[3][1]+= pchan->parent->bone->length;
                                                        
-                                                       Mat4MulMat4(diff_mat, offs_bone, pchan->parent->pose_mat);
-                                                       Mat4CpyMat4(tempmat, mat);
-                                                       Mat4MulMat4(mat, tempmat, diff_mat);
+                                                       if (pchan->bone->flag & BONE_HINGE) {
+                                                               /* pose_mat = par_pose-space_location * chan_mat */
+                                                               float tmat[4][4];
+                                                               
+                                                               /* the rotation of the parent restposition */
+                                                               Mat4CpyMat4(tmat, pchan->parent->bone->arm_mat);
+                                                               
+                                                               /* the location of actual parent transform */
+                                                               VECCOPY(tmat[3], offs_bone[3]);
+                                                               offs_bone[3][0]= offs_bone[3][1]= offs_bone[3][2]= 0.0f;
+                                                               Mat4MulVecfl(pchan->parent->pose_mat, tmat[3]);
+                                                               
+                                                               Mat4MulMat4(diff_mat, offs_bone, tmat);
+                                                               
+                                                               Mat4MulMat4(diff_mat, pchan->parent->pose_mat, offs_bone);
+                                                               Mat4CpyMat4(tempmat, mat);
+                                                               Mat4MulMat4(mat, tempmat, diff_mat);
+                                                       }
+                                                       else {
+                                                               /* pose_mat = par_pose_mat * bone_mat * chan_mat */
+                                                               Mat4MulMat4(diff_mat, pchan->parent->pose_mat, offs_bone);
+                                                               Mat4CpyMat4(tempmat, mat);
+                                                               Mat4MulMat4(mat, tempmat, diff_mat);
+                                                       }
                                                }
                                                else {
                                                        Mat4CpyMat4(diff_mat, pchan->bone->arm_mat);