[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [23039] branches/blender2.5/blender/source /blender: 2.5 - Rotation Order Tweaks

Joshua Leung aligorith at gmail.com
Mon Sep 7 01:15:43 CEST 2009


Revision: 23039
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=23039
Author:   aligorith
Date:     2009-09-07 01:15:43 +0200 (Mon, 07 Sep 2009)

Log Message:
-----------
2.5 - Rotation Order Tweaks

* Copy Rotation constraint should now work ok with this new code again. Previously, it was the only thing that really went beserk when the typos were still uncaught.

* Fixed one other case of a potential case where typos would cause problems.

* Made changing the rotation order setting perform conversions of the current rotation to an equivalent representation in the other orders/forms. This is done at RNA level, so maybe not that great for switching representations while animating?

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/blenkernel/intern/constraint.c
    branches/blender2.5/blender/source/blender/blenlib/intern/arithb.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_pose.c

Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/constraint.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/constraint.c	2009-09-06 20:59:06 UTC (rev 23038)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/constraint.c	2009-09-06 23:15:43 UTC (rev 23039)
@@ -1558,8 +1558,7 @@
 		VECCOPY(loc, cob->matrix[3]);
 		Mat4ToSize(cob->matrix, size);
 		
-		//Mat4ToEulO(ct->matrix, eul, ct->rotOrder);
-		Mat4ToEul(ct->matrix, eul); // the version we should be using causes errors...
+		Mat4ToEulO(ct->matrix, eul, ct->rotOrder);
 		Mat4ToEulO(cob->matrix, obeul, cob->rotOrder);
 		
 		if ((data->flag & ROTLIKE_X)==0)

Modified: branches/blender2.5/blender/source/blender/blenlib/intern/arithb.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenlib/intern/arithb.c	2009-09-06 20:59:06 UTC (rev 23038)
+++ branches/blender2.5/blender/source/blender/blenlib/intern/arithb.c	2009-09-06 23:15:43 UTC (rev 23039)
@@ -2835,10 +2835,10 @@
 	double ti, tj, th, ci, cj, ch, si, sj, sh, cc, cs, sc, ss;
 	double a[3];
 	
-	if (R->parity) e[1] = -e[1]; // xxx watch it!
-	
 	ti = e[i]/2; tj = e[j]/2; th = e[k]/2;
 	
+	if (R->parity) e[j] = -e[j];
+	
 	ci = cos(ti);  cj = cos(tj);  ch = cos(th);
 	si = sin(ti);  sj = sin(tj);  sh = sin(th);
 	

Modified: branches/blender2.5/blender/source/blender/makesrna/intern/rna_pose.c
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/intern/rna_pose.c	2009-09-06 20:59:06 UTC (rev 23038)
+++ branches/blender2.5/blender/source/blender/makesrna/intern/rna_pose.c	2009-09-06 23:15:43 UTC (rev 23039)
@@ -130,6 +130,67 @@
 		VECCOPY(pchan->eul, value);
 }
 
+static void rna_PoseChannel_rotation_mode_set(PointerRNA *ptr, int value)
+{
+	bPoseChannel *pchan= ptr->data;
+	
+	/* check if any change - if so, need to convert data */
+	// TODO: this needs to be generalised at some point to work for objects too...
+	if (value > 0) { /* to euler */
+		if (pchan->rotmode < 0) { // FIXME: need a define for this
+			/* axis-angle to euler */
+			float m[3][3];
+			
+			/* convert to 3x3 matrix, then to euler 
+			 *	- axis angle is stored in quats
+			 */
+			VecRotToMat3(&pchan->quat[1], pchan->quat[0], m);
+			Mat3ToEulO(m, pchan->eul, value);
+		}
+		else if (pchan->rotmode == PCHAN_ROT_QUAT) {
+			/* quat to euler */
+			QuatToEulO(pchan->quat, pchan->eul, value);
+		}
+		/* else { no conversion needed } */
+	}
+	else if (value == PCHAN_ROT_QUAT) { /* to quat */
+		if (pchan->rotmode < 0) { // FIXME: need a define for this
+			/* axis angle to quat */
+			float q[4];
+			
+			/* copy to temp var first, since quats and axis-angle are stored in same place */
+			QuatCopy(q, pchan->quat);
+			AxisAngleToQuat(q, &pchan->quat[1], pchan->quat[0]);
+		}
+		else if (pchan->rotmode > 0) {
+			/* euler to quat */
+			EulOToQuat(pchan->eul, pchan->rotmode, pchan->quat);
+		}
+		/* else { no conversion needed } */
+	}
+	else { /* to axis-angle */
+		if (pchan->rotmode > 0) { // FIXME: need a define for this
+			/* euler to axis angle */
+			float q[4];
+			
+			/* convert to temp quat, then to axis angle (since stored in same var) */
+			EulOToQuat(pchan->eul, pchan->rotmode, q);
+			QuatToAxisAngle(q, &pchan->quat[1], pchan->quat[0]);
+		}
+		else if (pchan->rotmode == PCHAN_ROT_QUAT) {
+			/* quat to axis angle */
+			float q[4];
+			
+			/* copy to temp var first, since quats and axis-angle are stored in same place */
+			QuatCopy(q, pchan->quat);
+			QuatToAxisAngle(q, &pchan->quat[1], pchan->quat[0]);
+		}
+	}
+	
+	/* finally, set the new rotation type */
+	pchan->rotmode= value;
+}
+
 static void rna_PoseChannel_name_set(PointerRNA *ptr, const char *value)
 {
 	Object *ob= (Object*)ptr->id.data;
@@ -439,6 +500,7 @@
 	prop= RNA_def_property(srna, "rotation_mode", PROP_ENUM, PROP_NONE);
 	RNA_def_property_enum_sdna(prop, NULL, "rotmode");
 	RNA_def_property_enum_items(prop, prop_rotmode_items);
+	RNA_def_property_enum_funcs(prop, NULL, "rna_PoseChannel_rotation_mode_set", NULL);
 	RNA_def_property_ui_text(prop, "Rotation Mode", "");
 	RNA_def_property_update(prop, NC_OBJECT|ND_POSE|ND_TRANSFORM, "rna_Pose_update");
 





More information about the Bf-blender-cvs mailing list