diff options
author | Martin Poirier <theeth@yahoo.com> | 2005-07-24 10:25:00 +0400 |
---|---|---|
committer | Martin Poirier <theeth@yahoo.com> | 2005-07-24 10:25:00 +0400 |
commit | 0e2302bfa563bed5e98e86a71c00b3d2861df0c3 (patch) | |
tree | df1b69e33506ce8f780d07f4b67ce3876ef87a0d /source/blender | |
parent | 1516381df1548cad58f505b35e13f6455bf6d1b6 (diff) |
Big Transform Manipulator Merge
*NOTE*: Some UI decision done in this commit will most likely be revised, all flame shall go in /dev/null. Constructive discussions of course welcomed.
This commit merges manipulator orientation selection back in "traditional" transform.
That's how it works:
- The dropdown in the 3D view header is always visible
- The orientation chosen will be used when choosing an axis with MMB and for the *second* key press of X,Y,Z
However, Local orientation doesn't use the one calculated by the manipulator. This is to ensure that multiple object local and armatures in pose still works as before.
- Alt-Space (to change the orientation) works during transform
New Transform orientation: View, using the view axis.
Fixes for the following bugs:
- Constraint projection code "jammed" if input vector was <0,0,0>, reported a couple of times on IRC. Thanks to Basse for the example file.
- Transform on texspace crashed on objects without texspace data (camera, lamp, ...). This was reported in tracker.
- Numinput with lock constraints didn't work correctly. Reported on elysiun
Probably some others that I'm forgetting
I also moved a couple of functions around in an attempt to make things clearer.
Diffstat (limited to 'source/blender')
-rwxr-xr-x | source/blender/include/BIF_transform.h | 2 | ||||
-rwxr-xr-x | source/blender/include/transform.h | 70 | ||||
-rw-r--r-- | source/blender/src/header_view3d.c | 12 | ||||
-rw-r--r-- | source/blender/src/space.c | 10 | ||||
-rwxr-xr-x | source/blender/src/transform.c | 123 | ||||
-rwxr-xr-x | source/blender/src/transform_constraints.c | 299 | ||||
-rwxr-xr-x | source/blender/src/transform_conversions.c | 11 | ||||
-rwxr-xr-x | source/blender/src/transform_generics.c | 8 | ||||
-rw-r--r-- | source/blender/src/transform_manipulator.c | 70 | ||||
-rwxr-xr-x | source/blender/src/transform_numinput.c | 24 |
10 files changed, 334 insertions, 295 deletions
diff --git a/source/blender/include/BIF_transform.h b/source/blender/include/BIF_transform.h index 78f2bb38c48..7c5acf2cce8 100755 --- a/source/blender/include/BIF_transform.h +++ b/source/blender/include/BIF_transform.h @@ -75,6 +75,8 @@ void BIF_drawPropCircle(void); void BIF_TransformSetUndo(char *str); +void BIF_selectOrientation(void); + /* view3d manipulators */ void initManipulator(int mode); void ManipulatorTransform(); diff --git a/source/blender/include/transform.h b/source/blender/include/transform.h index e42a3dcb7e7..943f18793f4 100755 --- a/source/blender/include/transform.h +++ b/source/blender/include/transform.h @@ -124,27 +124,27 @@ typedef struct TransData { typedef struct TransInfo { int mode; /* current mode */ + int flag; /* generic flags for special behaviors */ short state; /* current state (running, canceled,...)*/ int context; /* current context */ + float val; /* init value for some transformations (and rotation angle) */ + float fac; /* factor for distance based transform */ int (*transform)(struct TransInfo *, short *); /* transform function pointer */ - char redraw; /* redraw flag */ - int flag; /* generic flags for special behaviors */ int total; /* total number of transformed data */ + TransData *data; /* transformed data (array) */ + TransDataExtension *ext; /* transformed data extension (array) */ + TransCon con; /* transformed constraint */ + NumInput num; /* numerical input */ + char redraw; /* redraw flag */ float propsize; /* proportional circle radius */ char proptext[20]; /* proportional falloff text */ float center[3]; /* center of transformation */ int center2d[2]; /* center in screen coordinates */ short imval[2]; /* initial mouse position */ short shiftmval[2]; /* mouse position when shift was pressed */ - short idx_max; + short idx_max; /* maximum index on the input vector */ float snap[3]; /* Snapping Gears */ - TransData *data; /* transformed data (array) */ - TransDataExtension *ext; /* transformed data extension (array) */ - TransCon con; /* transformed constraint */ - NumInput num; /* numerical input */ - float val; /* init value for some transformations (and rotation angle) */ - float fac; /* factor for distance based transform */ float viewmat[4][4]; /* copy from G.vd, prevents feedback */ float viewinv[4][4]; @@ -153,7 +153,9 @@ typedef struct TransInfo { float vec[3]; /* translation, to show for widget */ float mat[3][3]; /* rot/rescale, to show for widget */ - char *undostr; /* if set, uses this string for undo */ + char *undostr; /* if set, uses this string for undo */ + float spacemtx[3][3]; /* orientation matrix of the current space */ + char spacename[32]; /* name of the current space */ } TransInfo; @@ -184,9 +186,9 @@ typedef struct TransInfo { /* restrictions flags */ #define T_ALL_RESTRICTIONS (256|512|1024) -#define T_NO_CONSTRAINT 256 -#define T_NULL_ONE 512 -#define T_NO_ZERO 1024 +#define T_NO_CONSTRAINT 256 +#define T_NULL_ONE 512 +#define T_NO_ZERO 1024 #define T_PROP_EDIT 2048 #define T_PROP_CONNECTED 4096 @@ -202,11 +204,12 @@ typedef struct TransInfo { #define CON_SELECT 16 #define CON_NOFLIP 32 /* does not reorient vector to face viewport when on */ #define CON_LOCAL 64 +#define CON_USER 128 /* transdata->flag */ -#define TD_SELECTED 1 -#define TD_NOACTION 2 -#define TD_USEQUAT 4 +#define TD_SELECTED 1 +#define TD_NOACTION 2 +#define TD_USEQUAT 4 #define TD_NOTCONNECTED 8 #define TD_SINGLESIZE 16 /* used for scaling of MetaElem->rad */ @@ -264,40 +267,34 @@ void add_tdi_poin(float *poin, float *old, float delta); void special_aftertrans_update(short canceled); /*********************** Constraints *****************************/ + void getConstraintMatrix(TransInfo *t); void setConstraint(TransInfo *t, float space[3][3], int mode, const char text[]); void setLocalConstraint(TransInfo *t, int mode, const char text[]); +void setUserConstraint(TransInfo *t, int mode, const char text[]); void constraintNumInput(TransInfo *t, float vec[3]); -//void drawConstraint(TransCon *t); -void drawConstraint(); - -//void drawPropCircle(TransInfo *t); -void drawPropCircle(); - +void getConstraintMatrix(TransInfo *t); int isLockConstraint(TransInfo *t); +int getConstraintSpaceDimension(TransInfo *t); +char constraintModeToChar(TransInfo *t); -void initConstraint(TransInfo *t); void startConstraint(TransInfo *t); void stopConstraint(TransInfo *t); -void getConstraintMatrix(TransInfo *t); - void initSelectConstraint(TransInfo *t, float mtx[3][3]); void selectConstraint(TransInfo *t); void postSelectConstraint(TransInfo *t); -int getConstraintSpaceDimension(TransInfo *t); - void setNearestAxis(TransInfo *t); - -char constraintModeToChar(TransInfo *t); +void drawObjectConstraint(TransInfo *t); /*********************** Generics ********************************/ -void recalcData(TransInfo *t); +void initTrans(TransInfo *t); void initTransModeFlags(TransInfo *t, int mode); +void postTrans (TransInfo *t); void drawLine(float *center, float *dir, char axis, short options); @@ -308,16 +305,13 @@ void drawLine(float *center, float *dir, char axis, short options); void applyTransObjects(TransInfo *t); void restoreTransObjects(TransInfo *t); +void recalcData(TransInfo *t); -void initTrans(TransInfo *t); -void postTrans (TransInfo *t); - +void calculateCenter(TransInfo *t); void calculateCenterBound(TransInfo *t); void calculateCenterMedian(TransInfo *t); void calculateCenterCursor(TransInfo *t); -void calculateCenter(TransInfo *t); - void calculatePropRatio(TransInfo *t); void snapGrid(TransInfo *t, float *val); @@ -326,14 +320,12 @@ void getViewVector(float coord[3], float vec[3]); TransInfo * BIF_GetTransInfo(void); - /*********************** NumInput ********************************/ -void outputNumInput(NumInput *n, char *str); +void outputNumInput(NumInput *n, char *str); short hasNumInput(NumInput *n); - void applyNumInput(NumInput *n, float *vec); - char handleNumInput(NumInput *n, unsigned short event); + #endif diff --git a/source/blender/src/header_view3d.c b/source/blender/src/header_view3d.c index 606169a0e85..b1fd7551fbf 100644 --- a/source/blender/src/header_view3d.c +++ b/source/blender/src/header_view3d.c @@ -4064,19 +4064,19 @@ void view3d_buttons(void) /* Transform widget / manipulators */ uiBlockBeginAlign(block); - uiDefIconButS(block, TOG|BIT|0, B_REDR, ICON_MANIPUL,xco,0,XIC,YIC, &G.vd->twflag, 0, 0, 0, 0, "Use 3d transform widgets (CTRL+Space)"); + uiDefIconButS(block, TOG|BIT|0, B_REDR, ICON_MANIPUL,xco,0,XIC,YIC, &G.vd->twflag, 0, 0, 0, 0, "Use 3d transform manipulator (CTRL+Space)"); xco+= XIC; if(G.vd->twflag & V3D_USE_MANIPULATOR) { - uiDefIconButS(block, TOG|BIT|0, B_MAN_TRANS, ICON_MAN_TRANS, xco,0,XIC,YIC, &G.vd->twtype, 1.0, 0.0, 0, 0, "Translate widget mode (CTRL+Space)"); + uiDefIconButS(block, TOG|BIT|0, B_MAN_TRANS, ICON_MAN_TRANS, xco,0,XIC,YIC, &G.vd->twtype, 1.0, 0.0, 0, 0, "Translate manipulator mode (CTRL+Space)"); xco+= XIC; - uiDefIconButS(block, TOG|BIT|1, B_MAN_ROT, ICON_MAN_ROT, xco,0,XIC,YIC, &G.vd->twtype, 1.0, 0.0, 0, 0, "Rotate widget mode (CTRL+Space)"); + uiDefIconButS(block, TOG|BIT|1, B_MAN_ROT, ICON_MAN_ROT, xco,0,XIC,YIC, &G.vd->twtype, 1.0, 0.0, 0, 0, "Rotate manipulator mode (CTRL+Space)"); xco+= XIC; - uiDefIconButS(block, TOG|BIT|2, B_MAN_SCALE, ICON_MAN_SCALE, xco,0,XIC,YIC, &G.vd->twtype, 1.0, 0.0, 0, 0, "Scale widget mode (CTRL+Space)"); + uiDefIconButS(block, TOG|BIT|2, B_MAN_SCALE, ICON_MAN_SCALE, xco,0,XIC,YIC, &G.vd->twtype, 1.0, 0.0, 0, 0, "Scale manipulator mode (CTRL+Space)"); xco+= XIC; - uiDefButS(block, MENU, REDRAWVIEW3D, "Orientation%t|Global%x0|Local%x1|Normal%x2", xco,0,60,YIC, &G.vd->twmode, 0, 0, 0, 0, "Widget orientation (ALT+Space)"); - xco+= 60; } + uiDefButS(block, MENU, B_MAN_MODE, "Orientation%t|Global%x0|Local%x1|Normal%x2|View%x3|Custom%x4",xco,0,70,YIC, &G.vd->twmode, 0, 0, 0, 0, "Transform Orientation (ALT+Space)"); + xco+= 70; uiBlockEndAlign(block); xco+= 8; diff --git a/source/blender/src/space.c b/source/blender/src/space.c index a690a6e3d16..895a292bffa 100644 --- a/source/blender/src/space.c +++ b/source/blender/src/space.c @@ -1072,14 +1072,8 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt) } } else if(G.qual == LR_ALTKEY) { - val= pupmenu("Manipulator Orientation%t|Global|Local|Normal"); - if(val>0) { - if(val==1) v3d->twmode= V3D_MANIP_GLOBAL; - else if(val==2) v3d->twmode= V3D_MANIP_LOCAL; - else if(val==3) v3d->twmode= V3D_MANIP_NORMAL; - v3d->twflag |= V3D_USE_MANIPULATOR; - doredraw= 1; - } + BIF_selectOrientation(); + doredraw= 1; } break; diff --git a/source/blender/src/transform.c b/source/blender/src/transform.c index 70d4781b7b5..053f50f6df6 100755 --- a/source/blender/src/transform.c +++ b/source/blender/src/transform.c @@ -31,6 +31,7 @@ */ #include <stdlib.h> +#include <stdio.h> #include <string.h> #include <math.h> @@ -46,51 +47,43 @@ #include "MEM_guardedalloc.h" -#include "DNA_action_types.h" -#include "DNA_armature_types.h" -#include "DNA_camera_types.h" -#include "DNA_constraint_types.h" -#include "DNA_curve_types.h" -#include "DNA_effect_types.h" -#include "DNA_image_types.h" -#include "DNA_ipo_types.h" -#include "DNA_key_types.h" -#include "DNA_lamp_types.h" -#include "DNA_lattice_types.h" -#include "DNA_mesh_types.h" -#include "DNA_meshdata_types.h" -#include "DNA_meta_types.h" +#include "DNA_listBase.h" +#include "DNA_userdef_types.h" +#include "DNA_scene_types.h" /* PET modes */ +#include "DNA_screen_types.h" /* area dimensions */ #include "DNA_object_types.h" #include "DNA_scene_types.h" #include "DNA_screen_types.h" #include "DNA_texture_types.h" #include "DNA_view3d_types.h" -#include "DNA_world_types.h" -#include "DNA_userdef_types.h" -#include "DNA_property_types.h" -#include "DNA_vfont_types.h" +#include "DNA_ipo_types.h" /* some silly ipo flag */ +#include "DNA_meshdata_types.h" +#include "DNA_mesh_types.h" #include "BIF_editview.h" /* arrows_move_cursor */ #include "BIF_gl.h" #include "BIF_mywindow.h" #include "BIF_resources.h" #include "BIF_screen.h" -#include "BIF_space.h" /* undo */ -#include "BIF_toets.h" /* persptoetsen */ +#include "BIF_space.h" /* undo */ +#include "BIF_toets.h" /* persptoetsen */ +#include "BIF_mywindow.h" /* warp_pointer */ +#include "BIF_toolbox.h" /* notice */ +#include "BIF_editmesh.h" -#include "BKE_blender.h" #include "BKE_global.h" #include "BKE_utildefines.h" +#include "BKE_bad_level_calls.h"/* popmenu and error */ -#include "BDR_editobject.h" +#include "BDR_editobject.h" /* compatible_eul */ #include "BSE_view.h" #include "BLI_arithb.h" +#include "BLI_blenlib.h" +#include "BLI_editVert.h" -#include "BDR_editobject.h" - -#include "PIL_time.h" +#include "PIL_time.h" /* sleep */ #include "blendef.h" @@ -141,6 +134,17 @@ static void helpline(float *vec, int local) /* ************************** TRANSFORMATIONS **************************** */ +void BIF_selectOrientation() { + short val; + val= pupmenu("Orientation%t|Global|Local|Normal|View"); + if(val>0) { + if(val==1) G.vd->twmode= V3D_MANIP_GLOBAL; + else if(val==2) G.vd->twmode= V3D_MANIP_LOCAL; + else if(val==3) G.vd->twmode= V3D_MANIP_NORMAL; + else if(val==4) G.vd->twmode= V3D_MANIP_VIEW; + } +} + static void view_editmove(unsigned short event) { int refresh = 0; @@ -209,6 +213,13 @@ static void view_editmove(unsigned short event) } } +void checkFirstTime() { + if(Trans.mode==TFM_INIT) { + memset(&Trans, 0, sizeof(TransInfo)); + Trans.propsize = 1.0; + } +} + static char *transform_to_undostr(TransInfo *t) { switch (t->mode) { @@ -240,14 +251,6 @@ static char *transform_to_undostr(TransInfo *t) /* ************************************************* */ -void checkFirstTime() { - if(Trans.mode==TFM_INIT) { - memset(&Trans, 0, sizeof(TransInfo)); - Trans.propsize = 1.0; - Mat3One(MatSpace); - } -} - static void transformEvent(unsigned short event, short val) { float mati[3][3] = {{1.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 1.0f}}; char cmode = constraintModeToChar(&Trans); @@ -266,6 +269,22 @@ static void transformEvent(unsigned short event, short val) { Trans.flag |= T_SHIFT_MOD; Trans.redraw = 1; break; + + case SPACEKEY: + if (G.qual & LR_ALTKEY) { + short mval[2]; + + getmouseco_sc(mval); + BIF_selectOrientation(); + calc_manipulator_stats(curarea); + Mat3CpyMat4(Trans.spacemtx, G.vd->twmat); + warp_pointer(mval[0], mval[1]); + } + else { + Trans.state = TRANS_CONFIRM; + } + break; + case MIDDLEMOUSE: if ((Trans.flag & T_NO_CONSTRAINT)==0) { @@ -285,7 +304,7 @@ static void transformEvent(unsigned short event, short val) { stopConstraint(&Trans); } else { - initSelectConstraint(&Trans, MatSpace); + initSelectConstraint(&Trans, Trans.spacemtx); postSelectConstraint(&Trans); } } @@ -297,7 +316,6 @@ static void transformEvent(unsigned short event, short val) { Trans.state = TRANS_CANCEL; break; case LEFTMOUSE: - case SPACEKEY: case PADENTER: case RETKEY: Trans.state = TRANS_CONFIRM; @@ -342,14 +360,14 @@ static void transformEvent(unsigned short event, short val) { case XKEY: if ((Trans.flag & T_NO_CONSTRAINT)==0) { if (cmode == 'X') { - if (Trans.con.mode & CON_LOCAL) { + if (Trans.con.mode & CON_USER) { stopConstraint(&Trans); } else { if (G.qual == 0) - setLocalConstraint(&Trans, (CON_AXIS0), "along local X"); + setUserConstraint(&Trans, (CON_AXIS0), "along %s X"); else if (G.qual == LR_SHIFTKEY) - setLocalConstraint(&Trans, (CON_AXIS1|CON_AXIS2), "locking local X"); + setUserConstraint(&Trans, (CON_AXIS1|CON_AXIS2), "locking %s X"); } } else { @@ -364,14 +382,14 @@ static void transformEvent(unsigned short event, short val) { case YKEY: if ((Trans.flag & T_NO_CONSTRAINT)==0) { if (cmode == 'Y') { - if (Trans.con.mode & CON_LOCAL) { + if (Trans.con.mode & CON_USER) { stopConstraint(&Trans); } else { if (G.qual == 0) - setLocalConstraint(&Trans, (CON_AXIS1), "along local Y"); + setUserConstraint(&Trans, (CON_AXIS1), "along %s Y"); else if (G.qual == LR_SHIFTKEY) - setLocalConstraint(&Trans, (CON_AXIS0|CON_AXIS2), "locking local Y"); + setUserConstraint(&Trans, (CON_AXIS0|CON_AXIS2), "locking %s Y"); } } else { @@ -386,14 +404,14 @@ static void transformEvent(unsigned short event, short val) { case ZKEY: if ((Trans.flag & T_NO_CONSTRAINT)==0) { if (cmode == 'Z') { - if (Trans.con.mode & CON_LOCAL) { + if (Trans.con.mode & CON_USER) { stopConstraint(&Trans); } else { if (G.qual == 0) - setLocalConstraint(&Trans, (CON_AXIS2), "along local Z"); + setUserConstraint(&Trans, (CON_AXIS2), "along %s Z"); else if (G.qual == LR_SHIFTKEY) - setLocalConstraint(&Trans, (CON_AXIS0|CON_AXIS1), "locking local Z"); + setUserConstraint(&Trans, (CON_AXIS0|CON_AXIS1), "locking %s Z"); } } else { @@ -481,6 +499,9 @@ void initTransform(int mode, int context) { Trans.context = context; + calc_manipulator_stats(curarea); + Mat3CpyMat4(Trans.spacemtx, G.vd->twmat); + initTrans(&Trans); // internal data, mouse, vectors initTransModeFlags(&Trans, mode); // modal settings in struct Trans @@ -537,20 +558,15 @@ void initTransform(int mode, int context) { initBoneSize(&Trans); break; } - - initConstraint(&Trans); } void Transform() { - float mati[3][3]; short pmval[2] = {0, 0}, mval[2], val; unsigned short event; if(Trans.total==0) return; // added, can happen now! (ton) - Mat3One(mati); - // Emptying event queue while( qtest() ) { event= extern_qread(&val); @@ -564,7 +580,7 @@ void Transform() if (mval[0] != pmval[0] || mval[1] != pmval[1]) { if (Trans.flag & T_MMB_PRESSED) { - initSelectConstraint(&Trans, mati); + initSelectConstraint(&Trans, Trans.spacemtx); } Trans.redraw = 1; } @@ -612,6 +628,8 @@ void Transform() scrarea_queue_headredraw(curarea); } +/* ************************** Manipulator init and main **************************** */ + void initManipulator(int mode) { Trans.state = TRANS_RUNNING; @@ -651,7 +669,6 @@ void initManipulator(int mode) } Trans.flag |= T_USES_MANIPULATOR; - initConstraint(&Trans); } void ManipulatorTransform() @@ -765,7 +782,7 @@ void ManipulatorTransform() scrarea_queue_headredraw(curarea); } - +/* ************************** TRANSFORMATIONS **************************** */ /* ************************** WRAP *************************** */ @@ -2147,8 +2164,6 @@ void Mirror(short mode) initResize(&Trans); - initConstraint(&Trans); - if (Trans.total == 0) { postTrans(&Trans); return; diff --git a/source/blender/src/transform_constraints.c b/source/blender/src/transform_constraints.c index b8d7e4bbbcf..24ff6b20587 100755 --- a/source/blender/src/transform_constraints.c +++ b/source/blender/src/transform_constraints.c @@ -31,6 +31,7 @@ */ #include <stdlib.h> +#include <stdio.h> #include <string.h> #ifdef HAVE_CONFIG_H @@ -86,11 +87,7 @@ extern ListBase editNurb; extern ListBase editelems; -void recalcData(); - /* ************************** CONSTRAINTS ************************* */ -void getConstraintMatrix(TransInfo *t); - void constraintNumInput(TransInfo *t, float vec[3]) { int mode = t->con.mode; @@ -98,15 +95,16 @@ void constraintNumInput(TransInfo *t, float vec[3]) float nval = (t->flag & T_NULL_ONE)?1.0f:0.0f; if (getConstraintSpaceDimension(t) == 2) { - if (mode & (CON_AXIS0|CON_AXIS1)) { + int axis = mode & (CON_AXIS0|CON_AXIS1|CON_AXIS2); + if (axis == (CON_AXIS0|CON_AXIS1)) { vec[2] = nval; } - else if (mode & (CON_AXIS1|CON_AXIS2)) { + else if (axis == (CON_AXIS1|CON_AXIS2)) { vec[2] = vec[1]; vec[1] = vec[0]; vec[0] = nval; } - else if (mode & (CON_AXIS0|CON_AXIS2)) { + else if (axis == (CON_AXIS0|CON_AXIS2)) { vec[2] = vec[1]; vec[1] = nval; } @@ -166,7 +164,6 @@ static void postConstraintChecks(TransInfo *t, float vec[3], float pvec[3]) { Mat3MulVecfl(t->con.mtx, vec); } - static void axisProjection(TransInfo *t, float axis[3], float in[3], float out[3]) { float norm[3], n[3], n2[3], vec[3], factor; @@ -186,7 +183,7 @@ static void axisProjection(TransInfo *t, float axis[3], float in[3], float out[3 } else { // prevent division by zero, happens on constrainting without initial delta transform */ - if(in[0]!=0.0f || in[1]!=0.0f || in[2]!=0.0) { + if(in[0]!=0.0f || in[1]!=0.0f || in[2]!=0.0f) { /* project axis on viewplane */ Projf(vec, axis, t->viewinv[2]); VecSubf(vec, axis, vec); @@ -204,7 +201,9 @@ static void axisProjection(TransInfo *t, float axis[3], float in[3], float out[3 Projf(vec, in, n2); /* Adjust output */ - factor = Inpf(vec, vec) / Inpf(axis, vec); + factor = Inpf(axis, vec); + if (factor == 0.0f) return; /* prevent divide by zero */ + factor = Inpf(vec, vec) / factor; VecMulf(axis, factor); VECCOPY(out, axis); @@ -220,7 +219,9 @@ static void planeProjection(TransInfo *t, float in[3], float out[3]) { VecSubf(vec, out, in); - factor = Inpf(vec, vec) / Inpf(vec, norm); + factor = Inpf(vec, norm); + if (factor == 0.0f) return; /* prevent divide by zero */ + factor = Inpf(vec, vec) / factor; VECCOPY(vec, norm); VecMulf(vec, factor); @@ -459,71 +460,7 @@ static void applyObjectConstraintRot(TransInfo *t, TransData *td, float vec[3]) } } -static void drawObjectConstraint(TransInfo *t) { - int i; - TransData * td = t->data; - - /* Draw the first one lighter because that's the one who controls the others. - Meaning the transformation is projected on that one and just copied on the others - constraint space. - In a nutshell, the object with light axis is controlled by the user and the others follow. - Without drawing the first light, users have little clue what they are doing. - */ - if (t->con.mode & CON_AXIS0) { - drawLine(td->ob->obmat[3], td->axismtx[0], 'x', DRAWLIGHT); - } - if (t->con.mode & CON_AXIS1) { - drawLine(td->ob->obmat[3], td->axismtx[1], 'y', DRAWLIGHT); - } - if (t->con.mode & CON_AXIS2) { - drawLine(td->ob->obmat[3], td->axismtx[2], 'z', DRAWLIGHT); - } - - td++; - - for(i=1;i<t->total;i++,td++) { - if (t->con.mode & CON_AXIS0) { - drawLine(td->ob->obmat[3], td->axismtx[0], 'x', 0); - } - if (t->con.mode & CON_AXIS1) { - drawLine(td->ob->obmat[3], td->axismtx[1], 'y', 0); - } - if (t->con.mode & CON_AXIS2) { - drawLine(td->ob->obmat[3], td->axismtx[2], 'z', 0); - } - } -} - -/* - * Returns the dimension of the constraint space. - * - * For that reason, the flags always needs to be set to properly evaluate here, - * even if they aren't actually used in the callback function. (Which could happen - * for weird constraints not yet designed. Along a path for example.) - */ - -int getConstraintSpaceDimension(TransInfo *t) -{ - int n = 0; - - if (t->con.mode & CON_AXIS0) - n++; - - if (t->con.mode & CON_AXIS1) - n++; - - if (t->con.mode & CON_AXIS2) - n++; - - return n; -/* - Someone willing to do it criptically could do the following instead: - - return t->con & (CON_AXIS0|CON_AXIS1|CON_AXIS2); - - Based on the assumptions that the axis flags are one after the other and start at 1 -*/ -} +/*--------------------- INTERNAL SETUP CALLS ------------------*/ void setConstraint(TransInfo *t, float space[3][3], int mode, const char text[]) { strncpy(t->con.text + 1, text, 48); @@ -540,38 +477,6 @@ 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(); - - switch (axis) { - case 'X': - setLocalConstraint(t, CON_AXIS0, text); - break; - case 'Y': - setLocalConstraint(t, CON_AXIS1, text); - break; - case 'Z': - setLocalConstraint(t, CON_AXIS2, text); - break; - } -} - -void BIF_setLocalLockConstraint(char axis, char *text) { - TransInfo *t = BIF_GetTransInfo(); - - switch (axis) { - case 'x': - setLocalConstraint(t, (CON_AXIS1|CON_AXIS2), text); - break; - case 'y': - setLocalConstraint(t, (CON_AXIS0|CON_AXIS2), text); - break; - case 'z': - setLocalConstraint(t, (CON_AXIS0|CON_AXIS1), text); - break; - } -} - void setLocalConstraint(TransInfo *t, int mode, const char text[]) { if (t->flag & T_EDIT) { float obmat[3][3]; @@ -599,6 +504,73 @@ void setLocalConstraint(TransInfo *t, int mode, const char text[]) { } } +/* + Set the constraint according to the user defined orientation + + ftext is a format string passed to sprintf. It will add the name of + the orientation where %s is (logically). +*/ +void setUserConstraint(TransInfo *t, int mode, const char ftext[]) { + float mtx[3][3]; + char text[40]; + + switch(G.vd->twmode) { + case V3D_MANIP_GLOBAL: + sprintf(text, ftext, "global"); + Mat3One(mtx); + setConstraint(t, mtx, mode, text); + break; + case V3D_MANIP_LOCAL: + sprintf(text, ftext, "local"); + setLocalConstraint(t, mode, text); + break; + case V3D_MANIP_NORMAL: + sprintf(text, ftext, "normal"); + setConstraint(t, t->spacemtx, mode, text); + break; + case V3D_MANIP_VIEW: + sprintf(text, ftext, "view"); + setConstraint(t, t->spacemtx, mode, text); + break; + } + + t->con.mode |= CON_USER; +} + +/*--------------------- EXTERNAL SETUP CALLS ------------------*/ + +void BIF_setLocalLockConstraint(char axis, char *text) { + TransInfo *t = BIF_GetTransInfo(); + + switch (axis) { + case 'x': + setLocalConstraint(t, (CON_AXIS1|CON_AXIS2), text); + break; + case 'y': + setLocalConstraint(t, (CON_AXIS0|CON_AXIS2), text); + break; + case 'z': + setLocalConstraint(t, (CON_AXIS0|CON_AXIS1), text); + break; + } +} + +void BIF_setLocalAxisConstraint(char axis, char *text) { + TransInfo *t = BIF_GetTransInfo(); + + switch (axis) { + case 'X': + setLocalConstraint(t, CON_AXIS0, text); + break; + case 'Y': + setLocalConstraint(t, CON_AXIS1, text); + break; + case 'Z': + setLocalConstraint(t, CON_AXIS2, text); + break; + } +} + /* text is optional, for header print */ void BIF_setSingleAxisConstraint(float vec[3], char *text) { TransInfo *t = BIF_GetTransInfo(); @@ -652,6 +624,7 @@ void BIF_setDualAxisConstraint(float vec1[3], float vec2[3], char *text) { t->redraw = 1; } +/*----------------- DRAWING CONSTRAINTS -------------------*/ void BIF_drawConstraint(void) { @@ -730,27 +703,44 @@ void BIF_drawPropCircle() } } -int isLockConstraint(TransInfo *t) { - int mode = t->con.mode; - - if ( (mode & (CON_AXIS0|CON_AXIS1)) == (CON_AXIS0|CON_AXIS1)) - return 1; - if ( (mode & (CON_AXIS1|CON_AXIS2)) == (CON_AXIS1|CON_AXIS2)) - return 1; - - if ( (mode & (CON_AXIS0|CON_AXIS2)) == (CON_AXIS0|CON_AXIS2)) - return 1; +static void drawObjectConstraint(TransInfo *t) { + int i; + TransData * td = t->data; - return 0; -} + /* Draw the first one lighter because that's the one who controls the others. + Meaning the transformation is projected on that one and just copied on the others + constraint space. + In a nutshell, the object with light axis is controlled by the user and the others follow. + Without drawing the first light, users have little clue what they are doing. + */ + if (t->con.mode & CON_AXIS0) { + drawLine(td->ob->obmat[3], td->axismtx[0], 'x', DRAWLIGHT); + } + if (t->con.mode & CON_AXIS1) { + drawLine(td->ob->obmat[3], td->axismtx[1], 'y', DRAWLIGHT); + } + if (t->con.mode & CON_AXIS2) { + drawLine(td->ob->obmat[3], td->axismtx[2], 'z', DRAWLIGHT); + } + + td++; -void initConstraint(TransInfo *t) { - if (t->con.mode & CON_APPLY) { - startConstraint(t); + for(i=1;i<t->total;i++,td++) { + if (t->con.mode & CON_AXIS0) { + drawLine(td->ob->obmat[3], td->axismtx[0], 'x', 0); + } + if (t->con.mode & CON_AXIS1) { + drawLine(td->ob->obmat[3], td->axismtx[1], 'y', 0); + } + if (t->con.mode & CON_AXIS2) { + drawLine(td->ob->obmat[3], td->axismtx[2], 'z', 0); + } } } +/*--------------------- START / STOP CONSTRAINTS ---------------------- */ + void startConstraint(TransInfo *t) { t->con.mode |= CON_APPLY; *t->con.text = ' '; @@ -791,6 +781,8 @@ void getConstraintMatrix(TransInfo *t) Mat3MulMat3(t->con.pmtx, t->con.mtx, mat); } +/*------------------------- MMB Select -------------------------------*/ + void initSelectConstraint(TransInfo *t, float mtx[3][3]) { Mat3CpyMat3(t->con.mtx, mtx); @@ -881,36 +873,38 @@ void setNearestAxis(TransInfo *t) if (len[0] <= len[1] && len[0] <= len[2]) { if (G.qual & LR_SHIFTKEY) { t->con.mode |= (CON_AXIS1|CON_AXIS2); - strcpy(t->con.text, " locking global X"); + sprintf(t->con.text, " locking %s X axis", t->spacename); } else { t->con.mode |= CON_AXIS0; - strcpy(t->con.text, " along global X"); + sprintf(t->con.text, " along %s X axis", t->spacename); } } else if (len[1] <= len[0] && len[1] <= len[2]) { if (G.qual & LR_SHIFTKEY) { t->con.mode |= (CON_AXIS0|CON_AXIS2); - strcpy(t->con.text, " locking global Y"); + sprintf(t->con.text, " locking %s Y axis", t->spacename); } else { t->con.mode |= CON_AXIS1; - strcpy(t->con.text, " along global Y"); + sprintf(t->con.text, " along %s Y axis", t->spacename); } } else if (len[2] <= len[1] && len[2] <= len[0]) { if (G.qual & LR_SHIFTKEY) { t->con.mode |= (CON_AXIS0|CON_AXIS1); - strcpy(t->con.text, " locking global Z"); + sprintf(t->con.text, " locking %s Z axis", t->spacename); } else { t->con.mode |= CON_AXIS2; - strcpy(t->con.text, " along global Z"); + sprintf(t->con.text, " along %s Z axis", t->spacename); } } getConstraintMatrix(t); } +/*-------------- HELPER FUNCTIONS ----------------*/ + char constraintModeToChar(TransInfo *t) { if ((t->con.mode & CON_APPLY)==0) { return '\0'; @@ -929,3 +923,50 @@ char constraintModeToChar(TransInfo *t) { return '\0'; } } + + +int isLockConstraint(TransInfo *t) { + int mode = t->con.mode; + + if ( (mode & (CON_AXIS0|CON_AXIS1)) == (CON_AXIS0|CON_AXIS1)) + return 1; + + if ( (mode & (CON_AXIS1|CON_AXIS2)) == (CON_AXIS1|CON_AXIS2)) + return 1; + + if ( (mode & (CON_AXIS0|CON_AXIS2)) == (CON_AXIS0|CON_AXIS2)) + return 1; + + return 0; +} + +/* + * Returns the dimension of the constraint space. + * + * For that reason, the flags always needs to be set to properly evaluate here, + * even if they aren't actually used in the callback function. (Which could happen + * for weird constraints not yet designed. Along a path for example.) + */ + +int getConstraintSpaceDimension(TransInfo *t) +{ + int n = 0; + + if (t->con.mode & CON_AXIS0) + n++; + + if (t->con.mode & CON_AXIS1) + n++; + + if (t->con.mode & CON_AXIS2) + n++; + + return n; +/* + Someone willing to do it criptically could do the following instead: + + return t->con & (CON_AXIS0|CON_AXIS1|CON_AXIS2); + + Based on the assumptions that the axis flags are one after the other and start at 1 +*/ +}
\ No newline at end of file diff --git a/source/blender/src/transform_conversions.c b/source/blender/src/transform_conversions.c index 9680b61c661..4126a61bf45 100755 --- a/source/blender/src/transform_conversions.c +++ b/source/blender/src/transform_conversions.c @@ -259,6 +259,13 @@ static void createTransTexspace(TransInfo *t) ID *id; ob= OBACT; + + id= ob->data; + if(id==NULL || !ELEM3( GS(id->name), ID_ME, ID_CU, ID_MB )) { + t->total = 0; + return; + } + t->total = 1; td= t->data= MEM_callocN(sizeof(TransData), "TransTexspace"); td->ext= t->ext= MEM_callocN(sizeof(TransDataExtension), "TransTexspace"); @@ -270,9 +277,7 @@ static void createTransTexspace(TransInfo *t) Mat3CpyMat4(td->mtx, ob->obmat); Mat3Inv(td->smtx, td->mtx); - id= ob->data; - if(id==0); - else if( GS(id->name)==ID_ME) { + if( GS(id->name)==ID_ME) { Mesh *me= ob->data; me->texflag &= ~AUTOSPACE; td->loc= me->loc; diff --git a/source/blender/src/transform_generics.c b/source/blender/src/transform_generics.c index 4875228a209..9a6839a8c32 100755 --- a/source/blender/src/transform_generics.c +++ b/source/blender/src/transform_generics.c @@ -322,14 +322,6 @@ void postTrans (TransInfo *t) G.moving = 0; // Set moving flag off (display as usual) stopConstraint(t); - /* Not needed anymore but will keep there in case it will be - t->con.drawExtra = NULL; - t->con.applyVec = NULL; - t->con.applySize= NULL; - t->con.applyRot = NULL; - t->con.mode = 0; - */ - /* postTrans can be called when nothing is selected, so data is NULL already */ if (t->data) { diff --git a/source/blender/src/transform_manipulator.c b/source/blender/src/transform_manipulator.c index effe2f610aa..55dd981c576 100644 --- a/source/blender/src/transform_manipulator.c +++ b/source/blender/src/transform_manipulator.c @@ -153,12 +153,15 @@ static void stats_pose(bPoseChannel *pchan, float *normal, float *plane) int calc_manipulator_stats(ScrArea *sa) { extern ListBase editNurb; + TransInfo *t; View3D *v3d= sa->spacedata.first; Base *base; Object *ob= OBACT; float normal[3]={0.0, 0.0, 0.0}; float plane[3]={0.0, 0.0, 0.0}; int a, totsel=0; + + t = BIF_GetTransInfo(); /* transform widget matrix */ Mat4One(v3d->twmat); @@ -387,10 +390,12 @@ int calc_manipulator_stats(ScrArea *sa) switch(v3d->twmode) { case V3D_MANIP_GLOBAL: + strcpy(t->spacename, "global"); break; case V3D_MANIP_NORMAL: if(G.obedit || (ob->flag & OB_POSEMODE)) { + strcpy(t->spacename, "normal"); if(normal[0]!=0.0 || normal[1]!=0.0 || normal[2]!=0.0) { float imat[3][3], mat[3][3]; @@ -411,18 +416,29 @@ int calc_manipulator_stats(ScrArea *sa) Mat4CpyMat3(v3d->twmat, mat); Mat4Ortho(v3d->twmat); - + break; } } /* no break we define 'normal' as 'local' in Object mode */ case V3D_MANIP_LOCAL: if(totsel==1 || v3d->around==V3D_LOCAL || G.obedit || (ob->flag & OB_POSEMODE)) { + strcpy(t->spacename, "local"); Mat4CpyMat4(v3d->twmat, ob->obmat); Mat4Ortho(v3d->twmat); } break; - } + case V3D_MANIP_VIEW: + { + float mat[3][3]; + strcpy(t->spacename, "view"); + Mat3CpyMat4(mat, v3d->viewinv); + Mat3Ortho(mat); + Mat4CpyMat3(v3d->twmat, mat); + } + break; + } + } return totsel; @@ -588,8 +604,8 @@ static void draw_manipulator_axes(int colcode, int flagx, int flagy, int flagz) if(flagx & MAN_SCALE_X) glLoadName(MAN_SCALE_X); else if(flagx & MAN_TRANS_X) glLoadName(MAN_TRANS_X); glBegin(GL_LINES); - glVertex3f(0.2, 0.0, 0.0); - glVertex3f(1.0, 0.0, 0.0); + glVertex3f(0.2f, 0.0f, 0.0f); + glVertex3f(1.0f, 0.0f, 0.0f); glEnd(); } if(flagy) { @@ -597,8 +613,8 @@ static void draw_manipulator_axes(int colcode, int flagx, int flagy, int flagz) else if(flagy & MAN_TRANS_Y) glLoadName(MAN_TRANS_Y); manipulator_setcolor('y', colcode); glBegin(GL_LINES); - glVertex3f(0.0, 0.2, 0.0); - glVertex3f(0.0, 1.0, 0.0); + glVertex3f(0.0f, 0.2f, 0.0f); + glVertex3f(0.0f, 1.0f, 0.0f); glEnd(); } if(flagz) { @@ -606,8 +622,8 @@ static void draw_manipulator_axes(int colcode, int flagx, int flagy, int flagz) else if(flagz & MAN_TRANS_Z) glLoadName(MAN_TRANS_Z); manipulator_setcolor('z', colcode); glBegin(GL_LINES); - glVertex3f(0.0, 0.0, 0.2); - glVertex3f(0.0, 0.0, 1.0); + glVertex3f(0.0f, 0.0f, 0.2f); + glVertex3f(0.0f, 0.0f, 1.0f); glEnd(); } } @@ -681,9 +697,9 @@ static void draw_manipulator_rotate_ghost(float mat[][4], int drawflags) svec[1]+= tmat[2][1]; Normalise(svec); - startphi= atan2(svec[0], svec[1]); + startphi= (float)atan2(svec[0], svec[1]); } - else startphi= 0.5*M_PI; + else startphi= 0.5f*(float)M_PI; VECCOPY(vec, mat[0]); // use x axis to detect rotation Normalise(vec); @@ -703,9 +719,9 @@ static void draw_manipulator_rotate_ghost(float mat[][4], int drawflags) svec[2]+= tmat[2][2]; Normalise(svec); - startphi= M_PI + atan2(svec[2], -svec[1]); + startphi= (float)(M_PI + atan2(svec[2], -svec[1])); } - else startphi= 0.0; + else startphi= 0.0f; VECCOPY(vec, mat[1]); // use y axis to detect rotation Normalise(vec); @@ -727,9 +743,9 @@ static void draw_manipulator_rotate_ghost(float mat[][4], int drawflags) svec[2]+= tmat[2][2]; Normalise(svec); - startphi= M_PI + atan2(-svec[0], svec[2]); + startphi= (float)(M_PI + atan2(-svec[0], svec[2])); } - else startphi= M_PI; + else startphi= (float)M_PI; VECCOPY(vec, mat[2]); // use z axis to detect rotation Normalise(vec); @@ -833,18 +849,18 @@ static void draw_manipulator_rotate(float mat[][4], int moving, int drawflags, i glBegin(GL_LINES); if( (drawflags & MAN_ROT_X) || (moving && (drawflags & MAN_ROT_Z)) ) { manipulator_setcolor('x', colcode); - glVertex3f(0.2, 0.0, 0.0); - glVertex3f(1.0, 0.0, 0.0); + glVertex3f(0.2f, 0.0f, 0.0f); + glVertex3f(1.0f, 0.0f, 0.0f); } if( (drawflags & MAN_ROT_Y) || (moving && (drawflags & MAN_ROT_X)) ) { manipulator_setcolor('y', colcode); - glVertex3f(0.0, 0.2, 0.0); - glVertex3f(0.0, 1.0, 0.0); + glVertex3f(0.0f, 0.2f, 0.0f); + glVertex3f(0.0f, 1.0f, 0.0f); } if( (drawflags & MAN_ROT_Z) || (moving && (drawflags & MAN_ROT_Y)) ) { manipulator_setcolor('z', colcode); - glVertex3f(0.0, 0.0, 0.2); - glVertex3f(0.0, 0.0, 1.0); + glVertex3f(0.0f, 0.0f, 0.2f); + glVertex3f(0.0f, 0.0f, 1.0f); } glEnd(); } @@ -918,7 +934,7 @@ static void draw_manipulator_rotate(float mat[][4], int moving, int drawflags, i if(G.f & G_PICKSEL) glLoadName(MAN_ROT_Z); manipulator_setcolor('z', colcode); - partial_donut(0.7*cusize, 1.0, 31, 33, 8, 64); + partial_donut(0.7f*cusize, 1.0f, 31, 33, 8, 64); glPopMatrix(); } @@ -931,7 +947,7 @@ static void draw_manipulator_rotate(float mat[][4], int moving, int drawflags, i glRotatef(90.0, 1.0, 0.0, 0.0); glRotatef(90.0, 0.0, 0.0, 1.0); - partial_donut(0.7*cusize, 1.0, 31, 33, 8, 64); + partial_donut(0.7f*cusize, 1.0f, 31, 33, 8, 64); glPopMatrix(); } @@ -944,7 +960,7 @@ static void draw_manipulator_rotate(float mat[][4], int moving, int drawflags, i glRotatef(-90.0, 0.0, 1.0, 0.0); glRotatef(90.0, 0.0, 0.0, 1.0); - partial_donut(0.7*cusize, 1.0, 31, 33, 8, 64); + partial_donut(0.7f*cusize, 1.0f, 31, 33, 8, 64); glPopMatrix(); } @@ -979,7 +995,7 @@ static void draw_manipulator_scale(float mat[][4], int moving, int drawflags, in glPushMatrix(); size= screen_aligned(mat); Mat4One(unitmat); - drawcircball(GL_LINE_LOOP, unitmat[3], 0.2*size, unitmat); + drawcircball(GL_LINE_LOOP, unitmat[3], 0.2f*size, unitmat); glPopMatrix(); dz= 1.0; @@ -1092,7 +1108,7 @@ static void draw_manipulator_translate(float mat[][4], int moving, int drawflags glPushMatrix(); size= screen_aligned(mat); Mat4One(unitmat); - drawcircball(GL_LINE_LOOP, unitmat[3], 0.2*size, unitmat); + drawcircball(GL_LINE_LOOP, unitmat[3], 0.2f*size, unitmat); glPopMatrix(); /* and now apply matrix, we move to local matrix drawing */ @@ -1107,8 +1123,8 @@ static void draw_manipulator_translate(float mat[][4], int moving, int drawflags /* offset in combo mode, for rotate a bit more */ - if(combo & (V3D_MANIP_ROTATE)) dz= 1.0f+2.0*cylen; - else if(combo & (V3D_MANIP_SCALE)) dz= 1.0f+0.5*cylen; + if(combo & (V3D_MANIP_ROTATE)) dz= 1.0f+2.0f*cylen; + else if(combo & (V3D_MANIP_SCALE)) dz= 1.0f+0.5f*cylen; else dz= 1.0f; /* Z Cone */ diff --git a/source/blender/src/transform_numinput.c b/source/blender/src/transform_numinput.c index a2e9fe475b7..6c254697011 100755 --- a/source/blender/src/transform_numinput.c +++ b/source/blender/src/transform_numinput.c @@ -30,29 +30,11 @@ * ***** END GPL/BL DUAL LICENSE BLOCK ***** */ -#include <stdlib.h> -#include <string.h> -#include <math.h> +#include <stdio.h> /* for sprintf */ -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif +#include "BKE_global.h" /* for G */ -#ifndef WIN32 -#include <unistd.h> -#else -#include <io.h> -#endif - -#include "MEM_guardedalloc.h" - -#include "BKE_global.h" /* for G */ - -#include "blendef.h" - -#include "mydevice.h" - -#include "BLI_arithb.h" +#include "mydevice.h" /* for KEY defines */ #include "transform.h" |