Few cleanup in matrix mathutils (make mul_m3_m3m4 and mul_m4_m3m4 consistant with other similar funcs, mainly copy-safe [i.e. you can use the same matrix as operand and result, saves lines in some already over-complicated code!]).
This commit is contained in:
@@ -1030,7 +1030,6 @@ static void trackto_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *tar
|
||||
if (VALID_CONS_TARGET(ct)) {
|
||||
float size[3], vec[3];
|
||||
float totmat[3][3];
|
||||
float tmat[4][4];
|
||||
|
||||
/* Get size property, since ob->size is only the object's own relative size, not its global one */
|
||||
mat4_to_size(size, cob->matrix);
|
||||
@@ -1053,9 +1052,8 @@ static void trackto_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *tar
|
||||
vectomat(vec, ct->matrix[2],
|
||||
(short)data->reserved1, (short)data->reserved2,
|
||||
data->flags, totmat);
|
||||
|
||||
copy_m4_m4(tmat, cob->matrix);
|
||||
mul_m4_m3m4(cob->matrix, totmat, tmat);
|
||||
|
||||
mul_m4_m3m4(cob->matrix, totmat, cob->matrix);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2281,7 +2279,6 @@ static void locktrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *t
|
||||
float totmat[3][3];
|
||||
float tmpmat[3][3];
|
||||
float invmat[3][3];
|
||||
float tmat[4][4];
|
||||
float mdet;
|
||||
|
||||
/* Vector object -> target */
|
||||
@@ -2509,8 +2506,6 @@ static void locktrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *t
|
||||
totmat[1][0] = tmpmat[1][0]; totmat[1][1] = tmpmat[1][1]; totmat[1][2] = tmpmat[1][2];
|
||||
totmat[2][0] = tmpmat[2][0]; totmat[2][1] = tmpmat[2][1]; totmat[2][2] = tmpmat[2][2];
|
||||
|
||||
copy_m4_m4(tmat, cob->matrix);
|
||||
|
||||
mdet = determinant_m3(totmat[0][0], totmat[0][1], totmat[0][2],
|
||||
totmat[1][0], totmat[1][1], totmat[1][2],
|
||||
totmat[2][0], totmat[2][1], totmat[2][2]);
|
||||
@@ -2519,7 +2514,7 @@ static void locktrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *t
|
||||
}
|
||||
|
||||
/* apply out transformaton to the object */
|
||||
mul_m4_m3m4(cob->matrix, totmat, tmat);
|
||||
mul_m4_m3m4(cob->matrix, totmat, cob->matrix);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2717,7 +2712,6 @@ static void stretchto_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *t
|
||||
if (VALID_CONS_TARGET(ct)) {
|
||||
float size[3], scale[3], vec[3], xx[3], zz[3], orth[3];
|
||||
float totmat[3][3];
|
||||
float tmat[4][4];
|
||||
float dist;
|
||||
|
||||
/* store scaling before destroying obmat */
|
||||
@@ -2815,9 +2809,8 @@ static void stretchto_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *t
|
||||
normalize_v3_v3(totmat[2], zz);
|
||||
break;
|
||||
} /* switch (data->plane) */
|
||||
|
||||
copy_m4_m4(tmat, cob->matrix);
|
||||
mul_m4_m3m4(cob->matrix, totmat, tmat);
|
||||
|
||||
mul_m4_m3m4(cob->matrix, totmat, cob->matrix);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -195,7 +195,7 @@ void mul_m3_m3m3(float m1[][3], float m3_[][3], float m2_[][3])
|
||||
m1[2][2] = m2[2][0] * m3[0][2] + m2[2][1] * m3[1][2] + m2[2][2] * m3[2][2];
|
||||
}
|
||||
|
||||
void mul_m4_m4m3(float (*m1)[4], float (*m3_)[4], float (*m2_)[3])
|
||||
void mul_m4_m4m3(float m1[][4], float m3_[][4], float m2_[][3])
|
||||
{
|
||||
float m2[3][3], m3[4][4];
|
||||
|
||||
@@ -215,8 +215,14 @@ void mul_m4_m4m3(float (*m1)[4], float (*m3_)[4], float (*m2_)[3])
|
||||
}
|
||||
|
||||
/* m1 = m2 * m3, ignore the elements on the 4th row/column of m3 */
|
||||
void mult_m3_m3m4(float m1[][3], float m3[][4], float m2[][3])
|
||||
void mult_m3_m3m4(float m1[][3], float m3_[][4], float m2_[][3])
|
||||
{
|
||||
float m2[3][3], m3[4][4];
|
||||
|
||||
/* copy so it works when m1 is the same pointer as m2 or m3 */
|
||||
copy_m3_m3(m2, m2_);
|
||||
copy_m4_m4(m3, m3_);
|
||||
|
||||
/* m1[i][j] = m2[i][k] * m3[k][j] */
|
||||
m1[0][0] = m2[0][0] * m3[0][0] + m2[0][1] * m3[1][0] + m2[0][2] * m3[2][0];
|
||||
m1[0][1] = m2[0][0] * m3[0][1] + m2[0][1] * m3[1][1] + m2[0][2] * m3[2][1];
|
||||
@@ -231,8 +237,14 @@ void mult_m3_m3m4(float m1[][3], float m3[][4], float m2[][3])
|
||||
m1[2][2] = m2[2][0] * m3[0][2] + m2[2][1] * m3[1][2] + m2[2][2] * m3[2][2];
|
||||
}
|
||||
|
||||
void mul_m4_m3m4(float (*m1)[4], float (*m3)[3], float (*m2)[4])
|
||||
void mul_m4_m3m4(float m1[][4], float m3_[][3], float m2_[][4])
|
||||
{
|
||||
float m2[4][4], m3[3][3];
|
||||
|
||||
/* copy so it works when m1 is the same pointer as m2 or m3 */
|
||||
copy_m4_m4(m2, m2_);
|
||||
copy_m3_m3(m3, m3_);
|
||||
|
||||
m1[0][0] = m2[0][0] * m3[0][0] + m2[0][1] * m3[1][0] + m2[0][2] * m3[2][0];
|
||||
m1[0][1] = m2[0][0] * m3[0][1] + m2[0][1] * m3[1][1] + m2[0][2] * m3[2][1];
|
||||
m1[0][2] = m2[0][0] * m3[0][2] + m2[0][1] * m3[1][2] + m2[0][2] * m3[2][2];
|
||||
|
||||
@@ -2195,7 +2195,6 @@ static void constraintTransLim(TransInfo *t, TransData *td)
|
||||
for (con = td->con; con; con = con->next) {
|
||||
bConstraintTypeInfo *cti = NULL;
|
||||
ListBase targets = {NULL, NULL};
|
||||
float tmat[4][4];
|
||||
|
||||
/* only consider constraint if enabled */
|
||||
if (con->flag & CONSTRAINT_DISABLE) continue;
|
||||
@@ -2221,8 +2220,7 @@ static void constraintTransLim(TransInfo *t, TransData *td)
|
||||
/* do space conversions */
|
||||
if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
|
||||
/* just multiply by td->mtx (this should be ok) */
|
||||
copy_m4_m4(tmat, cob.matrix);
|
||||
mul_m4_m3m4(cob.matrix, td->mtx, tmat);
|
||||
mul_m4_m3m4(cob.matrix, td->mtx, cob.matrix);
|
||||
}
|
||||
else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) {
|
||||
/* skip... incompatable spacetype */
|
||||
@@ -2237,9 +2235,8 @@ static void constraintTransLim(TransInfo *t, TransData *td)
|
||||
|
||||
/* convert spaces again */
|
||||
if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
|
||||
/* just multiply by td->mtx (this should be ok) */
|
||||
copy_m4_m4(tmat, cob.matrix);
|
||||
mul_m4_m3m4(cob.matrix, td->smtx, tmat);
|
||||
/* just multiply by td->smtx (this should be ok) */
|
||||
mul_m4_m3m4(cob.matrix, td->smtx, cob.matrix);
|
||||
}
|
||||
|
||||
/* free targets list */
|
||||
@@ -2287,18 +2284,17 @@ static void constraintRotLim(TransInfo *UNUSED(t), TransData *td)
|
||||
bConstraintOb cob;
|
||||
bConstraint *con;
|
||||
int do_limit = FALSE;
|
||||
|
||||
|
||||
/* Evaluate valid constraints */
|
||||
for (con = td->con; con; con = con->next) {
|
||||
/* only consider constraint if enabled */
|
||||
if (con->flag & CONSTRAINT_DISABLE) continue;
|
||||
if (con->enforce == 0.0f) continue;
|
||||
|
||||
|
||||
/* we're only interested in Limit-Rotation constraints */
|
||||
if (con->type == CONSTRAINT_TYPE_ROTLIMIT) {
|
||||
bRotLimitConstraint *data = con->data;
|
||||
float tmat[4][4];
|
||||
|
||||
|
||||
/* only use it if it's tagged for this purpose */
|
||||
if ((data->flag2 & LIMIT_TRANSFORM) == 0)
|
||||
continue;
|
||||
@@ -2312,12 +2308,11 @@ static void constraintRotLim(TransInfo *UNUSED(t), TransData *td)
|
||||
constraintob_from_transdata(&cob, td);
|
||||
do_limit = TRUE;
|
||||
}
|
||||
|
||||
|
||||
/* do space conversions */
|
||||
if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
|
||||
/* just multiply by td->mtx (this should be ok) */
|
||||
copy_m4_m4(tmat, cob.matrix);
|
||||
mul_m4_m3m4(cob.matrix, td->mtx, tmat);
|
||||
mul_m4_m3m4(cob.matrix, td->mtx, cob.matrix);
|
||||
}
|
||||
|
||||
/* do constraint */
|
||||
@@ -2325,9 +2320,8 @@ static void constraintRotLim(TransInfo *UNUSED(t), TransData *td)
|
||||
|
||||
/* convert spaces again */
|
||||
if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
|
||||
/* just multiply by td->mtx (this should be ok) */
|
||||
copy_m4_m4(tmat, cob.matrix);
|
||||
mul_m4_m3m4(cob.matrix, td->smtx, tmat);
|
||||
/* just multiply by td->smtx (this should be ok) */
|
||||
mul_m4_m3m4(cob.matrix, td->smtx, cob.matrix);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2382,7 +2376,6 @@ static void constraintSizeLim(TransInfo *t, TransData *td)
|
||||
/* we're only interested in Limit-Scale constraints */
|
||||
if (con->type == CONSTRAINT_TYPE_SIZELIMIT) {
|
||||
bSizeLimitConstraint *data = con->data;
|
||||
float tmat[4][4];
|
||||
|
||||
/* only use it if it's tagged for this purpose */
|
||||
if ((data->flag2 & LIMIT_TRANSFORM) == 0)
|
||||
@@ -2391,11 +2384,10 @@ static void constraintSizeLim(TransInfo *t, TransData *td)
|
||||
/* do space conversions */
|
||||
if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
|
||||
/* just multiply by td->mtx (this should be ok) */
|
||||
copy_m4_m4(tmat, cob.matrix);
|
||||
mul_m4_m3m4(cob.matrix, td->mtx, tmat);
|
||||
mul_m4_m3m4(cob.matrix, td->mtx, cob.matrix);
|
||||
}
|
||||
else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) {
|
||||
/* skip... incompatable spacetype */
|
||||
/* skip... incompatible spacetype */
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -2404,13 +2396,12 @@ static void constraintSizeLim(TransInfo *t, TransData *td)
|
||||
|
||||
/* convert spaces again */
|
||||
if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
|
||||
/* just multiply by td->mtx (this should be ok) */
|
||||
copy_m4_m4(tmat, cob.matrix);
|
||||
mul_m4_m3m4(cob.matrix, td->smtx, tmat);
|
||||
/* just multiply by td->smtx (this should be ok) */
|
||||
mul_m4_m3m4(cob.matrix, td->smtx, cob.matrix);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* copy results from cob->matrix */
|
||||
if ((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)) {
|
||||
/* scale val and reset size */
|
||||
@@ -2420,7 +2411,7 @@ static void constraintSizeLim(TransInfo *t, TransData *td)
|
||||
/* Reset val if SINGLESIZE but using a constraint */
|
||||
if (td->flag & TD_SINGLESIZE)
|
||||
return;
|
||||
|
||||
|
||||
mat4_to_size(td->ext->size, cob.matrix);
|
||||
}
|
||||
}
|
||||
@@ -2852,11 +2843,11 @@ static void ElementResize(TransInfo *t, TransData *td, float mat[3][3])
|
||||
|
||||
if (t->flag & (T_OBJECT | T_TEXTURE | T_POSE)) {
|
||||
float obsizemat[3][3];
|
||||
// Reorient the size mat to fit the oriented object.
|
||||
/* Reorient the size mat to fit the oriented object. */
|
||||
mul_m3_m3m3(obsizemat, tmat, td->axismtx);
|
||||
//print_m3("obsizemat", obsizemat);
|
||||
/* print_m3("obsizemat", obsizemat); */
|
||||
TransMat3ToSize(obsizemat, td->axismtx, fsize);
|
||||
//print_v3("fsize", fsize);
|
||||
/* print_v3("fsize", fsize); */
|
||||
}
|
||||
else {
|
||||
mat3_to_size(fsize, tmat);
|
||||
@@ -2864,7 +2855,7 @@ static void ElementResize(TransInfo *t, TransData *td, float mat[3][3])
|
||||
|
||||
protectedSizeBits(td->protectflag, fsize);
|
||||
|
||||
if ((t->flag & T_V3D_ALIGN) == 0) { // align mode doesn't resize objects itself
|
||||
if ((t->flag & T_V3D_ALIGN) == 0) { /* align mode doesn't resize objects itself */
|
||||
if ((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)) {
|
||||
/* scale val and reset size */
|
||||
*td->val = td->ival * (1 + (fsize[0] - 1) * td->factor);
|
||||
|
||||
Reference in New Issue
Block a user