[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [22948] branches/blender2.5/blender/source /blender: 2.5 - Rotation order is now taken into account for constraints

Joshua Leung aligorith at gmail.com
Wed Sep 2 12:45:12 CEST 2009


Revision: 22948
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=22948
Author:   aligorith
Date:     2009-09-02 12:45:11 +0200 (Wed, 02 Sep 2009)

Log Message:
-----------
2.5 - Rotation order is now taken into account for constraints

* Added a 'rotOrder' parameter for constraint evaluation objects and constraint targets, which describes the rotation mode used for the matrices there. 

Todos:
* Constraint targets default to using XYZ only for now. This will need be be addressed eventually.
* Copy Rotation constraint currently cannot use the new rotation order code for the target matrix. What's surprising is that even though it's just using XYZ as the old code did, it doesn't work, and yet everything else works nicely. Silly constraint! (it is almost impossible to improve this constraint further without breaking a rig out there)

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/blenkernel/BKE_constraint.h
    branches/blender2.5/blender/source/blender/blenkernel/intern/constraint.c
    branches/blender2.5/blender/source/blender/blenlib/BLI_arithb.h
    branches/blender2.5/blender/source/blender/blenlib/intern/arithb.c
    branches/blender2.5/blender/source/blender/makesdna/DNA_constraint_types.h

Modified: branches/blender2.5/blender/source/blender/blenkernel/BKE_constraint.h
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/BKE_constraint.h	2009-09-02 10:14:03 UTC (rev 22947)
+++ branches/blender2.5/blender/source/blender/blenkernel/BKE_constraint.h	2009-09-02 10:45:11 UTC (rev 22948)
@@ -49,6 +49,7 @@
 	float startmat[4][4];		/* original matrix (before constraint solving) */
 	
 	short type;					/* type of owner  */
+	short rotOrder;				/* rotation order for constraint owner (as defined in eEulerRotationOrders in BLI_arithb.h) */
 } bConstraintOb;
 
 /* ---------------------------------------------------------------------------- */

Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/constraint.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/constraint.c	2009-09-02 10:14:03 UTC (rev 22947)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/constraint.c	2009-09-02 10:45:11 UTC (rev 22948)
@@ -121,6 +121,7 @@
 			if (ob) {
 				cob->ob = ob;
 				cob->type = datatype;
+				cob->rotOrder = EULER_ORDER_DEFAULT; // TODO: when objects have rotation order too, use that
 				Mat4CpyMat4(cob->matrix, ob->obmat);
 			}
 			else
@@ -137,6 +138,15 @@
 				cob->pchan = (bPoseChannel *)subdata;
 				cob->type = datatype;
 				
+				if (cob->pchan->rotmode > 0) {
+					/* should be some type of Euler order */
+					cob->rotOrder= cob->pchan->rotmode; 
+				}
+				else {
+					/* Quats, so eulers should just use default order */
+					cob->rotOrder= EULER_ORDER_DEFAULT;
+				}
+				
 				/* matrix in world-space */
 				Mat4MulMat4(cob->matrix, cob->pchan->pose_mat, ob->obmat);
 			}
@@ -664,6 +674,7 @@
  * (Hopefully all compilers will be happy with the lines with just a space on them. Those are
  *  really just to help this code easier to read)
  */
+// TODO: cope with getting rotation order...
 #define SINGLETARGET_GET_TARS(con, datatar, datasubtarget, ct, list) \
 	{ \
 		ct= MEM_callocN(sizeof(bConstraintTarget), "tempConstraintTarget"); \
@@ -687,6 +698,7 @@
  * (Hopefully all compilers will be happy with the lines with just a space on them. Those are
  *  really just to help this code easier to read)
  */
+// TODO: cope with getting rotation order...
 #define SINGLETARGETNS_GET_TARS(con, datatar, ct, list) \
 	{ \
 		ct= MEM_callocN(sizeof(bConstraintTarget), "tempConstraintTarget"); \
@@ -795,11 +807,11 @@
 		
 		/* extract components of both matrices */
 		VECCOPY(loc, ct->matrix[3]);
-		Mat4ToEul(ct->matrix, eul);
+		Mat4ToEulO(ct->matrix, eul, ct->rotOrder);
 		Mat4ToSize(ct->matrix, size);
 		
 		VECCOPY(loco, invmat[3]);
-		Mat4ToEul(invmat, eulo);
+		Mat4ToEulO(invmat, eulo, cob->rotOrder);
 		Mat4ToSize(invmat, sizo);
 		
 		/* disable channels not enabled */
@@ -814,8 +826,8 @@
 		if (!(data->flag & CHILDOF_SIZEZ)) size[2]= sizo[2]= 1.0f;
 		
 		/* make new target mat and offset mat */
-		LocEulSizeToMat4(ct->matrix, loc, eul, size);
-		LocEulSizeToMat4(invmat, loco, eulo, sizo);
+		LocEulOSizeToMat4(ct->matrix, loc, eul, size, ct->rotOrder);
+		LocEulOSizeToMat4(invmat, loco, eulo, sizo, cob->rotOrder);
 		
 		/* multiply target (parent matrix) by offset (parent inverse) to get 
 		 * the effect of the parent that will be exherted on the owner
@@ -1304,7 +1316,7 @@
 	VECCOPY(loc, cob->matrix[3]);
 	Mat4ToSize(cob->matrix, size);
 	
-	Mat4ToEul(cob->matrix, eul);
+	Mat4ToEulO(cob->matrix, eul, cob->rotOrder);
 	
 	/* eulers: radians to degrees! */
 	eul[0] = (float)(eul[0] / M_PI * 180);
@@ -1339,7 +1351,7 @@
 	eul[1] = (float)(eul[1] / 180 * M_PI);
 	eul[2] = (float)(eul[2] / 180 * M_PI);
 	
-	LocEulSizeToMat4(cob->matrix, loc, eul, size);
+	LocEulOSizeToMat4(cob->matrix, loc, eul, size, cob->rotOrder);
 }
 
 static bConstraintTypeInfo CTI_ROTLIMIT = {
@@ -1546,14 +1558,15 @@
 		VECCOPY(loc, cob->matrix[3]);
 		Mat4ToSize(cob->matrix, size);
 		
-		Mat4ToEul(ct->matrix, eul);
-		Mat4ToEul(cob->matrix, obeul);
+		//Mat4ToEulO(ct->matrix, eul, ct->rotOrder);
+		Mat4ToEul(ct->matrix, eul); // the version we should be using causes errors...
+		Mat4ToEulO(cob->matrix, obeul, cob->rotOrder);
 		
 		if ((data->flag & ROTLIKE_X)==0)
 			eul[0] = obeul[0];
 		else {
 			if (data->flag & ROTLIKE_OFFSET)
-				euler_rot(eul, obeul[0], 'x');
+				eulerO_rot(eul, obeul[0], 'x', cob->rotOrder);
 			
 			if (data->flag & ROTLIKE_X_INVERT)
 				eul[0] *= -1;
@@ -1563,7 +1576,7 @@
 			eul[1] = obeul[1];
 		else {
 			if (data->flag & ROTLIKE_OFFSET)
-				euler_rot(eul, obeul[1], 'y');
+				eulerO_rot(eul, obeul[1], 'y', cob->rotOrder);
 			
 			if (data->flag & ROTLIKE_Y_INVERT)
 				eul[1] *= -1;
@@ -1573,14 +1586,14 @@
 			eul[2] = obeul[2];
 		else {
 			if (data->flag & ROTLIKE_OFFSET)
-				euler_rot(eul, obeul[2], 'z');
+				eulerO_rot(eul, obeul[2], 'z', cob->rotOrder);
 			
 			if (data->flag & ROTLIKE_Z_INVERT)
 				eul[2] *= -1;
 		}
 		
 		compatible_eul(eul, obeul);
-		LocEulSizeToMat4(cob->matrix, loc, eul, size);
+		LocEulOSizeToMat4(cob->matrix, loc, eul, size, cob->rotOrder);
 	}
 }
 
@@ -3036,7 +3049,7 @@
 				Mat4ToSize(ct->matrix, dvec);
 				break;
 			case 1: /* rotation (convert to degrees first) */
-				Mat4ToEul(ct->matrix, dvec);
+				Mat4ToEulO(ct->matrix, dvec, cob->rotOrder);
 				for (i=0; i<3; i++)
 					dvec[i] = (float)(dvec[i] / M_PI * 180);
 				break;
@@ -3047,7 +3060,7 @@
 		
 		/* extract components of owner's matrix */
 		VECCOPY(loc, cob->matrix[3]);
-		Mat4ToEul(cob->matrix, eul);
+		Mat4ToEulO(cob->matrix, eul, cob->rotOrder);
 		Mat4ToSize(cob->matrix, size);	
 		
 		/* determine where in range current transforms lie */
@@ -3102,7 +3115,7 @@
 		}
 		
 		/* apply to matrix */
-		LocEulSizeToMat4(cob->matrix, loc, eul, size);
+		LocEulOSizeToMat4(cob->matrix, loc, eul, size, cob->rotOrder);
 	}
 }
 

Modified: branches/blender2.5/blender/source/blender/blenlib/BLI_arithb.h
===================================================================
--- branches/blender2.5/blender/source/blender/blenlib/BLI_arithb.h	2009-09-02 10:14:03 UTC (rev 22947)
+++ branches/blender2.5/blender/source/blender/blenlib/BLI_arithb.h	2009-09-02 10:45:11 UTC (rev 22948)
@@ -202,6 +202,8 @@
 void Mat4ToEulO(float Mat[4][4], float eul[3], short order);
 
 void Mat3ToCompatibleEulO(float mat[3][3], float eul[3], float oldrot[3], short order);
+
+void eulerO_rot(float beul[3], float ang, char axis, short order);
  
 /**
  * @section Euler conversion routines (Blender XYZ)
@@ -484,8 +486,9 @@
 
 void triatoquat(float *v1, float *v2, float *v3, float *quat);
 
-void LocEulSizeToMat4(float mat[][4], float loc[3], float eul[3], float size[3]);
-void LocQuatSizeToMat4(float mat[][4], float loc[3], float quat[4], float size[3]);
+void LocEulSizeToMat4(float mat[4][4], float loc[3], float eul[3], float size[3]);
+void LocEulOSizeToMat4(float mat[4][4], float loc[3], float eul[3], float size[3], short rotOrder);
+void LocQuatSizeToMat4(float mat[4][4], float loc[3], float quat[4], float size[3]);
 
 void tubemap(float x, float y, float z, float *u, float *v);
 void spheremap(float x, float y, float z, float *u, float *v);

Modified: branches/blender2.5/blender/source/blender/blenlib/intern/arithb.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenlib/intern/arithb.c	2009-09-02 10:14:03 UTC (rev 22947)
+++ branches/blender2.5/blender/source/blender/blenlib/intern/arithb.c	2009-09-02 10:45:11 UTC (rev 22948)
@@ -2825,7 +2825,6 @@
  * NOTE: since we start at 1 for the values, but arrays index from 0, 
  *		 there is -1 factor involved in this process...
  */
-// FIXME: what happens when invalid order given
 #define GET_ROTATIONORDER_INFO(order) (((order)>=1) ? &rotOrders[(order)-1] : &rotOrders[0])
 
 /* Construct quaternion from Euler angles (in radians). */
@@ -2936,6 +2935,7 @@
 	
 	/* for now, we'll just do this the slow way (i.e. copying matrices) */
 	Mat3CpyMat4(m, M);
+	Mat3Ortho(m);
 	Mat3ToEulO(m, e, order);
 }
 
@@ -2996,8 +2996,28 @@
 		VecCopyf(eul, eul1);
 }
 
+/* rotate the given euler by the given angle on the specified axis */
+// NOTE: is this safe to do with different axis orders?
+void eulerO_rot(float beul[3], float ang, char axis, short order)
+{
+	float eul[3], mat1[3][3], mat2[3][3], totmat[3][3];
+	
+	eul[0]= eul[1]= eul[2]= 0.0f;
+	if (axis=='x') 
+		eul[0]= ang;
+	else if (axis=='y') 
+		eul[1]= ang;
+	else 
+		eul[2]= ang;
+	
+	EulOToMat3(eul, order, mat1);
+	EulOToMat3(beul, order, mat2);
+	
+	Mat3MulMat3(totmat, mat2, mat1);
+	
+	Mat3ToEulO(totmat, beul, order);
+}
 
-
 /* ************ EULER (old XYZ) *************** */
 
 /* XYZ order */
@@ -4947,7 +4967,7 @@
 /* make a 4x4 matrix out of 3 transform components */
 /* matrices are made in the order: scale * rot * loc */
 // TODO: need to have a version that allows for rotation order...
-void LocEulSizeToMat4(float mat[][4], float loc[3], float eul[3], float size[3])
+void LocEulSizeToMat4(float mat[4][4], float loc[3], float eul[3], float size[3])
 {
 	float rmat[3][3], smat[3][3], tmat[3][3];
 	
@@ -4970,7 +4990,7 @@
 
 /* make a 4x4 matrix out of 3 transform components */
 /* matrices are made in the order: scale * rot * loc */
-void LocQuatSizeToMat4(float mat[][4], float loc[3], float quat[4], float size[3])
+void LocEulOSizeToMat4(float mat[4][4], float loc[3], float eul[3], float size[3], short rotOrder)
 {
 	float rmat[3][3], smat[3][3], tmat[3][3];
 	
@@ -4978,6 +4998,30 @@
 	Mat4One(mat);
 	
 	/* make rotation + scaling part */
+	EulOToMat3(eul, rotOrder, rmat);
+	SizeToMat3(size, smat);
+	Mat3MulMat3(tmat, rmat, smat);
+	
+	/* copy rot/scale part to output matrix*/
+	Mat4CpyMat3(mat, tmat);
+	
+	/* copy location to matrix */
+	mat[3][0] = loc[0];
+	mat[3][1] = loc[1];
+	mat[3][2] = loc[2];
+}
+
+
+/* make a 4x4 matrix out of 3 transform components */
+/* matrices are made in the order: scale * rot * loc */
+void LocQuatSizeToMat4(float mat[4][4], float loc[3], float quat[4], float size[3])
+{
+	float rmat[3][3], smat[3][3], tmat[3][3];
+	
+	/* initialise new matrix */
+	Mat4One(mat);
+	
+	/* make rotation + scaling part */
 	QuatToMat3(quat, rmat);
 	SizeToMat3(size, smat);
 	Mat3MulMat3(tmat, rmat, smat);

Modified: branches/blender2.5/blender/source/blender/makesdna/DNA_constraint_types.h
===================================================================

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list