Fix for negative scaling & Mirror menu in Object mode (CTRL+M)

Hope Martin likes this simple hack. :)

Also; added flag in constraint to denote whether its local or not. That
way its possible to:

- prevent local scale and rotate on multiple objects to change own position
- draw constraint lines cleaner
This commit is contained in:
2005-05-07 21:04:55 +00:00
parent 4a123c082f
commit d10862a9da
3 changed files with 36 additions and 8 deletions

View File

@@ -192,6 +192,7 @@ typedef struct TransInfo {
#define CON_AXIS2 8 #define CON_AXIS2 8
#define CON_SELECT 16 #define CON_SELECT 16
#define CON_NOFLIP 32 /* does not reorient vector to face viewport when on */ #define CON_NOFLIP 32 /* does not reorient vector to face viewport when on */
#define CON_LOCAL 64
/* transdata->flag */ /* transdata->flag */
#define TD_SELECTED 1 #define TD_SELECTED 1

View File

@@ -1004,6 +1004,28 @@ static void headerResize(TransInfo *t, float vec[3], char *str) {
} }
} }
#define SIGN(a) (a<-FLT_EPSILON?1:a>FLT_EPSILON?2:3)
#define VECSIGNFLIP(a, b) ((SIGN(a[0]) & SIGN(b[0]))==0 || (SIGN(a[1]) & SIGN(b[1]))==0 || (SIGN(a[2]) & SIGN(b[2]))==0)
/* smat is reference matrix, only scaled */
static void TransMat3ToSize( float mat[][3], float smat[][3], float *size)
{
float vec[3];
VecCopyf(vec, mat[0]);
size[0]= Normalise(vec);
VecCopyf(vec, mat[1]);
size[1]= Normalise(vec);
VecCopyf(vec, mat[2]);
size[2]= Normalise(vec);
/* first tried with dotproduct... but the sign flip is crucial */
if( VECSIGNFLIP(mat[0], smat[0]) ) size[0]= -size[0];
if( VECSIGNFLIP(mat[1], smat[1]) ) size[1]= -size[1];
if( VECSIGNFLIP(mat[2], smat[2]) ) size[2]= -size[2];
}
void ElementResize(TransInfo *t, TransData *td, float mat[3][3]) { void ElementResize(TransInfo *t, TransData *td, float mat[3][3]) {
float tmat[3][3], smat[3][3], center[3]; float tmat[3][3], smat[3][3], center[3];
float vec[3]; float vec[3];
@@ -1020,7 +1042,8 @@ void ElementResize(TransInfo *t, TransData *td, float mat[3][3]) {
t->con.applySize(t, td, tmat); t->con.applySize(t, td, tmat);
} }
if (G.vd->around == V3D_LOCAL) { /* local constraint shouldn't alter center */
if (G.vd->around == V3D_LOCAL || (t->con.mode & CON_LOCAL)) {
VECCOPY(center, td->center); VECCOPY(center, td->center);
} }
else { else {
@@ -1035,7 +1058,7 @@ void ElementResize(TransInfo *t, TransData *td, float mat[3][3]) {
// Reorient the size mat to fit the oriented object. // Reorient the size mat to fit the oriented object.
Mat3MulMat3(obsizemat, tmat, td->axismtx); Mat3MulMat3(obsizemat, tmat, td->axismtx);
//printmatrix3("obsizemat", obsizemat); //printmatrix3("obsizemat", obsizemat);
Mat3ToSize(obsizemat, fsize); TransMat3ToSize(obsizemat, td->axismtx, fsize);
//printvecf("fsize", fsize); //printvecf("fsize", fsize);
} }
else { else {
@@ -1373,7 +1396,7 @@ static void applyRotation(TransInfo *t, float angle, float axis[3])
int i; int i;
/* saving original center */ /* saving original center */
if (G.vd->around == V3D_LOCAL) { if (G.vd->around == V3D_LOCAL || (t->con.mode & CON_LOCAL)) {
VECCOPY(center, t->center); VECCOPY(center, t->center);
} }
@@ -1384,7 +1407,8 @@ static void applyRotation(TransInfo *t, float angle, float axis[3])
if (td->flag & TD_NOACTION) if (td->flag & TD_NOACTION)
break; break;
if (G.vd->around == V3D_LOCAL) { /* local constraint shouldn't alter center */
if (G.vd->around == V3D_LOCAL || (t->con.mode & CON_LOCAL)) {
VECCOPY(t->center, td->center); VECCOPY(t->center, td->center);
} }
@@ -1400,7 +1424,7 @@ static void applyRotation(TransInfo *t, float angle, float axis[3])
} }
/* restoring original center */ /* restoring original center */
if (G.vd->around == V3D_LOCAL) { if (G.vd->around == V3D_LOCAL || (t->con.mode & CON_LOCAL)) {
VECCOPY(t->center, center); VECCOPY(t->center, center);
} }
} }

View File

@@ -472,6 +472,7 @@ static void drawObjectConstraint(TransInfo *t) {
int i; int i;
TransData * td = t->data; TransData * td = t->data;
/* cannot find any reason for drawing first constraint this way... (ton)
if (t->con.mode & CON_AXIS0) { if (t->con.mode & CON_AXIS0) {
drawLine(td->ob->obmat[3], td->axismtx[0], 'x', DRAWLIGHT); drawLine(td->ob->obmat[3], td->axismtx[0], 'x', DRAWLIGHT);
} }
@@ -481,9 +482,10 @@ static void drawObjectConstraint(TransInfo *t) {
if (t->con.mode & CON_AXIS2) { if (t->con.mode & CON_AXIS2) {
drawLine(td->ob->obmat[3], td->axismtx[2], 'z', DRAWLIGHT); drawLine(td->ob->obmat[3], td->axismtx[2], 'z', DRAWLIGHT);
} }
td++; td++;
for(i=1;i<t->total;i++,td++) { */
for(i=0;i<t->total;i++,td++) {
if (t->con.mode & CON_AXIS0) { if (t->con.mode & CON_AXIS0) {
drawLine(td->ob->obmat[3], td->axismtx[0], 'x', 0); drawLine(td->ob->obmat[3], td->axismtx[0], 'x', 0);
} }
@@ -535,6 +537,7 @@ void setConstraint(TransInfo *t, float space[3][3], int mode, const char text[])
startConstraint(t); startConstraint(t);
t->con.drawExtra = NULL;
t->con.applyVec = applyAxisConstraintVec; t->con.applyVec = applyAxisConstraintVec;
t->con.applySize = applyAxisConstraintSize; t->con.applySize = applyAxisConstraintSize;
t->con.applyRot = applyAxisConstraintRot; t->con.applyRot = applyAxisConstraintRot;
@@ -590,7 +593,7 @@ void setLocalConstraint(TransInfo *t, int mode, const char text[]) {
else { else {
strncpy(t->con.text + 1, text, 48); strncpy(t->con.text + 1, text, 48);
Mat3CpyMat3(t->con.mtx, t->data->axismtx); Mat3CpyMat3(t->con.mtx, t->data->axismtx);
t->con.mode = mode; t->con.mode = mode|CON_LOCAL;
getConstraintMatrix(t); getConstraintMatrix(t);
startConstraint(t); startConstraint(t);