Revision: 21977
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21977
Author:   ben2610
Date:     2009-07-28 19:12:20 +0200 (Tue, 28 Jul 2009)

Log Message:
-----------
iTaSC: support multiple IK constraint on same bone + Wahonney namespace patch.

Modified Paths:
--------------
    branches/itasc/source/blender/ikplugin/intern/itasc_plugin.cpp

Modified: branches/itasc/source/blender/ikplugin/intern/itasc_plugin.cpp
===================================================================
--- branches/itasc/source/blender/ikplugin/intern/itasc_plugin.cpp      
2009-07-28 16:56:22 UTC (rev 21976)
+++ branches/itasc/source/blender/ikplugin/intern/itasc_plugin.cpp      
2009-07-28 17:12:20 UTC (rev 21977)
@@ -182,26 +182,15 @@
        IK_TRANS_Z = 5
 };
 
-int initialize_scene(Object *ob, bPoseChannel *pchan_tip)
+static int initialize_chain(Object *ob, bPoseChannel *pchan_tip, bConstraint 
*con)
 {
        bPoseChannel *curchan, *pchan_root=NULL, *chanlist[256], **oldchan;
        PoseTree *tree;
        PoseTarget *target;
-       bConstraint *con;
        bKinematicConstraint *data;
        int a, segcount= 0, size, newsize, *oldparent, parent, rootbone, 
treecount;
 
-       /* find IK constraint, and validate it */
-       for(con= (bConstraint *)pchan_tip->constraints.first; con; con= 
(bConstraint *)con->next) {
-               if(con->type==CONSTRAINT_TYPE_KINEMATIC) {
-                       data=(bKinematicConstraint*)con->data;
-                       if (data->flag & CONSTRAINT_IK_AUTO) break;
-                       if (data->tar==NULL) continue;
-                       if (data->tar->type==OB_ARMATURE && 
data->subtarget[0]==0) continue;
-                       if ((con->flag & CONSTRAINT_DISABLE)==0 && 
(con->enforce!=0.0)) break;
-               }
-       }
-       if(con==NULL) return 0;
+       data=(bKinematicConstraint*)con->data;
        
        /* exclude tip from chain? */
        if(!(data->flag & CONSTRAINT_IK_TIP))
@@ -314,6 +303,35 @@
        return treecount;
 }
 
+int initialize_scene(Object *ob, bPoseChannel *pchan_tip)
+{
+       bPoseChannel *curchan, *pchan_root=NULL, *chanlist[256], **oldchan;
+       PoseTree *tree;
+       PoseTarget *target;
+       bConstraint *con;
+       bKinematicConstraint *data;
+       int a, segcount= 0, size, newsize, *oldparent, parent, rootbone, 
treecount;
+
+       /* find all IK constraints and validate them */
+       treecount = 0;
+       for(con= (bConstraint *)pchan_tip->constraints.first; con; con= 
(bConstraint *)con->next) {
+               if(con->type==CONSTRAINT_TYPE_KINEMATIC) {
+                       data=(bKinematicConstraint*)con->data;
+                       if (data->flag & CONSTRAINT_IK_AUTO) {
+                               treecount += initialize_chain(ob, pchan_tip, 
con);
+                               continue;
+                       }
+                       if (data->tar==NULL) continue;
+                       if (data->tar->type==OB_ARMATURE && 
data->subtarget[0]==0) continue;
+                       if ((con->flag & CONSTRAINT_DISABLE)==0 && 
(con->enforce!=0.0)) {
+                               treecount += initialize_chain(ob, pchan_tip, 
con);
+                               continue;
+                       }
+               }
+       }
+       return treecount;
+}
+
 static IK_Data* get_ikdata(bPose *pose)
 {
        if (pose->ikdata)
@@ -328,15 +346,15 @@
 }
 static double EulerAngleFromMatrix(const KDL::Rotation& R, int axis)
 {
-       double t = sqrt(R(0,0)*R(0,0) + R(0,1)*R(0,1));
+       double t = KDL::sqrt(R(0,0)*R(0,0) + R(0,1)*R(0,1));
 
        if (t > 16.0*KDL::epsilon) {
-               if (axis == 0) return -atan2(R(1,2), R(2,2));
-        else if(axis == 1) return atan2(-R(0,2), t);
-        else return -atan2(R(0,1), R(0,0));
+               if (axis == 0) return -KDL::atan2(R(1,2), R(2,2));
+        else if(axis == 1) return KDL::atan2(-R(0,2), t);
+        else return -KDL::atan2(R(0,1), R(0,0));
     } else {
-               if (axis == 0) return -atan2(-R(2,1), R(1,1));
-        else if(axis == 1) return atan2(-R(0,2), t);
+               if (axis == 0) return -KDL::atan2(-R(2,1), R(1,1));
+        else if(axis == 1) return KDL::atan2(-R(0,2), t);
         else return 0.0f;
     }
 }
@@ -347,7 +365,7 @@
        double qy = R(0,2) - R(2,0);
        double qw = R(0,0) + R(1,1) + R(2,2) + 1;
 
-       double tau = 2*atan2(qy, qw);
+       double tau = 2*KDL::atan2(qy, qw);
 
        return tau;
 }
@@ -381,7 +399,7 @@
         Y = 0.0 ;
     } else {
         X = KDL::atan2(R(2,1), R(1,1));
-        Z = KDL::atan2(-R(0,1), sqrt( KDL::sqr(R(0,0)) + KDL::sqr(R(0,2))));
+        Z = KDL::atan2(-R(0,1), KDL::sqrt( KDL::sqr(R(0,0)) + 
KDL::sqr(R(0,2))));
         Y = KDL::atan2(R(0,2), R(0,0));
     }
 }
@@ -394,7 +412,7 @@
         Z = 0.0 ;
     } else {
         X = KDL::atan2(-R(1,2), R(2,2));
-        Y = KDL::atan2(R(0,2), sqrt( KDL::sqr(R(0,0)) + KDL::sqr(R(0,1))));
+        Y = KDL::atan2(R(0,2), KDL::sqrt( KDL::sqr(R(0,0)) + 
KDL::sqr(R(0,1))));
         Z = KDL::atan2(-R(0,1), R(0,0));
     }
 }


_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to