Local axis constraint started.

Works with edit data and in object mode with single selections (only one object selected).

Also started adding constraint stuff in headerprints. Only for Translation for now.

Pressing X,Y,Z (and the Ctrl versions) toggle between global, local and off like it used to do.
This commit is contained in:
2005-03-07 02:21:04 +00:00
parent b3b96acc73
commit 7b081fe3b7
4 changed files with 115 additions and 37 deletions

View File

@@ -1196,6 +1196,7 @@ void Transform(int mode)
short pmval[2] = {0, 0}, mval[2], val;
float mati[3][3];
unsigned short event;
char cmode = '\0';
/*joeedh -> hopefully may be what makes the old transform() constant*/
/* ton: I doubt, but it doesnt harm for now. shouldnt be needed though */
@@ -1313,24 +1314,72 @@ void Transform(int mode)
restoreTransObjects(&Trans);
break;
case XKEY:
if (cmode == 'X') {
Trans.con.mode &= ~CON_APPLY;
cmode = '\0';
}
else if(cmode == 'x') {
if (G.qual == 0)
setConstraint(&Trans, mati, (CON_APPLY|CON_AXIS0));
setLocalConstraint(&Trans, (CON_APPLY|CON_AXIS0), "along local X");
else if (G.qual == LR_CTRLKEY)
setConstraint(&Trans, mati, (CON_APPLY|CON_AXIS1|CON_AXIS2));
break;
setLocalConstraint(&Trans, (CON_APPLY|CON_AXIS1|CON_AXIS2), "locking local X");
cmode = 'X';
}
else {
if (G.qual == 0)
setConstraint(&Trans, mati, (CON_APPLY|CON_AXIS0), "along global X");
else if (G.qual == LR_CTRLKEY)
setConstraint(&Trans, mati, (CON_APPLY|CON_AXIS1|CON_AXIS2), "locking global X");
cmode = 'x';
}
Trans.redraw = 1;
break;
case YKEY:
if (cmode == 'Y') {
Trans.con.mode &= ~CON_APPLY;
cmode = '\0';
}
else if(cmode == 'y') {
if (G.qual == 0)
setConstraint(&Trans, mati, (CON_APPLY|CON_AXIS1));
setLocalConstraint(&Trans, (CON_APPLY|CON_AXIS1), "along global Y");
else if (G.qual == LR_CTRLKEY)
setConstraint(&Trans, mati, (CON_APPLY|CON_AXIS0|CON_AXIS2));
break;
setLocalConstraint(&Trans, (CON_APPLY|CON_AXIS0|CON_AXIS2), "locking global Y");
cmode = 'Y';
}
else {
if (G.qual == 0)
setConstraint(&Trans, mati, (CON_APPLY|CON_AXIS1), "along local Y");
else if (G.qual == LR_CTRLKEY)
setConstraint(&Trans, mati, (CON_APPLY|CON_AXIS0|CON_AXIS2), "locking local Y");
cmode = 'y';
}
Trans.redraw = 1;
break;
case ZKEY:
if (cmode == 'Z') {
Trans.con.mode &= ~CON_APPLY;
cmode = '\0';
}
else if(cmode == 'z') {
if (G.qual == 0)
setConstraint(&Trans, mati, (CON_APPLY|CON_AXIS2));
setLocalConstraint(&Trans, (CON_APPLY|CON_AXIS2), "along local Z");
else if (G.qual == LR_CTRLKEY)
setConstraint(&Trans, mati, (CON_APPLY|CON_AXIS0|CON_AXIS1));
setLocalConstraint(&Trans, (CON_APPLY|CON_AXIS0|CON_AXIS1), "locking local Z");
cmode = 'Z';
}
else {
if (G.qual == 0)
setConstraint(&Trans, mati, (CON_APPLY|CON_AXIS2), "along global Z");
else if (G.qual == LR_CTRLKEY)
setConstraint(&Trans, mati, (CON_APPLY|CON_AXIS0|CON_AXIS1), "locking global Z");
cmode = 'z';
}
Trans.redraw = 1;
break;
case OKEY:
@@ -1395,7 +1444,7 @@ void Transform(int mode)
if(mode==TFM_RESIZE) cmode= 's';
else if(mode==TFM_ROTATION) cmode= 'r';
/* aftertrans does displists, ipos and action channels */
special_aftertrans_update(cmode, 0, ret_val == TRANS_CANCEL, 0 /*keyflags*/);
special_aftertrans_update(cmode, 0, (short)(ret_val == TRANS_CANCEL), 0 /*keyflags*/);
if(G.obedit==NULL && G.obpose==NULL)
clear_trans_object_base_flags();
@@ -1965,7 +2014,7 @@ int Translation(TransInfo *t, short mval[2])
{
float vec[3], tvec[3];
int i;
char str[70];
char str[200];
TransData *td = t->data;
window_to_3d(vec, (short)(mval[0] - t->imval[0]), (short)(mval[1] - t->imval[1]));
@@ -1985,10 +2034,16 @@ int Translation(TransInfo *t, short mval[2])
outputNumInput(&(t->num), c);
if (t->con.mode & CON_APPLY)
sprintf(str, "Dx: %s Dy: %s Dz: %s %s %s", &c[0], &c[20], &c[40], t->con.text, t->proptext);
else
sprintf(str, "Dx: %s Dy: %s Dz: %s %s", &c[0], &c[20], &c[40], t->proptext);
}
else {
/* default header print */
if (t->con.mode & CON_APPLY)
sprintf(str, "Dx: %.4f Dy: %.4f Dz: %.4f %s %s", vec[0], vec[1], vec[2], t->con.text, t->proptext);
else
sprintf(str, "Dx: %.4f Dy: %.4f Dz: %.4f %s", vec[0], vec[1], vec[2], t->proptext);
}

View File

@@ -337,6 +337,38 @@ int getConstraintSpaceDimension(TransInfo *t)
*/
}
void setConstraint(TransInfo *t, float space[3][3], int mode, const char text[]) {
strcpy(t->con.text, text);
Mat3CpyMat3(t->con.mtx, space);
t->con.mode = mode;
getConstraintMatrix(t);
VECCOPY(t->con.center, t->center);
if (G.obedit) {
Mat4MulVecfl(G.obedit->obmat, t->con.center);
}
t->con.applyVec = applyAxisConstraintVec;
t->con.applySize = applyAxisConstraintSize;
t->con.applyRot = applyAxisConstraintRot;
t->redraw = 1;
}
void setLocalConstraint(TransInfo *t, int mode, const char text[]) {
if (G.obedit) {
float obmat[3][3];
Mat3CpyMat4(obmat, G.obedit->obmat);
setConstraint(t, obmat, mode, text);
}
else {
if (t->total == 1) {
float obmat[3][3];
Mat3CpyMat4(obmat, t->data->ob->obmat);
setConstraint(t, obmat, mode, text);
}
}
}
void BIF_setSingleAxisConstraint(float vec[3]) {
TransInfo *t = BIF_GetTransInfo();
float space[3][3], v[3];
@@ -364,29 +396,13 @@ void BIF_setSingleAxisConstraint(float vec[3]) {
t->redraw = 1;
}
void setConstraint(TransInfo *t, float space[3][3], int mode) {
Mat3CpyMat3(t->con.mtx, space);
t->con.mode = mode;
getConstraintMatrix(t);
VECCOPY(t->con.center, t->center);
if (G.obedit) {
Mat4MulVecfl(G.obedit->obmat, t->con.center);
}
t->con.applyVec = applyAxisConstraintVec;
t->con.applySize = applyAxisConstraintSize;
t->con.applyRot = applyAxisConstraintRot;
t->redraw = 1;
}
void BIF_drawConstraint()
{
int i = -1;
TransInfo *t = BIF_GetTransInfo();
TransCon *tc = &(t->con);
if (tc->mode == 0)
if (!(tc->mode & CON_APPLY))
return;
if (tc->mode & CON_SELECT) {
@@ -544,25 +560,31 @@ void setNearestAxis(TransInfo *t)
if (len[0] < len[1] && len[0] < len[2]) {
if (G.qual == LR_CTRLKEY) {
t->con.mode |= (CON_AXIS1|CON_AXIS2);
strcpy(t->con.text, "locking global X");
}
else {
t->con.mode |= CON_AXIS0;
strcpy(t->con.text, "along global X");
}
}
else if (len[1] < len[0] && len[1] < len[2]) {
if (G.qual == LR_CTRLKEY) {
t->con.mode |= (CON_AXIS0|CON_AXIS2);
strcpy(t->con.text, "locking global Y");
}
else {
t->con.mode |= CON_AXIS1;
strcpy(t->con.text, "along global Y");
}
}
else if (len[2] < len[1] && len[2] < len[0]) {
if (G.qual == LR_CTRLKEY) {
t->con.mode |= (CON_AXIS0|CON_AXIS1);
strcpy(t->con.text, "locking global Z");
}
else {
t->con.mode |= CON_AXIS2;
strcpy(t->con.text, "along global Z");
}
}
getConstraintMatrix(t);

View File

@@ -36,7 +36,8 @@
#include "transform.h"
void getConstraintMatrix(TransInfo *t);
void setConstraint(TransInfo *t, float space[3][3], int mode);
void setConstraint(TransInfo *t, float space[3][3], int mode, const char text[]);
void setLocalConstraint(TransInfo *t, int mode, const char text[]);
//void drawConstraint(TransCon *t);
void drawConstraint();

View File

@@ -635,7 +635,7 @@ void calculatePropRatio(TransInfo *t)
if (G.f & G_PROPORTIONAL) {
for(i = 0 ; i < t->total; i++, td++) {
if (td->dist == 0.0f) {
if (td->flag & TD_SELECTED) {
td->factor = 1.0f;
}
else if (td->dist > t->propsize) {