Transform fixes
Connected PET for mesh had an infinite loop in some case. Fixed an made a bit faster. Renamed the numinput flag. Corrected a conflict in TransInfo flags. This was a crash waiting to happen. NO_CONSTRAINT flag now correctly used to disable MMB and constraint hotkeys when needed. Added check for the manipulator flag when drawing them before applying transformation matrix. Was really weird when doing MMB with rotation.
This commit is contained in:
@@ -788,7 +788,7 @@ static void editmesh_set_connectivity_distance(int total, float *vectors, EditVe
|
||||
eve->vn = (EditVert *)(i);
|
||||
|
||||
if(eve->f & SELECT) {
|
||||
eve->f2= 1;
|
||||
eve->f2= 2;
|
||||
E_NEAR(eve) = eve;
|
||||
E_VEC(eve)[0] = 0.0f;
|
||||
E_VEC(eve)[1] = 0.0f;
|
||||
@@ -816,13 +816,17 @@ static void editmesh_set_connectivity_distance(int total, float *vectors, EditVe
|
||||
float *vec2 = E_VEC(v2);
|
||||
float *vec1 = E_VEC(v1);
|
||||
|
||||
if (v1->f2 + v2->f2 == 4)
|
||||
continue;
|
||||
|
||||
if (v1->f2) {
|
||||
if (v2->f2) {
|
||||
float nvec[3];
|
||||
float len1 = VecLength(vec1);
|
||||
float len2 = VecLength(vec2);
|
||||
float lenn;
|
||||
/* for v2 */
|
||||
/* for v2 if not selected */
|
||||
if (v2->f2 != 2) {
|
||||
VecSubf(nvec, v2->co, E_NEAR(v1)->co);
|
||||
lenn = VecLength(nvec);
|
||||
if (lenn - len1 > 0.00001f && len2 - lenn > 0.00001f) {
|
||||
@@ -830,14 +834,18 @@ static void editmesh_set_connectivity_distance(int total, float *vectors, EditVe
|
||||
E_NEAR(v2) = E_NEAR(v1);
|
||||
done = 1;
|
||||
}
|
||||
/* for v1 */
|
||||
}
|
||||
/* for v1 if not selected */
|
||||
if (v1->f2 != 2) {
|
||||
VecSubf(nvec, v1->co, E_NEAR(v2)->co);
|
||||
lenn = VecLength(nvec);
|
||||
if (lenn - len2 > 0.00001f && len1 - lenn > 0.00001f) {
|
||||
VECCOPY(vec1, nvec);
|
||||
E_NEAR(v1) = E_NEAR(v2);
|
||||
done = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
v2->f2 = 1;
|
||||
VecSubf(vec2, v2->co, E_NEAR(v1)->co);
|
||||
@@ -1504,10 +1512,10 @@ void Transform(int mode, int context)
|
||||
|
||||
Trans.context = context;
|
||||
|
||||
initTransModeFlags(&Trans, mode); // modal settings in struct Trans
|
||||
|
||||
initTrans(&Trans); // internal data, mouse, vectors
|
||||
|
||||
initTransModeFlags(&Trans, mode); // modal settings in struct Trans
|
||||
|
||||
createTransData(&Trans); // make TransData structs from selection
|
||||
|
||||
if (Trans.total == 0)
|
||||
@@ -1599,6 +1607,7 @@ void Transform(int mode, int context)
|
||||
break;
|
||||
|
||||
case MIDDLEMOUSE:
|
||||
if ((Trans.flag & T_NO_CONSTRAINT)==0) {
|
||||
/* exception for switching to dolly, or trackball, in camera view */
|
||||
if (Trans.flag & T_CAMERA) {
|
||||
if (Trans.mode==TFM_TRANSLATION)
|
||||
@@ -1611,6 +1620,7 @@ void Transform(int mode, int context)
|
||||
}
|
||||
else
|
||||
initSelectConstraint(&Trans);
|
||||
}
|
||||
Trans.redraw = 1;
|
||||
break;
|
||||
case ESCKEY:
|
||||
@@ -1649,6 +1659,7 @@ void Transform(int mode, int context)
|
||||
Trans.redraw = 1;
|
||||
break;
|
||||
case XKEY:
|
||||
if ((Trans.flag & T_NO_CONSTRAINT)==0) {
|
||||
if (cmode == 'X') {
|
||||
stopConstraint(&Trans);
|
||||
cmode = '\0';
|
||||
@@ -1670,8 +1681,10 @@ void Transform(int mode, int context)
|
||||
cmode = 'x';
|
||||
}
|
||||
Trans.redraw = 1;
|
||||
}
|
||||
break;
|
||||
case YKEY:
|
||||
if ((Trans.flag & T_NO_CONSTRAINT)==0) {
|
||||
if (cmode == 'Y') {
|
||||
stopConstraint(&Trans);
|
||||
cmode = '\0';
|
||||
@@ -1693,8 +1706,10 @@ void Transform(int mode, int context)
|
||||
cmode = 'y';
|
||||
}
|
||||
Trans.redraw = 1;
|
||||
}
|
||||
break;
|
||||
case ZKEY:
|
||||
if ((Trans.flag & T_NO_CONSTRAINT)==0) {
|
||||
if (cmode == 'Z') {
|
||||
stopConstraint(&Trans);
|
||||
cmode = '\0';
|
||||
@@ -1716,6 +1731,7 @@ void Transform(int mode, int context)
|
||||
cmode = 'z';
|
||||
}
|
||||
Trans.redraw = 1;
|
||||
}
|
||||
break;
|
||||
case OKEY:
|
||||
if (G.qual==LR_SHIFTKEY) {
|
||||
@@ -1750,8 +1766,10 @@ void Transform(int mode, int context)
|
||||
/* no redraw on release modifier keys! this makes sure you can assign the 'grid' still
|
||||
after releasing modifer key */
|
||||
case MIDDLEMOUSE:
|
||||
if ((Trans.flag & T_NO_CONSTRAINT)==0) {
|
||||
postSelectConstraint(&Trans);
|
||||
Trans.redraw = 1;
|
||||
}
|
||||
break;
|
||||
case LEFTMOUSE:
|
||||
case RIGHTMOUSE:
|
||||
@@ -1821,9 +1839,10 @@ void ManipulatorTransform(int mode)
|
||||
|
||||
Trans.context = CTX_NONE;
|
||||
|
||||
initTrans(&Trans); // internal data, mouse, vectors
|
||||
|
||||
initTransModeFlags(&Trans, mode); // modal settings in struct Trans
|
||||
|
||||
initTrans(&Trans); // internal data, mouse, vectors
|
||||
G.moving |= G_TRANSFORM_MANIP; // signal to draw manipuls while transform
|
||||
createTransData(&Trans); // make TransData structs from selection
|
||||
|
||||
@@ -3063,3 +3082,72 @@ int Tilt(TransInfo *t, short mval[2])
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* ************************** PUSH/PULL *************************** */
|
||||
|
||||
void initPushPull(TransInfo *t)
|
||||
{
|
||||
t->idx_max = 0;
|
||||
t->num.idx_max = 0;
|
||||
t->snap[0] = 0.0f;
|
||||
t->snap[1] = 1.0f;
|
||||
t->snap[2] = t->snap[1] * 0.1f;
|
||||
t->transform = ShrinkFatten;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int PushPull(TransInfo *t, short mval[2])
|
||||
{
|
||||
float vec[3];
|
||||
float distance;
|
||||
int i;
|
||||
char str[50];
|
||||
TransData *td = t->data;
|
||||
|
||||
window_to_3d(t->vec, (short)(mval[0] - t->imval[0]), (short)(mval[1] - t->imval[1]));
|
||||
Projf(vec, t->vec, G.vd->viewinv[1]);
|
||||
distance = Inpf(t->viewinv[1], vec) * 2.0f;
|
||||
|
||||
snapGrid(t, &distance);
|
||||
|
||||
applyNumInput(&t->num, &distance);
|
||||
|
||||
/* header print for NumInput */
|
||||
if (hasNumInput(&t->num)) {
|
||||
char c[20];
|
||||
|
||||
outputNumInput(&(t->num), c);
|
||||
|
||||
sprintf(str, "Push/Pull: %s%s %s", c, t->con.text, t->proptext);
|
||||
}
|
||||
else {
|
||||
/* default header print */
|
||||
sprintf(str, "Push/Pull: %.4f%s %s", distance, t->con.text, t->proptext);
|
||||
}
|
||||
|
||||
|
||||
for(i = 0 ; i < t->total; i++, td++) {
|
||||
if (td->flag & TD_NOACTION)
|
||||
break;
|
||||
|
||||
VecSubf(vec, t->center, td->center);
|
||||
if (t->con.applyRot) {
|
||||
float axis[3];
|
||||
t->con.applyRot(t, td, axis);
|
||||
Projf(vec, vec, axis);
|
||||
}
|
||||
Normalise(vec);
|
||||
VecMulf(vec, distance);
|
||||
VecMulf(vec, td->factor);
|
||||
|
||||
VecAddf(td->loc, td->iloc, vec);
|
||||
}
|
||||
|
||||
recalcData(t);
|
||||
|
||||
headerprint(str);
|
||||
|
||||
force_draw(0);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -140,13 +140,12 @@ typedef struct TransInfo {
|
||||
|
||||
/* ******************** Macros & Prototypes *********************** */
|
||||
|
||||
/* MODE AND NUMINPUT FLAGS */
|
||||
#define NOCONSTRAINT 1
|
||||
#define NULLONE 2
|
||||
#define NONEGATIVE 4
|
||||
#define NOZERO 8
|
||||
#define NOFRACTION 16
|
||||
#define AFFECTALL 32
|
||||
/* NUMINPUT FLAGS */
|
||||
#define NUM_NULL_ONE 2
|
||||
#define NUM_NO_NEGATIVE 4
|
||||
#define NUM_NO_ZERO 8
|
||||
#define NUM_NO_FRACTION 16
|
||||
#define NUM_AFFECT_ALL 32
|
||||
|
||||
/* transinfo->flag */
|
||||
#define T_OBJECT 1
|
||||
@@ -159,6 +158,12 @@ typedef struct TransInfo {
|
||||
// for manipulator exceptions, like scaling using center point, drawing help lines
|
||||
#define T_USES_MANIPULATOR 128
|
||||
|
||||
/* restrictions flags */
|
||||
#define T_ALL_RESTRICTIONS (256|512|1024)
|
||||
#define T_NO_CONSTRAINT 256
|
||||
#define T_NULL_ONE 512
|
||||
#define T_NO_ZERO 1024
|
||||
|
||||
|
||||
/* transinfo->con->mode */
|
||||
#define CON_APPLY 1
|
||||
|
||||
@@ -116,7 +116,7 @@ void getConstraintMatrix(TransInfo *t);
|
||||
void constraintNumInput(TransInfo *t, float vec[3])
|
||||
{
|
||||
int mode = t->con.mode;
|
||||
float nval = (t->num.flag & NULLONE)?1.0f:0.0f;
|
||||
float nval = (t->flag & T_NULL_ONE)?1.0f:0.0f;
|
||||
|
||||
if (getConstraintSpaceDimension(t) == 2) {
|
||||
if (mode & (CON_AXIS0|CON_AXIS1)) {
|
||||
@@ -157,7 +157,7 @@ static void postConstraintChecks(TransInfo *t, float vec[3], float pvec[3]) {
|
||||
|
||||
snapGrid(t, vec);
|
||||
|
||||
if (t->num.flag & NULLONE) {
|
||||
if (t->num.flag & T_NULL_ONE) {
|
||||
if (!(t->con.mode & CON_AXIS0))
|
||||
vec[0] = 1.0f;
|
||||
|
||||
|
||||
@@ -314,25 +314,29 @@ void recalcData(TransInfo *t)
|
||||
|
||||
void initTransModeFlags(TransInfo *t, int mode)
|
||||
{
|
||||
t->num.flag = 0;
|
||||
t->mode = mode;
|
||||
t->num.flag = 0;
|
||||
|
||||
/* REMOVING RESTRICTIONS FLAGS */
|
||||
t->flag &= ~T_ALL_RESTRICTIONS;
|
||||
|
||||
switch (mode) {
|
||||
case TFM_RESIZE:
|
||||
t->num.flag |= NULLONE;
|
||||
t->num.flag |= AFFECTALL;
|
||||
t->flag |= T_NULL_ONE;
|
||||
t->num.flag |= NUM_NULL_ONE;
|
||||
t->num.flag |= NUM_AFFECT_ALL;
|
||||
if (!G.obedit) {
|
||||
t->flag |= NOZERO;
|
||||
t->num.flag |= NOZERO;
|
||||
t->flag |= T_NO_ZERO;
|
||||
t->num.flag |= NUM_NO_ZERO;
|
||||
}
|
||||
break;
|
||||
case TFM_TOSPHERE:
|
||||
t->num.flag |= NULLONE;
|
||||
t->num.flag |= NONEGATIVE;
|
||||
t->flag |= NOCONSTRAINT;
|
||||
t->num.flag |= NUM_NULL_ONE;
|
||||
t->num.flag |= NUM_NO_NEGATIVE;
|
||||
t->flag |= T_NO_CONSTRAINT;
|
||||
break;
|
||||
case TFM_SHEAR:
|
||||
t->flag |= NOCONSTRAINT;
|
||||
t->flag |= T_NO_CONSTRAINT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -381,8 +385,9 @@ void initTrans (TransInfo *t)
|
||||
t->data = NULL;
|
||||
t->ext = NULL;
|
||||
|
||||
getmouseco_areawin(t->imval);
|
||||
t->flag = 0;
|
||||
|
||||
getmouseco_areawin(t->imval);
|
||||
t->con.imval[0] = t->imval[0];
|
||||
t->con.imval[1] = t->imval[1];
|
||||
|
||||
|
||||
@@ -1177,7 +1177,9 @@ static void draw_manipulator_rotate_cyl(float mat[][4], int moving, int drawflag
|
||||
if(moving) {
|
||||
float matt[4][4];
|
||||
Mat4CpyMat4(matt, mat); // to copy the parts outside of [3][3]
|
||||
if (Trans.flag & T_USES_MANIPULATOR) {
|
||||
Mat4MulMat34(matt, Trans.mat, mat);
|
||||
}
|
||||
mymultmatrix(matt);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -66,7 +66,7 @@ void outputNumInput(NumInput *n, char *str)
|
||||
|
||||
for (j=0; j<=n->idx_max; j++) {
|
||||
/* if AFFECTALL and no number typed and cursor not on number, use first number */
|
||||
if (n->flag & AFFECTALL && n->idx != j && n->ctrl[j] == 0)
|
||||
if (n->flag & NUM_AFFECT_ALL && n->idx != j && n->ctrl[j] == 0)
|
||||
i = 0;
|
||||
else
|
||||
i = j;
|
||||
@@ -124,15 +124,15 @@ void applyNumInput(NumInput *n, float *vec)
|
||||
if (hasNumInput(n)) {
|
||||
for (j=0; j<=n->idx_max; j++) {
|
||||
/* if AFFECTALL and no number typed and cursor not on number, use first number */
|
||||
if (n->flag & AFFECTALL && n->idx != j && n->ctrl[j] == 0)
|
||||
if (n->flag & NUM_AFFECT_ALL && n->idx != j && n->ctrl[j] == 0)
|
||||
i = 0;
|
||||
else
|
||||
i = j;
|
||||
|
||||
if (n->ctrl[i] == 0 && n->flag & NULLONE) {
|
||||
if (n->ctrl[i] == 0 && n->flag & NUM_NULL_ONE) {
|
||||
vec[j] = 1.0f;
|
||||
}
|
||||
else if (n->val[i] == 0.0f && n->flag & NOZERO) {
|
||||
else if (n->val[i] == 0.0f && n->flag & NUM_NO_ZERO) {
|
||||
vec[j] = 0.0001f;
|
||||
}
|
||||
else {
|
||||
@@ -164,7 +164,7 @@ char handleNumInput(NumInput *n, unsigned short event)
|
||||
break;
|
||||
case PERIODKEY:
|
||||
case PADPERIOD:
|
||||
if (n->flag & NOFRACTION)
|
||||
if (n->flag & NUM_NO_FRACTION)
|
||||
break;
|
||||
|
||||
switch (n->ctrl[idx])
|
||||
@@ -178,7 +178,7 @@ char handleNumInput(NumInput *n, unsigned short event)
|
||||
}
|
||||
break;
|
||||
case MINUSKEY:
|
||||
if (n->flag & NONEGATIVE)
|
||||
if (n->flag & NUM_NO_NEGATIVE)
|
||||
break;
|
||||
|
||||
if (n->ctrl[idx]) {
|
||||
|
||||
Reference in New Issue
Block a user