From 61f2736ec36154f5832c11ae5d018e6eaf89a3b2 Mon Sep 17 00:00:00 2001 From: Martin Poirier Date: Mon, 2 May 2005 02:18:13 +0000 Subject: [PATCH] Local axis constraint external call. Had to do it in a very hackish way which highlight a design problem in the code. To solve it (and would solve other problems too), we'd have to split off the initialisation function. Not terribly hard to do but I'm overwhelmed with work... Push/Pull had a problem with constraints enabling/disabling. Fixed Restablished infinite line for constraint draw (when not using manipulator) as discussed in meeting. --- source/blender/include/BIF_transform.h | 3 ++ source/blender/src/header_view3d.c | 27 +++++++---- source/blender/src/transform.c | 15 ++++++- source/blender/src/transform_constraints.c | 52 +++++++++++++++++----- 4 files changed, 76 insertions(+), 21 deletions(-) diff --git a/source/blender/include/BIF_transform.h b/source/blender/include/BIF_transform.h index 6450d8c80a8..1557f87d039 100755 --- a/source/blender/include/BIF_transform.h +++ b/source/blender/include/BIF_transform.h @@ -56,6 +56,7 @@ #define CTX_EDGE 2 #define CTX_NO_PET 4 #define CTX_NO_NOR_RECALC 8 +#define CTX_SETLOCALCONST 16 /* TRANSFORM PROPORTIONAL FALLOFF MODES */ #define PROP_SHARP 0 @@ -74,6 +75,8 @@ struct ScrArea; struct TransInfo * BIF_GetTransInfo(void); void BIF_setSingleAxisConstraint(float vec[3], char *text); void BIF_setDualAxisConstraint(float vec1[3], float vec2[3], char *text); +void BIF_setLocalAxisConstraint(char axis, char *text); +void BIF_setLocalLockConstraint(char axis, char *text); void BIF_drawConstraint(void); void BIF_drawPropCircle(void); diff --git a/source/blender/src/header_view3d.c b/source/blender/src/header_view3d.c index 602637ee863..1962a7beedc 100644 --- a/source/blender/src/header_view3d.c +++ b/source/blender/src/header_view3d.c @@ -1154,13 +1154,16 @@ void do_view3d_transform_moveaxismenu(void *arg, int event) Transform(TFM_TRANSLATION, CTX_NONE); break; case 3: /* X Local */ -// transform('g'*'x'); + BIF_setLocalAxisConstraint('X', " X"); + Transform(TFM_TRANSLATION, CTX_SETLOCALCONST); break; case 4: /* Y Local */ -// transform('g'*'y'); + BIF_setLocalAxisConstraint('Y', " Y"); + Transform(TFM_TRANSLATION, CTX_SETLOCALCONST); break; case 5: /* Z Local */ -// transform('g'*'z'); + BIF_setLocalAxisConstraint('Z', " Z"); + Transform(TFM_TRANSLATION, CTX_SETLOCALCONST); break; } allqueue(REDRAWVIEW3D, 0); @@ -1211,13 +1214,16 @@ void do_view3d_transform_rotateaxismenu(void *arg, int event) Transform(TFM_ROTATION, CTX_NONE); break; case 3: /* X Local */ -// transform('r'*'x'); + BIF_setLocalAxisConstraint('X', " X"); + Transform(TFM_ROTATION, CTX_SETLOCALCONST); break; case 4: /* Y Local */ -// transform('r'*'y'); + BIF_setLocalAxisConstraint('Y', " Y"); + Transform(TFM_ROTATION, CTX_SETLOCALCONST); break; case 5: /* Z Local */ -// transform('r'*'z'); + BIF_setLocalAxisConstraint('Z', " Z"); + Transform(TFM_ROTATION, CTX_SETLOCALCONST); break; } allqueue(REDRAWVIEW3D, 0); @@ -1268,13 +1274,16 @@ void do_view3d_transform_scaleaxismenu(void *arg, int event) Transform(TFM_RESIZE, CTX_NONE); break; case 3: /* X Local */ - + BIF_setLocalAxisConstraint('X', " X"); + Transform(TFM_RESIZE, CTX_SETLOCALCONST); break; case 4: /* Y Local */ - + BIF_setLocalAxisConstraint('X', " X"); + Transform(TFM_RESIZE, CTX_SETLOCALCONST); break; case 5: /* Z Local */ - + BIF_setLocalAxisConstraint('X', " X"); + Transform(TFM_RESIZE, CTX_SETLOCALCONST); break; } allqueue(REDRAWVIEW3D, 0); diff --git a/source/blender/src/transform.c b/source/blender/src/transform.c index 3c6de26b7d6..1df4025da04 100755 --- a/source/blender/src/transform.c +++ b/source/blender/src/transform.c @@ -233,6 +233,16 @@ void Transform(int mode, int context) return; } + /* CHECKING FOR CTX_SETLOCALCONST CONTEXT FLAG */ + /* EVIL, best would be to split off init, this way all the external constraint call could work like that: + initTransform(mode) + initconstraint(setup) + Transform() + */ + if (Trans.context & CTX_SETLOCALCONST) { + setLocalConstraint(&Trans, Trans.con.mode, Trans.con.text); + } + /* EVIL! posemode code can switch translation to rotate when 1 bone is selected. will be removed (ton) */ /* EVIL2: we gave as argument also texture space context bit... was cleared */ mode= Trans.mode; @@ -395,6 +405,7 @@ void Transform(int mode, int context) Trans.redraw= 1; } else { + cmode = '\0'; stopConstraint(&Trans); Trans.redraw = 1; } @@ -1899,7 +1910,7 @@ int PushPull(TransInfo *t, short mval[2]) sprintf(str, "Push/Pull: %.4f%s %s", distance, t->con.text, t->proptext); } - if (t->con.applyRot) { + if (t->con.applyRot && t->con.mode & CON_APPLY) { t->con.applyRot(t, NULL, axis); } @@ -1908,7 +1919,7 @@ int PushPull(TransInfo *t, short mval[2]) break; VecSubf(vec, t->center, td->center); - if (t->con.applyRot) { + if (t->con.applyRot && t->con.mode & CON_APPLY) { t->con.applyRot(t, td, axis); Projf(vec, vec, axis); } diff --git a/source/blender/src/transform_constraints.c b/source/blender/src/transform_constraints.c index 7611041cddd..1c67e272146 100755 --- a/source/blender/src/transform_constraints.c +++ b/source/blender/src/transform_constraints.c @@ -541,6 +541,42 @@ void setConstraint(TransInfo *t, float space[3][3], int mode, const char text[]) t->redraw = 1; } +void BIF_setLocalAxisConstraint(char axis, char *text) { + TransInfo *t = BIF_GetTransInfo(); + + strncpy(t->con.text, text, 48); + + switch (axis) { + case 'X': + t->con.mode = (CON_AXIS0|CON_APPLY); + break; + case 'Y': + t->con.mode = (CON_AXIS1|CON_APPLY); + break; + case 'Z': + t->con.mode = (CON_AXIS2|CON_APPLY); + break; + } +} + +void BIF_setLocalLockConstraint(char axis, char *text) { + TransInfo *t = BIF_GetTransInfo(); + + strncpy(t->con.text, text, 48); + + switch (axis) { + case 'x': + t->con.mode = (CON_AXIS1|CON_AXIS2|CON_APPLY); + break; + case 'y': + t->con.mode = (CON_AXIS0|CON_AXIS2|CON_APPLY); + break; + case 'z': + t->con.mode = (CON_AXIS0|CON_AXIS1|CON_APPLY); + break; + } +} + void setLocalConstraint(TransInfo *t, int mode, const char text[]) { if (t->flag & T_EDIT) { float obmat[3][3]; @@ -650,11 +686,10 @@ void BIF_drawConstraint(void) window_to_3d(vec, (short)(mval[0] - t->con.imval[0]), (short)(mval[1] - t->con.imval[1])); VecAddf(vec, vec, tc->center); -// drawLine(tc->center, tc->mtx[0], 'x', 0); -// drawLine(tc->center, tc->mtx[1], 'y', 0); -// drawLine(tc->center, tc->mtx[2], 'z', 0); + drawLine(tc->center, tc->mtx[0], 'x', 0); + drawLine(tc->center, tc->mtx[1], 'y', 0); + drawLine(tc->center, tc->mtx[2], 'z', 0); - draw_manipulator_ext(curarea, t->mode, 'c', 2, tc->center, tc->mtx); glColor3ubv(col2); glDisable(GL_DEPTH_TEST); @@ -668,16 +703,13 @@ void BIF_drawConstraint(void) } if (tc->mode & CON_AXIS0) { - draw_manipulator_ext(curarea, t->mode, 'x', 0, tc->center, tc->mtx); -// drawLine(tc->center, tc->mtx[0], 'x', DRAWLIGHT); + drawLine(tc->center, tc->mtx[0], 'x', DRAWLIGHT); } if (tc->mode & CON_AXIS1) { - draw_manipulator_ext(curarea, t->mode, 'y', 0, tc->center, tc->mtx); -// drawLine(tc->center, tc->mtx[1], 'y', DRAWLIGHT); + drawLine(tc->center, tc->mtx[1], 'y', DRAWLIGHT); } if (tc->mode & CON_AXIS2) { - draw_manipulator_ext(curarea, t->mode, 'z', 0, tc->center, tc->mtx); -// drawLine(tc->center, tc->mtx[2], 'z', DRAWLIGHT); + drawLine(tc->center, tc->mtx[2], 'z', DRAWLIGHT); } } }