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:
-rw-r--r--source/blender/blenkernel/BKE_constraint.h1
-rw-r--r--source/blender/blenkernel/intern/constraint.c43
-rw-r--r--source/blender/blenlib/BLI_arithb.h7
-rw-r--r--source/blender/blenlib/intern/arithb.c52
-rw-r--r--source/blender/makesdna/DNA_constraint_types.h2
5 files changed, 83 insertions, 22 deletions
diff --git a/source/blender/blenkernel/BKE_constraint.h b/source/blender/blenkernel/BKE_constraint.h
index 6e69906b71d..a0061173438 100644
--- a/source/blender/blenkernel/BKE_constraint.h
+++ b/source/blender/blenkernel/BKE_constraint.h
@@ -49,6 +49,7 @@ typedef struct bConstraintOb {
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;
/* ---------------------------------------------------------------------------- */
diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c
index 88e73a00ba7..e6e65ebd614 100644
--- a/source/blender/blenkernel/intern/constraint.c
+++ b/source/blender/blenkernel/intern/constraint.c
@@ -121,6 +121,7 @@ bConstraintOb *constraints_make_evalob (Scene *scene, Object *ob, void *subdata,
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 @@ bConstraintOb *constraints_make_evalob (Scene *scene, Object *ob, void *subdata,
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 @@ static void default_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstrain
* (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 @@ static void default_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstrain
* (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 @@ static void childof_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *ta
/* 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 @@ static void childof_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *ta
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 @@ static void rotlimit_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *t
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 @@ static void rotlimit_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *t
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 @@ static void rotlike_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *ta
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 @@ static void rotlike_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *ta
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 @@ static void rotlike_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *ta
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 @@ static void transform_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *
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 @@ static void transform_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *
/* 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 @@ static void transform_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *
}
/* apply to matrix */
- LocEulSizeToMat4(cob->matrix, loc, eul, size);
+ LocEulOSizeToMat4(cob->matrix, loc, eul, size, cob->rotOrder);
}
}
diff --git a/source/blender/blenlib/BLI_arithb.h b/source/blender/blenlib/BLI_arithb.h
index 5f3622e8aa5..2ab60c6a8d0 100644
--- a/source/blender/blenlib/BLI_arithb.h
+++ b/source/blender/blenlib/BLI_arithb.h
@@ -202,6 +202,8 @@ void Mat3ToEulO(float Mat[3][3], float eul[3], short order);
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 Mat4ToSize(float mat[][4], float *size);
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);
diff --git a/source/blender/blenlib/intern/arithb.c b/source/blender/blenlib/intern/arithb.c
index 64fb7d78ef1..9d67ac50108 100644
--- a/source/blender/blenlib/intern/arithb.c
+++ b/source/blender/blenlib/intern/arithb.c
@@ -2825,7 +2825,6 @@ static RotOrderInfo rotOrders[]= {
* 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 @@ void Mat4ToEulO(float M[4][4], float e[3], short order)
/* for now, we'll just do this the slow way (i.e. copying matrices) */
Mat3CpyMat4(m, M);
+ Mat3Ortho(m);
Mat3ToEulO(m, e, order);
}
@@ -2996,7 +2996,27 @@ void Mat3ToCompatibleEulO(float mat[3][3], float eul[3], float oldrot[3], short
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) *************** */
@@ -4947,7 +4967,7 @@ float PdistVL3Dfl(float *v1, float *v2, float *v3)
/* 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,31 @@ void LocEulSizeToMat4(float mat[][4], float loc[3], float eul[3], float size[3])
/* 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];
+
+ /* initialise new matrix */
+ 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];
diff --git a/source/blender/makesdna/DNA_constraint_types.h b/source/blender/makesdna/DNA_constraint_types.h
index 79f032d0d21..6fab633b192 100644
--- a/source/blender/makesdna/DNA_constraint_types.h
+++ b/source/blender/makesdna/DNA_constraint_types.h
@@ -85,7 +85,7 @@ typedef struct bConstraintTarget {
short space; /* space that target should be evaluated in (overrides bConstraint->tarspace) */
short flag; /* runtime settings (for editor, etc.) */
short type; /* type of target (B_CONSTRAINT_OB_TYPE) */
- short pad;
+ short rotOrder; /* rotation order for target (as defined in BLI_arithb.h) */
} bConstraintTarget;
/* bConstraintTarget -> flag */