4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21 * All rights reserved.
23 * The Original Code is: all of this file.
25 * Contributor(s): none yet.
27 * ***** END GPL LICENSE BLOCK *****
46 #include "MEM_guardedalloc.h"
48 #include "DNA_armature_types.h"
49 #include "DNA_action_types.h" /* for some special action-editor settings */
50 #include "DNA_constraint_types.h"
51 #include "DNA_ipo_types.h" /* some silly ipo flag */
52 #include "DNA_listBase.h"
53 #include "DNA_meshdata_types.h"
54 #include "DNA_mesh_types.h"
55 #include "DNA_object_types.h"
56 #include "DNA_scene_types.h" /* PET modes */
57 #include "DNA_screen_types.h" /* area dimensions */
58 #include "DNA_texture_types.h"
59 #include "DNA_userdef_types.h"
60 #include "DNA_view3d_types.h"
61 #include "DNA_space_types.h"
62 #include "DNA_windowmanager_types.h"
64 #include "RNA_access.h"
66 //#include "BIF_editview.h" /* arrows_move_cursor */
68 #include "BIF_glutil.h"
69 //#include "BIF_mywindow.h"
70 //#include "BIF_resources.h"
71 //#include "BIF_screen.h"
72 //#include "BIF_space.h" /* undo */
73 //#include "BIF_toets.h" /* persptoetsen */
74 //#include "BIF_mywindow.h" /* warp_pointer */
75 //#include "BIF_toolbox.h" /* notice */
76 //#include "BIF_editmesh.h"
77 //#include "BIF_editsima.h"
78 //#include "BIF_editparticle.h"
79 //#include "BIF_drawimage.h" /* uvco_to_areaco_noclip */
80 //#include "BIF_editaction.h"
82 #include "BKE_action.h" /* get_action_frame */
83 //#include "BKE_bad_level_calls.h"/* popmenu and error */
84 #include "BKE_bmesh.h"
85 #include "BKE_context.h"
86 #include "BKE_constraint.h"
87 #include "BKE_global.h"
88 #include "BKE_particle.h"
89 #include "BKE_pointcache.h"
90 #include "BKE_utildefines.h"
91 #include "BKE_context.h"
93 //#include "BSE_drawipo.h"
94 //#include "BSE_editnla_types.h" /* for NLAWIDTH */
95 //#include "BSE_editaction_types.h"
96 //#include "BSE_time.h"
97 //#include "BSE_view.h"
99 #include "ED_view3d.h"
100 #include "ED_screen.h"
102 #include "UI_view2d.h"
103 #include "WM_types.h"
105 #include "BLI_arithb.h"
106 #include "BLI_blenlib.h"
107 #include "BLI_editVert.h"
109 #include "PIL_time.h" /* sleep */
111 //#include "blendef.h"
113 //#include "mydevice.h"
115 #include "transform.h"
117 /******************************** Helper functions ************************************/
119 /* GLOBAL Wrapper Fonctions */
121 //void BIF_drawSnap()
123 // drawSnapping(&Trans);
126 /* ************************** Dashed help line **************************** */
129 /* bad frontbuffer call... because it is used in transform after force_draw() */
130 static void helpline(TransInfo *t, float *vec)
132 #if 0 // TRANSFORM_FIX_ME
133 float vecrot[3], cent[2];
136 VECCOPY(vecrot, vec);
137 if(t->flag & T_EDIT) {
138 Object *ob= t->obedit;
139 if(ob) Mat4MulVecfl(ob->obmat, vecrot);
141 else if(t->flag & T_POSE) {
142 Object *ob=t->poseobj;
143 if(ob) Mat4MulVecfl(ob->obmat, vecrot);
146 getmouseco_areawin(mval);
147 projectFloatView(t, vecrot, cent); // no overflow in extreme cases
151 glDrawBuffer(GL_FRONT);
153 BIF_ThemeColor(TH_WIRE);
156 glBegin(GL_LINE_STRIP);
163 bglFlush(); // flush display for frontbuffer
164 glDrawBuffer(GL_BACK);
168 /* ************************** SPACE DEPENDANT CODE **************************** */
170 void setTransformViewMatrices(TransInfo *t)
172 if(t->spacetype==SPACE_VIEW3D) {
173 View3D *v3d = t->view;
175 Mat4CpyMat4(t->viewmat, v3d->viewmat);
176 Mat4CpyMat4(t->viewinv, v3d->viewinv);
177 Mat4CpyMat4(t->persmat, v3d->persmat);
178 Mat4CpyMat4(t->persinv, v3d->persinv);
179 t->persp = v3d->persp;
186 t->persp = V3D_ORTHO;
189 calculateCenter2D(t);
192 void convertViewVec(TransInfo *t, float *vec, short dx, short dy)
194 if (t->spacetype==SPACE_VIEW3D) {
195 window_to_3d(t->ar, t->view, vec, dx, dy);
197 else if(t->spacetype==SPACE_IMAGE) {
198 View2D *v2d = t->view;
199 float divx, divy, aspx, aspy;
202 //transform_aspect_ratio_tface_uv(&aspx, &aspy);
205 divx= v2d->mask.xmax-v2d->mask.xmin;
206 divy= v2d->mask.ymax-v2d->mask.ymin;
208 vec[0]= aspx*(v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx;
209 vec[1]= aspy*(v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy;
212 else if(t->spacetype==SPACE_IPO) {
213 View2D *v2d = t->view;
216 divx= v2d->mask.xmax-v2d->mask.xmin;
217 divy= v2d->mask.ymax-v2d->mask.ymin;
219 vec[0]= (v2d->cur.xmax-v2d->cur.xmin)*(dx) / (divx);
220 vec[1]= (v2d->cur.ymax-v2d->cur.ymin)*(dy) / (divy);
223 else if(t->spacetype==SPACE_NODE) {
224 View2D *v2d = &t->ar->v2d;
227 divx= v2d->mask.xmax-v2d->mask.xmin;
228 divy= v2d->mask.ymax-v2d->mask.ymin;
230 vec[0]= (v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx;
231 vec[1]= (v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy;
236 void projectIntView(TransInfo *t, float *vec, int *adr)
238 if (t->spacetype==SPACE_VIEW3D) {
239 project_int_noclip(t->ar, t->view, vec, adr);
241 else if(t->spacetype==SPACE_IMAGE) {
242 float aspx, aspy, v[2];
245 //transform_aspect_ratio_tface_uv(&aspx, &aspy);
250 //uvco_to_areaco_noclip(v, adr);
252 else if(t->spacetype==SPACE_IPO) {
253 short out[2] = {0.0f, 0.0f};
255 UI_view2d_view_to_region((View2D *)t->view, vec[0], vec[1], out, out+1);
261 void projectFloatView(TransInfo *t, float *vec, float *adr)
263 if (t->spacetype==SPACE_VIEW3D) {
264 project_float_noclip(t->ar, t->view, vec, adr);
266 else if(t->spacetype==SPACE_IMAGE) {
269 projectIntView(t, vec, a);
273 else if(t->spacetype==SPACE_IPO) {
276 projectIntView(t, vec, a);
282 void convertVecToDisplayNum(float *vec, float *num)
286 #if 0 // TRANSFORM_FIX_ME
287 TransInfo *t = BIF_GetTransInfo();
289 if ((t->spacetype==SPACE_IMAGE) && (t->mode==TFM_TRANSLATION)) {
292 if((G.sima->flag & SI_COORDFLOATS)==0) {
294 transform_width_height_tface_uv(&width, &height);
300 transform_aspect_ratio_tface_uv(&aspx, &aspy);
307 void convertDisplayNumToVec(float *num, float *vec)
311 #if 0 // TRANSFORM_FIX_ME
312 TransInfo *t = BIF_GetTransInfo();
314 if ((t->spacetype==SPACE_IMAGE) && (t->mode==TFM_TRANSLATION)) {
317 if((G.sima->flag & SI_COORDFLOATS)==0) {
319 transform_width_height_tface_uv(&width, &height);
325 transform_aspect_ratio_tface_uv(&aspx, &aspy);
332 static void viewRedrawForce(TransInfo *t)
334 if (t->spacetype == SPACE_VIEW3D)
337 // need to redraw ALL 3d view
338 ED_area_tag_redraw(t->sa);
340 else if (t->spacetype == SPACE_ACTION) {
341 SpaceAction *saction= (SpaceAction *)t->sa->spacedata.first;
348 ED_area_tag_redraw(t->sa);
350 else if(t->spacetype == SPACE_NODE) {
351 ED_area_tag_redraw(t->sa);
353 #if 0 // TRANSFORM_FIX_ME
354 else if (t->spacetype==SPACE_IMAGE) {
355 if (G.sima->lock) force_draw_plus(SPACE_VIEW3D, 0);
358 else if (t->spacetype == SPACE_ACTION) {
359 if (G.saction->lock) {
362 /* we ignore the pointer this function returns (not needed) */
363 get_action_context(&context);
365 if (context == ACTCONT_ACTION)
366 force_draw_plus(SPACE_VIEW3D, 0);
367 else if (context == ACTCONT_SHAPEKEY)
376 else if (t->spacetype == SPACE_NLA) {
382 else if (t->spacetype == SPACE_IPO) {
383 /* update realtime */
385 if (G.sipo->blocktype==ID_MA || G.sipo->blocktype==ID_TE)
386 force_draw_plus(SPACE_BUTS, 0);
387 else if (G.sipo->blocktype==ID_CA)
388 force_draw_plus(SPACE_VIEW3D, 0);
389 else if (G.sipo->blocktype==ID_KE)
390 force_draw_plus(SPACE_VIEW3D, 0);
391 else if (G.sipo->blocktype==ID_PO)
392 force_draw_plus(SPACE_VIEW3D, 0);
393 else if (G.sipo->blocktype==ID_OB)
394 force_draw_plus(SPACE_VIEW3D, 0);
395 else if (G.sipo->blocktype==ID_SEQ)
396 force_draw_plus(SPACE_SEQ, 0);
407 static void viewRedrawPost(TransInfo *t)
409 ED_area_headerprint(t->sa, NULL);
411 #if 0 // TRANSFORM_FIX_ME
412 if(t->spacetype==SPACE_VIEW3D) {
413 allqueue(REDRAWBUTSOBJECT, 0);
414 allqueue(REDRAWVIEW3D, 0);
416 else if(t->spacetype==SPACE_IMAGE) {
417 allqueue(REDRAWIMAGE, 0);
418 allqueue(REDRAWVIEW3D, 0);
420 else if(ELEM3(t->spacetype, SPACE_ACTION, SPACE_NLA, SPACE_IPO)) {
421 allqueue(REDRAWVIEW3D, 0);
422 allqueue(REDRAWACTION, 0);
423 allqueue(REDRAWNLA, 0);
424 allqueue(REDRAWIPO, 0);
425 allqueue(REDRAWTIME, 0);
426 allqueue(REDRAWBUTSOBJECT, 0);
429 scrarea_queue_headredraw(curarea);
433 /* ************************** TRANSFORMATIONS **************************** */
435 void BIF_selectOrientation() {
436 #if 0 // TRANSFORM_FIX_ME
438 char *str_menu = BIF_menustringTransformOrientation("Orientation");
439 val= pupmenu(str_menu);
448 static void view_editmove(unsigned short event)
450 #if 0 // TRANSFORM_FIX_ME
452 /* Regular: Zoom in */
453 /* Shift: Scroll up */
454 /* Ctrl: Scroll right */
455 /* Alt-Shift: Rotate up */
456 /* Alt-Ctrl: Rotate right */
458 /* only work in 3D window for now
459 * In the end, will have to send to event to a 2D window handler instead
461 if (Trans.flag & T_2D_EDIT)
467 if( G.qual & LR_SHIFTKEY ) {
468 if( G.qual & LR_ALTKEY ) {
469 G.qual &= ~LR_SHIFTKEY;
471 G.qual |= LR_SHIFTKEY;
475 } else if( G.qual & LR_CTRLKEY ) {
476 if( G.qual & LR_ALTKEY ) {
477 G.qual &= ~LR_CTRLKEY;
479 G.qual |= LR_CTRLKEY;
483 } else if(U.uiflag & USER_WHEELZOOMDIR)
484 persptoetsen(PADMINUS);
486 persptoetsen(PADPLUSKEY);
491 if( G.qual & LR_SHIFTKEY ) {
492 if( G.qual & LR_ALTKEY ) {
493 G.qual &= ~LR_SHIFTKEY;
495 G.qual |= LR_SHIFTKEY;
499 } else if( G.qual & LR_CTRLKEY ) {
500 if( G.qual & LR_ALTKEY ) {
501 G.qual &= ~LR_CTRLKEY;
503 G.qual |= LR_CTRLKEY;
507 } else if(U.uiflag & USER_WHEELZOOMDIR)
508 persptoetsen(PADPLUSKEY);
510 persptoetsen(PADMINUS);
517 setTransformViewMatrices(&Trans);
521 static char *transform_to_undostr(TransInfo *t)
524 case TFM_TRANSLATION:
536 case TFM_SHRINKFATTEN:
537 return "Shrink/Fatten";
547 return "Bevel Weight";
552 case TFM_BONE_ENVELOPE:
553 return "Bone Envelope";
554 case TFM_TIME_TRANSLATE:
555 return "Translate Anim. Data";
557 return "Scale Anim. Data";
568 /* ************************************************* */
570 void transformEvent(TransInfo *t, wmEvent *event)
572 float mati[3][3] = {{1.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 1.0f}};
573 char cmode = constraintModeToChar(t);
575 t->redraw |= handleMouseInput(t, &t->mouse, event);
577 if (event->type == MOUSEMOVE)
579 t->mval[0] = event->x - t->ar->winrct.xmin;
580 t->mval[1] = event->y - t->ar->winrct.ymin;
584 applyMouseInput(t, &t->mouse, t->mval, t->values);
588 switch (event->type){
589 /* enforce redraw of transform when modifiers are used */
592 t->modifiers |= MOD_SNAP_GEARS;
598 t->modifiers |= MOD_CONSTRAINT_PLANE;
603 if ((t->spacetype==SPACE_VIEW3D) && event->alt) {
604 #if 0 // TRANSFORM_FIX_ME
608 BIF_selectOrientation();
609 calc_manipulator_stats(curarea);
610 Mat3CpyMat4(t->spacemtx, G.vd->twmat);
611 warp_pointer(mval[0], mval[1]);
615 t->state = TRANS_CONFIRM;
620 if ((t->flag & T_NO_CONSTRAINT)==0) {
621 /* exception for switching to dolly, or trackball, in camera view */
622 if (t->flag & T_CAMERA) {
623 if (t->mode==TFM_TRANSLATION)
624 setLocalConstraint(t, (CON_AXIS2), "along local Z");
625 else if (t->mode==TFM_ROTATION) {
626 restoreTransObjects(t);
631 t->modifiers |= MOD_CONSTRAINT_SELECT;
632 if (t->con.mode & CON_APPLY) {
637 initSelectConstraint(t, t->spacemtx);
640 /* bit hackish... but it prevents mmb select to print the orientation from menu */
641 strcpy(t->spacename, "global");
642 initSelectConstraint(t, mati);
644 postSelectConstraint(t);
652 printf("cancelled\n");
653 t->state = TRANS_CANCEL;
658 t->state = TRANS_CONFIRM;
661 /* only switch when... */
662 if( ELEM3(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL) ) {
663 resetTransRestrictions(t);
664 restoreTransObjects(t);
670 /* only switch when... */
671 if( ELEM3(t->mode, TFM_ROTATION, TFM_TRANSLATION, TFM_TRACKBALL) ) {
672 resetTransRestrictions(t);
673 restoreTransObjects(t);
679 /* only switch when... */
680 if( ELEM4(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL, TFM_TRANSLATION) ) {
682 resetTransRestrictions(t);
684 if (t->mode == TFM_ROTATION) {
685 restoreTransObjects(t);
689 restoreTransObjects(t);
697 t->flag ^= T_PROP_CONNECTED;
698 sort_trans_data_dist(t);
699 calculatePropRatio(t);
708 if ((t->flag & T_NO_CONSTRAINT)==0) {
710 if (t->flag & T_2D_EDIT) {
714 if (t->con.mode & CON_USER) {
718 if (event->keymodifier == 0)
719 setUserConstraint(t, (CON_AXIS0), "along %s X");
720 else if (event->keymodifier == KM_SHIFT)
721 setUserConstraint(t, (CON_AXIS1|CON_AXIS2), "locking %s X");
726 if (t->flag & T_2D_EDIT) {
727 setConstraint(t, mati, (CON_AXIS0), "along X axis");
730 if (event->keymodifier == 0)
731 setConstraint(t, mati, (CON_AXIS0), "along global X");
732 else if (event->keymodifier == KM_SHIFT)
733 setConstraint(t, mati, (CON_AXIS1|CON_AXIS2), "locking global X");
740 if ((t->flag & T_NO_CONSTRAINT)==0) {
742 if (t->flag & T_2D_EDIT) {
746 if (t->con.mode & CON_USER) {
750 if (event->keymodifier == 0)
751 setUserConstraint(t, (CON_AXIS1), "along %s Y");
752 else if (event->keymodifier == KM_SHIFT)
753 setUserConstraint(t, (CON_AXIS0|CON_AXIS2), "locking %s Y");
758 if (t->flag & T_2D_EDIT) {
759 setConstraint(t, mati, (CON_AXIS1), "along Y axis");
762 if (event->keymodifier == 0)
763 setConstraint(t, mati, (CON_AXIS1), "along global Y");
764 else if (event->keymodifier == KM_SHIFT)
765 setConstraint(t, mati, (CON_AXIS0|CON_AXIS2), "locking global Y");
772 if ((t->flag & T_NO_CONSTRAINT)==0) {
774 if (t->con.mode & CON_USER) {
778 if (event->keymodifier == 0)
779 setUserConstraint(t, (CON_AXIS2), "along %s Z");
780 else if ((event->keymodifier == KM_SHIFT) && ((t->flag & T_2D_EDIT)==0))
781 setUserConstraint(t, (CON_AXIS0|CON_AXIS1), "locking %s Z");
784 else if ((t->flag & T_2D_EDIT)==0) {
785 if (event->keymodifier == 0)
786 setConstraint(t, mati, (CON_AXIS2), "along global Z");
787 else if (event->keymodifier == KM_SHIFT)
788 setConstraint(t, mati, (CON_AXIS0|CON_AXIS1), "locking global Z");
794 if (t->flag & T_PROP_EDIT && event->keymodifier == KM_SHIFT) {
795 G.scene->prop_mode = (G.scene->prop_mode+1)%6;
796 calculatePropRatio(t);
801 if(event->keymodifier & KM_ALT && t->flag & T_PROP_EDIT) {
803 calculatePropRatio(t);
809 if (t->flag & T_AUTOIK) {
810 transform_autoik_update(t, 1);
812 else if(t->flag & T_PROP_EDIT) {
814 calculatePropRatio(t);
816 else view_editmove(event->type);
820 if(event->keymodifier & KM_ALT && t->flag & T_PROP_EDIT) {
821 t->propsize*= 0.90909090f;
822 calculatePropRatio(t);
828 if (t->flag & T_AUTOIK) {
829 transform_autoik_update(t, -1);
831 else if (t->flag & T_PROP_EDIT) {
832 t->propsize*= 0.90909090f;
833 calculatePropRatio(t);
835 else view_editmove(event->type);
843 // Numerical input events
844 t->redraw |= handleNumInput(&(t->num), event);
847 switch(handleNDofInput(&(t->ndof), event))
850 if ((t->options & CTX_NDOF) == 0)
852 /* Confirm on normal transform only */
853 t->state = TRANS_CONFIRM;
857 if (t->options & CTX_NDOF)
859 /* Cancel on pure NDOF transform */
860 t->state = TRANS_CANCEL;
864 /* Otherwise, just redraw, NDof input was cancelled */
869 if (t->options & CTX_NDOF)
871 /* Confirm on pure NDOF transform */
872 t->state = TRANS_CONFIRM;
882 t->redraw |= handleSnapping(t, event);
884 //arrows_move_cursor(event->type);
887 switch (event->type){
890 t->modifiers &= ~MOD_CONSTRAINT_PLANE;
896 t->modifiers &= ~MOD_SNAP_GEARS;
897 /* no redraw on release modifier keys! this makes sure you can assign the 'grid' still
898 after releasing modifer key */
902 if ((t->flag & T_NO_CONSTRAINT)==0) {
903 t->modifiers &= ~MOD_CONSTRAINT_SELECT;
904 postSelectConstraint(t);
910 if (t->options & CTX_TWEAK)
911 t->state = TRANS_CONFIRM;
916 // Per transform event, if present
918 t->redraw |= t->handleEvent(t, event);
921 int calculateTransformCenter(bContext *C, wmEvent *event, int centerMode, float *vec)
923 TransInfo *t = MEM_callocN(sizeof(TransInfo), "TransInfo data");
926 t->state = TRANS_RUNNING;
928 t->options = CTX_NONE;
932 initTransInfo(C, t, event); // internal data, mouse, vectors
934 createTransData(C, t); // make TransData structs from selection
936 t->around = centerMode; // override userdefined mode
946 // Copy center from constraint center. Transform center can be local
947 VECCOPY(vec, t->con.center);
952 /* aftertrans does insert ipos and action channels, and clears base flags, doesnt read transdata */
953 special_aftertrans_update(t);
960 void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
962 RNA_int_set(op->ptr, "mode", t->mode);
963 RNA_int_set(op->ptr, "options", t->options);
964 RNA_float_set_array(op->ptr, "values", t->values);
967 void initTransform(bContext *C, TransInfo *t, wmOperator *op, wmEvent *event)
969 int mode = RNA_int_get(op->ptr, "mode");
970 int options = RNA_int_get(op->ptr, "options");
973 /* added initialize, for external calls to set stuff in TransInfo, like undo string */
975 t->state = TRANS_RUNNING;
977 t->options = options;
981 initTransInfo(C, t, event); // internal data, mouse, vectors
983 if(t->spacetype == SPACE_VIEW3D)
985 View3D *v3d = t->view;
986 //calc_manipulator_stats(curarea);
987 Mat3CpyMat4(t->spacemtx, v3d->twmat);
988 Mat3Ortho(t->spacemtx);
991 Mat3One(t->spacemtx);
993 createTransData(C, t); // make TransData structs from selection
995 initSnapping(t); // Initialize snapping data AFTER mode flags
1002 /* EVIL! posemode code can switch translation to rotate when 1 bone is selected. will be removed (ton) */
1003 /* EVIL2: we gave as argument also texture space context bit... was cleared */
1004 /* EVIL3: extend mode for animation editors also switches modes... but is best way to avoid duplicate code */
1007 calculatePropRatio(t);
1010 initMouseInput(t, &t->mouse, t->center2d, t->imval);
1013 case TFM_TRANSLATION:
1031 case TFM_SHRINKFATTEN:
1032 initShrinkFatten(t);
1037 case TFM_CURVE_SHRINKFATTEN:
1038 initCurveShrinkFatten(t);
1050 { /* used for both B-Bone width (bonesize) as for deform-dist (envelope) */
1051 bArmature *arm= t->poseobj->data;
1052 if(arm->drawtype==ARM_ENVELOPE)
1053 initBoneEnvelope(t);
1058 case TFM_BONE_ENVELOPE:
1059 initBoneEnvelope(t);
1064 case TFM_TIME_TRANSLATE:
1065 initTimeTranslate(t);
1067 case TFM_TIME_SLIDE:
1070 case TFM_TIME_SCALE:
1073 case TFM_TIME_EXTEND:
1074 /* now that transdata has been made, do like for TFM_TIME_TRANSLATE */
1075 initTimeTranslate(t);
1094 RNA_float_get_array(op->ptr, "values", values);
1096 /* overwrite initial values if operator supplied a non-null vector */
1097 if (!QuatIsNul(values))
1099 QUATCOPY(t->values, values); /* vec-4 */
1104 void transformApply(TransInfo *t)
1108 if (t->modifiers & MOD_CONSTRAINT_SELECT)
1109 t->con.mode |= CON_SELECT;
1111 selectConstraint(t);
1113 t->transform(t, t->mval); // calls recalcData()
1118 /* If auto confirm is on, break after one pass */
1119 if (t->options & CTX_AUTOCONFIRM)
1121 t->state = TRANS_CONFIRM;
1124 if (BKE_ptcache_get_continue_physics())
1127 //do_screenhandlers(G.curscreen);
1132 int transformEnd(bContext *C, TransInfo *t)
1134 int exit_code = OPERATOR_RUNNING_MODAL;
1136 if (t->state != TRANS_RUNNING)
1138 /* handle restoring objects */
1139 if(t->state == TRANS_CANCEL)
1141 exit_code = OPERATOR_CANCELLED;
1142 restoreTransObjects(t); // calls recalcData()
1146 exit_code = OPERATOR_FINISHED;
1152 /* aftertrans does insert ipos and action channels, and clears base flags, doesnt read transdata */
1153 special_aftertrans_update(t);
1155 /* send events out for redraws */
1158 /* Undo as last, certainly after special_trans_update! */
1160 if(t->state == TRANS_CANCEL) {
1161 if(t->undostr) ED_undo_push(C, t->undostr);
1164 if(t->undostr) ED_undo_push(C, t->undostr);
1165 else ED_undo_push(C, transform_to_undostr(t));
1173 /* ************************** Manipulator init and main **************************** */
1175 void initManipulator(int mode)
1177 #if 0 // TRANSFORM_FIX_ME
1178 Trans.state = TRANS_RUNNING;
1180 Trans.options = CTX_NONE;
1184 /* automatic switch to scaling bone envelopes */
1185 if(mode==TFM_RESIZE && t->obedit && t->obedit->type==OB_ARMATURE) {
1186 bArmature *arm= t->obedit->data;
1187 if(arm->drawtype==ARM_ENVELOPE)
1188 mode= TFM_BONE_ENVELOPE;
1191 initTrans(&Trans); // internal data, mouse, vectors
1193 G.moving |= G_TRANSFORM_MANIP; // signal to draw manipuls while transform
1194 createTransData(&Trans); // make TransData structs from selection
1196 if (Trans.total == 0)
1199 initSnapping(&Trans); // Initialize snapping data AFTER mode flags
1201 /* EVIL! posemode code can switch translation to rotate when 1 bone is selected. will be removed (ton) */
1202 /* EVIL2: we gave as argument also texture space context bit... was cleared */
1205 calculatePropRatio(&Trans);
1206 calculateCenter(&Trans);
1209 case TFM_TRANSLATION:
1210 initTranslation(&Trans);
1213 initRotation(&Trans);
1219 initTrackball(&Trans);
1223 Trans.flag |= T_USES_MANIPULATOR;
1227 void ManipulatorTransform()
1229 #if 0 // TRANSFORM_FIX_ME
1230 int mouse_moved = 0;
1231 short pmval[2] = {0, 0}, mval[2], val;
1232 unsigned short event;
1234 if (Trans.total == 0)
1237 Trans.redraw = 1; /* initial draw */
1239 while (Trans.state == TRANS_RUNNING) {
1241 getmouseco_areawin(mval);
1243 if (mval[0] != pmval[0] || mval[1] != pmval[1]) {
1250 //selectConstraint(&Trans); needed?
1251 if (Trans.transform) {
1252 Trans.transform(&Trans, mval);
1257 /* essential for idling subloop */
1258 if( qtest()==0) PIL_sleep_ms(2);
1261 event= extern_qread(&val);
1268 /* enforce redraw of transform when modifiers are used */
1271 if(val) Trans.redraw = 1;
1275 /* shift is modifier for higher resolution transform, works nice to store this mouse position */
1277 getmouseco_areawin(Trans.shiftmval);
1278 Trans.flag |= T_SHIFT_MOD;
1281 else Trans.flag &= ~T_SHIFT_MOD;
1286 Trans.state = TRANS_CANCEL;
1289 if(mouse_moved==0 && val==0) break;
1290 // else we pass on event to next, which cancels
1294 Trans.state = TRANS_CONFIRM;
1303 if(G.qual & LR_ALTKEY && Trans.flag & T_PROP_EDIT) {
1304 Trans.propsize*= 1.1f;
1305 calculatePropRatio(&Trans);
1310 case WHEELDOWNMOUSE:
1311 if (Trans.flag & T_AUTOIK) {
1312 transform_autoik_update(&Trans, 1);
1314 else if(Trans.flag & T_PROP_EDIT) {
1315 Trans.propsize*= 1.1f;
1316 calculatePropRatio(&Trans);
1318 else view_editmove(event);
1322 if(G.qual & LR_ALTKEY && Trans.flag & T_PROP_EDIT) {
1323 Trans.propsize*= 0.90909090f;
1324 calculatePropRatio(&Trans);
1330 if (Trans.flag & T_AUTOIK) {
1331 transform_autoik_update(&Trans, -1);
1333 else if (Trans.flag & T_PROP_EDIT) {
1334 Trans.propsize*= 0.90909090f;
1335 calculatePropRatio(&Trans);
1337 else view_editmove(event);
1342 // Numerical input events
1343 Trans.redraw |= handleNumInput(&(Trans.num), event);
1348 if(Trans.state == TRANS_CANCEL) {
1349 restoreTransObjects(&Trans);
1352 /* free data, reset vars */
1355 /* aftertrans does insert ipos and action channels, and clears base flags */
1356 special_aftertrans_update(&Trans);
1358 /* send events out for redraws */
1359 viewRedrawPost(&Trans);
1361 if(Trans.state != TRANS_CANCEL) {
1362 BIF_undo_push(transform_to_undostr(&Trans));
1367 /* ************************** TRANSFORM LOCKS **************************** */
1369 static void protectedTransBits(short protectflag, float *vec)
1371 if(protectflag & OB_LOCK_LOCX)
1373 if(protectflag & OB_LOCK_LOCY)
1375 if(protectflag & OB_LOCK_LOCZ)
1379 static void protectedSizeBits(short protectflag, float *size)
1381 if(protectflag & OB_LOCK_SCALEX)
1383 if(protectflag & OB_LOCK_SCALEY)
1385 if(protectflag & OB_LOCK_SCALEZ)
1389 static void protectedRotateBits(short protectflag, float *eul, float *oldeul)
1391 if(protectflag & OB_LOCK_ROTX)
1393 if(protectflag & OB_LOCK_ROTY)
1395 if(protectflag & OB_LOCK_ROTZ)
1399 static void protectedQuaternionBits(short protectflag, float *quat, float *oldquat)
1401 /* quaternions get limited with euler... */
1402 /* this function only does the delta rotation */
1405 float eul[3], oldeul[3], quat1[4];
1407 QUATCOPY(quat1, quat);
1408 QuatToEul(quat, eul);
1409 QuatToEul(oldquat, oldeul);
1411 if(protectflag & OB_LOCK_ROTX)
1413 if(protectflag & OB_LOCK_ROTY)
1415 if(protectflag & OB_LOCK_ROTZ)
1418 EulToQuat(eul, quat);
1419 /* quaternions flip w sign to accumulate rotations correctly */
1420 if( (quat1[0]<0.0f && quat[0]>0.0f) || (quat1[0]>0.0f && quat[0]<0.0f) ) {
1421 QuatMulf(quat, -1.0f);
1426 /* ******************* TRANSFORM LIMITS ********************** */
1428 static void constraintTransLim(TransInfo *t, TransData *td)
1431 bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_LOCLIMIT);
1435 /* Make a temporary bConstraintOb for using these limit constraints
1436 * - they only care that cob->matrix is correctly set ;-)
1437 * - current space should be local
1439 memset(&cob, 0, sizeof(bConstraintOb));
1440 Mat4One(cob.matrix);
1442 TransDataIpokey *tdi= td->tdi;
1443 cob.matrix[3][0]= tdi->locx[0];
1444 cob.matrix[3][1]= tdi->locy[0];
1445 cob.matrix[3][2]= tdi->locz[0];
1448 VECCOPY(cob.matrix[3], td->loc);
1451 /* Evaluate valid constraints */
1452 for (con= td->con; con; con= con->next) {
1455 /* only consider constraint if enabled */
1456 if (con->flag & CONSTRAINT_DISABLE) continue;
1457 if (con->enforce == 0.0f) continue;
1459 /* only use it if it's tagged for this purpose (and the right type) */
1460 if (con->type == CONSTRAINT_TYPE_LOCLIMIT) {
1461 bLocLimitConstraint *data= con->data;
1463 if ((data->flag2 & LIMIT_TRANSFORM)==0)
1466 /* do space conversions */
1467 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1468 /* just multiply by td->mtx (this should be ok) */
1469 Mat4CpyMat4(tmat, cob.matrix);
1470 Mat4MulMat34(cob.matrix, td->mtx, tmat);
1472 else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) {
1473 /* skip... incompatable spacetype */
1478 cti->evaluate_constraint(con, &cob, NULL);
1480 /* convert spaces again */
1481 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1482 /* just multiply by td->mtx (this should be ok) */
1483 Mat4CpyMat4(tmat, cob.matrix);
1484 Mat4MulMat34(cob.matrix, td->smtx, tmat);
1489 /* copy results from cob->matrix */
1491 TransDataIpokey *tdi= td->tdi;
1492 tdi->locx[0]= cob.matrix[3][0];
1493 tdi->locy[0]= cob.matrix[3][1];
1494 tdi->locz[0]= cob.matrix[3][2];
1497 VECCOPY(td->loc, cob.matrix[3]);
1502 static void constraintRotLim(TransInfo *t, TransData *td)
1505 bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_ROTLIMIT);
1509 /* Make a temporary bConstraintOb for using these limit constraints
1510 * - they only care that cob->matrix is correctly set ;-)
1511 * - current space should be local
1513 memset(&cob, 0, sizeof(bConstraintOb));
1514 if (td->flag & TD_USEQUAT) {
1517 QuatToMat4(td->ext->quat, cob.matrix);
1522 /* ipo-keys eulers */
1523 TransDataIpokey *tdi= td->tdi;
1526 eul[0]= tdi->rotx[0];
1527 eul[1]= tdi->roty[0];
1528 eul[2]= tdi->rotz[0];
1530 EulToMat4(eul, cob.matrix);
1535 EulToMat4(td->ext->rot, cob.matrix);
1540 /* Evaluate valid constraints */
1541 for (con= td->con; con; con= con->next) {
1542 /* only consider constraint if enabled */
1543 if (con->flag & CONSTRAINT_DISABLE) continue;
1544 if (con->enforce == 0.0f) continue;
1546 /* we're only interested in Limit-Rotation constraints */
1547 if (con->type == CONSTRAINT_TYPE_ROTLIMIT) {
1548 bRotLimitConstraint *data= con->data;
1551 /* only use it if it's tagged for this purpose */
1552 if ((data->flag2 & LIMIT_TRANSFORM)==0)
1555 /* do space conversions */
1556 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1557 /* just multiply by td->mtx (this should be ok) */
1558 Mat4CpyMat4(tmat, cob.matrix);
1559 Mat4MulMat34(cob.matrix, td->mtx, tmat);
1561 else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) {
1562 /* skip... incompatable spacetype */
1567 cti->evaluate_constraint(con, &cob, NULL);
1569 /* convert spaces again */
1570 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1571 /* just multiply by td->mtx (this should be ok) */
1572 Mat4CpyMat4(tmat, cob.matrix);
1573 Mat4MulMat34(cob.matrix, td->smtx, tmat);
1578 /* copy results from cob->matrix */
1579 if (td->flag & TD_USEQUAT) {
1581 Mat4ToQuat(cob.matrix, td->ext->quat);
1584 /* ipo-keys eulers */
1585 TransDataIpokey *tdi= td->tdi;
1588 Mat4ToEul(cob.matrix, eul);
1590 tdi->rotx[0]= eul[0];
1591 tdi->roty[0]= eul[1];
1592 tdi->rotz[0]= eul[2];
1596 Mat4ToEul(cob.matrix, td->ext->rot);
1601 static void constraintSizeLim(TransInfo *t, TransData *td)
1603 if (td->con && td->ext) {
1604 bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_SIZELIMIT);
1608 /* Make a temporary bConstraintOb for using these limit constraints
1609 * - they only care that cob->matrix is correctly set ;-)
1610 * - current space should be local
1612 memset(&cob, 0, sizeof(bConstraintOb));
1614 TransDataIpokey *tdi= td->tdi;
1617 size[0]= tdi->sizex[0];
1618 size[1]= tdi->sizey[0];
1619 size[2]= tdi->sizez[0];
1620 SizeToMat4(size, cob.matrix);
1622 else if ((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)) {
1623 /* scale val and reset size */
1624 return; // TODO: fix this case
1627 /* Reset val if SINGLESIZE but using a constraint */
1628 if (td->flag & TD_SINGLESIZE)
1631 SizeToMat4(td->ext->size, cob.matrix);
1634 /* Evaluate valid constraints */
1635 for (con= td->con; con; con= con->next) {
1636 /* only consider constraint if enabled */
1637 if (con->flag & CONSTRAINT_DISABLE) continue;
1638 if (con->enforce == 0.0f) continue;
1640 /* we're only interested in Limit-Scale constraints */
1641 if (con->type == CONSTRAINT_TYPE_SIZELIMIT) {
1642 bSizeLimitConstraint *data= con->data;
1645 /* only use it if it's tagged for this purpose */
1646 if ((data->flag2 & LIMIT_TRANSFORM)==0)
1649 /* do space conversions */
1650 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1651 /* just multiply by td->mtx (this should be ok) */
1652 Mat4CpyMat4(tmat, cob.matrix);
1653 Mat4MulMat34(cob.matrix, td->mtx, tmat);
1655 else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) {
1656 /* skip... incompatable spacetype */
1661 cti->evaluate_constraint(con, &cob, NULL);
1663 /* convert spaces again */
1664 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1665 /* just multiply by td->mtx (this should be ok) */
1666 Mat4CpyMat4(tmat, cob.matrix);
1667 Mat4MulMat34(cob.matrix, td->smtx, tmat);
1672 /* copy results from cob->matrix */
1674 TransDataIpokey *tdi= td->tdi;
1677 Mat4ToSize(cob.matrix, size);
1679 tdi->sizex[0]= size[0];
1680 tdi->sizey[0]= size[1];
1681 tdi->sizez[0]= size[2];
1683 else if ((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)) {
1684 /* scale val and reset size */
1685 return; // TODO: fix this case
1688 /* Reset val if SINGLESIZE but using a constraint */
1689 if (td->flag & TD_SINGLESIZE)
1692 Mat4ToSize(cob.matrix, td->ext->size);
1697 /* ************************** WARP *************************** */
1699 void initWarp(TransInfo *t)
1701 float max[3], min[3];
1705 t->transform = Warp;
1706 t->handleEvent = handleEventWarp;
1708 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_RATIO);
1716 t->flag |= T_NO_CONSTRAINT;
1718 /* we need min/max in view space */
1719 for(i = 0; i < t->total; i++) {
1721 VECCOPY(center, t->data[i].center);
1722 Mat3MulVecfl(t->data[i].mtx, center);
1723 Mat4MulVecfl(t->viewmat, center);
1724 VecSubf(center, center, t->viewmat[3]);
1726 MinMax3(min, max, center);
1728 VECCOPY(max, center);
1729 VECCOPY(min, center);
1733 t->center[0]= (min[0]+max[0])/2.0f;
1734 t->center[1]= (min[1]+max[1])/2.0f;
1735 t->center[2]= (min[2]+max[2])/2.0f;
1737 if (max[0] == min[0]) max[0] += 0.1; /* not optimal, but flipping is better than invalid garbage (i.e. division by zero!) */
1738 t->val= (max[0]-min[0])/2.0f; /* t->val is X dimension projected boundbox */
1741 int handleEventWarp(TransInfo *t, wmEvent *event)
1745 if (event->type == MIDDLEMOUSE && event->val)
1747 // Use customData pointer to signal warp direction
1748 if (t->customData == 0)
1749 t->customData = (void*)1;
1759 int Warp(TransInfo *t, short mval[2])
1761 TransData *td = t->data;
1762 float vec[3], circumfac, dist, phi0, co, si, *curs, cursor[3], gcursor[3];
1766 curs= give_cursor(t->scene, t->view);
1768 * gcursor is the one used for helpline.
1769 * It has to be in the same space as the drawing loop
1770 * (that means it needs to be in the object's space when in edit mode and
1771 * in global space in object mode)
1773 * cursor is used for calculations.
1774 * It needs to be in view space, but we need to take object's offset
1775 * into account if in Edit mode.
1777 VECCOPY(cursor, curs);
1778 VECCOPY(gcursor, cursor);
1779 if (t->flag & T_EDIT) {
1780 VecSubf(cursor, cursor, t->obedit->obmat[3]);
1781 VecSubf(gcursor, gcursor, t->obedit->obmat[3]);
1782 Mat3MulVecfl(t->data->smtx, gcursor);
1784 Mat4MulVecfl(t->viewmat, cursor);
1785 VecSubf(cursor, cursor, t->viewmat[3]);
1787 /* amount of degrees for warp */
1788 circumfac = 360.0f * t->values[0];
1790 if (t->customData) /* non-null value indicates reversed input */
1795 snapGrid(t, &circumfac);
1796 applyNumInput(&t->num, &circumfac);
1798 /* header print for NumInput */
1799 if (hasNumInput(&t->num)) {
1802 outputNumInput(&(t->num), c);
1804 sprintf(str, "Warp: %s", c);
1807 /* default header print */
1808 sprintf(str, "Warp: %.3f", circumfac);
1811 circumfac*= (float)(-M_PI/360.0);
1813 for(i = 0; i < t->total; i++, td++) {
1815 if (td->flag & TD_NOACTION)
1818 if (td->flag & TD_SKIP)
1821 /* translate point to center, rotate in such a way that outline==distance */
1822 VECCOPY(vec, td->iloc);
1823 Mat3MulVecfl(td->mtx, vec);
1824 Mat4MulVecfl(t->viewmat, vec);
1825 VecSubf(vec, vec, t->viewmat[3]);
1827 dist= vec[0]-cursor[0];
1829 /* t->val is X dimension projected boundbox */
1830 phi0= (circumfac*dist/t->val);
1832 vec[1]= (vec[1]-cursor[1]);
1834 co= (float)cos(phi0);
1835 si= (float)sin(phi0);
1836 loc[0]= -si*vec[1]+cursor[0];
1837 loc[1]= co*vec[1]+cursor[1];
1840 Mat4MulVecfl(t->viewinv, loc);
1841 VecSubf(loc, loc, t->viewinv[3]);
1842 Mat3MulVecfl(td->smtx, loc);
1844 VecSubf(loc, loc, td->iloc);
1845 VecMulf(loc, td->factor);
1846 VecAddf(td->loc, td->iloc, loc);
1851 ED_area_headerprint(t->sa, str);
1855 helpline(t, gcursor);
1860 /* ************************** SHEAR *************************** */
1862 void initShear(TransInfo *t)
1864 t->mode = TFM_SHEAR;
1865 t->transform = Shear;
1866 t->handleEvent = handleEventShear;
1868 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_ABSOLUTE);
1874 t->snap[2] = t->snap[1] * 0.1f;
1876 t->flag |= T_NO_CONSTRAINT;
1879 int handleEventShear(TransInfo *t, wmEvent *event)
1883 if (event->type == MIDDLEMOUSE && event->val)
1885 // Use customData pointer to signal Shear direction
1886 if (t->customData == 0)
1888 initMouseInputMode(t, &t->mouse, INPUT_VERTICAL_ABSOLUTE);
1889 t->customData = (void*)1;
1893 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_ABSOLUTE);
1904 int Shear(TransInfo *t, short mval[2])
1906 TransData *td = t->data;
1908 float smat[3][3], tmat[3][3], totmat[3][3], persmat[3][3], persinv[3][3];
1913 Mat3CpyMat4(persmat, t->viewmat);
1914 Mat3Inv(persinv, persmat);
1916 value = 0.05f * t->values[0];
1918 snapGrid(t, &value);
1920 applyNumInput(&t->num, &value);
1922 /* header print for NumInput */
1923 if (hasNumInput(&t->num)) {
1926 outputNumInput(&(t->num), c);
1928 sprintf(str, "Shear: %s %s", c, t->proptext);
1931 /* default header print */
1932 sprintf(str, "Shear: %.3f %s", value, t->proptext);
1937 // Custom data signals shear direction
1938 if (t->customData == 0)
1943 Mat3MulMat3(tmat, smat, persmat);
1944 Mat3MulMat3(totmat, persinv, tmat);
1946 for(i = 0 ; i < t->total; i++, td++) {
1947 if (td->flag & TD_NOACTION)
1950 if (td->flag & TD_SKIP)
1955 Mat3MulMat3(mat3, totmat, td->mtx);
1956 Mat3MulMat3(tmat, td->smtx, mat3);
1959 Mat3CpyMat3(tmat, totmat);
1961 VecSubf(vec, td->center, t->center);
1963 Mat3MulVecfl(tmat, vec);
1965 VecAddf(vec, vec, t->center);
1966 VecSubf(vec, vec, td->center);
1968 VecMulf(vec, td->factor);
1970 VecAddf(td->loc, td->iloc, vec);
1975 ED_area_headerprint(t->sa, str);
1979 helpline (t, t->center);
1984 /* ************************** RESIZE *************************** */
1986 void initResize(TransInfo *t)
1988 t->mode = TFM_RESIZE;
1989 t->transform = Resize;
1991 initMouseInputMode(t, &t->mouse, INPUT_SPRING_FLIP);
1993 t->flag |= T_NULL_ONE;
1994 t->num.flag |= NUM_NULL_ONE;
1995 t->num.flag |= NUM_AFFECT_ALL;
1997 t->flag |= T_NO_ZERO;
1998 t->num.flag |= NUM_NO_ZERO;
2005 t->snap[2] = t->snap[1] * 0.1f;
2008 static void headerResize(TransInfo *t, float vec[3], char *str) {
2010 if (hasNumInput(&t->num)) {
2011 outputNumInput(&(t->num), tvec);
2014 sprintf(&tvec[0], "%.4f", vec[0]);
2015 sprintf(&tvec[20], "%.4f", vec[1]);
2016 sprintf(&tvec[40], "%.4f", vec[2]);
2019 if (t->con.mode & CON_APPLY) {
2020 switch(t->num.idx_max) {
2022 sprintf(str, "Scale: %s%s %s", &tvec[0], t->con.text, t->proptext);
2025 sprintf(str, "Scale: %s : %s%s %s", &tvec[0], &tvec[20], t->con.text, t->proptext);
2028 sprintf(str, "Scale: %s : %s : %s%s %s", &tvec[0], &tvec[20], &tvec[40], t->con.text, t->proptext);
2032 if (t->flag & T_2D_EDIT)
2033 sprintf(str, "Scale X: %s Y: %s%s %s", &tvec[0], &tvec[20], t->con.text, t->proptext);
2035 sprintf(str, "Scale X: %s Y: %s Z: %s%s %s", &tvec[0], &tvec[20], &tvec[40], t->con.text, t->proptext);
2039 #define SIGN(a) (a<-FLT_EPSILON?1:a>FLT_EPSILON?2:3)
2040 #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)
2042 /* smat is reference matrix, only scaled */
2043 static void TransMat3ToSize( float mat[][3], float smat[][3], float *size)
2047 VecCopyf(vec, mat[0]);
2048 size[0]= Normalize(vec);
2049 VecCopyf(vec, mat[1]);
2050 size[1]= Normalize(vec);
2051 VecCopyf(vec, mat[2]);
2052 size[2]= Normalize(vec);
2054 /* first tried with dotproduct... but the sign flip is crucial */
2055 if( VECSIGNFLIP(mat[0], smat[0]) ) size[0]= -size[0];
2056 if( VECSIGNFLIP(mat[1], smat[1]) ) size[1]= -size[1];
2057 if( VECSIGNFLIP(mat[2], smat[2]) ) size[2]= -size[2];
2061 static void ElementResize(TransInfo *t, TransData *td, float mat[3][3]) {
2062 float tmat[3][3], smat[3][3], center[3];
2065 if (t->flag & T_EDIT) {
2066 Mat3MulMat3(smat, mat, td->mtx);
2067 Mat3MulMat3(tmat, td->smtx, smat);
2070 Mat3CpyMat3(tmat, mat);
2073 if (t->con.applySize) {
2074 t->con.applySize(t, td, tmat);
2077 /* local constraint shouldn't alter center */
2078 if (t->around == V3D_LOCAL) {
2079 if (t->flag & T_OBJECT) {
2080 VECCOPY(center, td->center);
2082 else if (t->flag & T_EDIT) {
2084 if(t->around==V3D_LOCAL && (G.scene->selectmode & SCE_SELECT_FACE)) {
2085 VECCOPY(center, td->center);
2088 VECCOPY(center, t->center);
2092 VECCOPY(center, t->center);
2096 VECCOPY(center, t->center);
2102 if (t->flag & (T_OBJECT|T_TEXTURE|T_POSE)) {
2103 float obsizemat[3][3];
2104 // Reorient the size mat to fit the oriented object.
2105 Mat3MulMat3(obsizemat, tmat, td->axismtx);
2106 //printmatrix3("obsizemat", obsizemat);
2107 TransMat3ToSize(obsizemat, td->axismtx, fsize);
2108 //printvecf("fsize", fsize);
2111 Mat3ToSize(tmat, fsize);
2114 protectedSizeBits(td->protectflag, fsize);
2116 if ((t->flag & T_V3D_ALIGN)==0) { // align mode doesn't resize objects itself
2117 /* handle ipokeys? */
2119 TransDataIpokey *tdi= td->tdi;
2120 /* calculate delta size (equal for size and dsize) */
2122 vec[0]= (tdi->oldsize[0])*(fsize[0] -1.0f) * td->factor;
2123 vec[1]= (tdi->oldsize[1])*(fsize[1] -1.0f) * td->factor;
2124 vec[2]= (tdi->oldsize[2])*(fsize[2] -1.0f) * td->factor;
2126 add_tdi_poin(tdi->sizex, tdi->oldsize, vec[0]);
2127 add_tdi_poin(tdi->sizey, tdi->oldsize+1, vec[1]);
2128 add_tdi_poin(tdi->sizez, tdi->oldsize+2, vec[2]);
2131 else if((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)){
2132 /* scale val and reset size */
2133 *td->val = td->ival * fsize[0] * td->factor;
2135 td->ext->size[0] = td->ext->isize[0];
2136 td->ext->size[1] = td->ext->isize[1];
2137 td->ext->size[2] = td->ext->isize[2];
2140 /* Reset val if SINGLESIZE but using a constraint */
2141 if (td->flag & TD_SINGLESIZE)
2142 *td->val = td->ival;
2144 td->ext->size[0] = td->ext->isize[0] * (fsize[0]) * td->factor;
2145 td->ext->size[1] = td->ext->isize[1] * (fsize[1]) * td->factor;
2146 td->ext->size[2] = td->ext->isize[2] * (fsize[2]) * td->factor;
2150 constraintSizeLim(t, td);
2153 /* For individual element center, Editmode need to use iloc */
2154 if (t->flag & T_POINTS)
2155 VecSubf(vec, td->iloc, center);
2157 VecSubf(vec, td->center, center);
2159 Mat3MulVecfl(tmat, vec);
2161 VecAddf(vec, vec, center);
2162 if (t->flag & T_POINTS)
2163 VecSubf(vec, vec, td->iloc);
2165 VecSubf(vec, vec, td->center);
2167 VecMulf(vec, td->factor);
2169 if (t->flag & (T_OBJECT|T_POSE)) {
2170 Mat3MulVecfl(td->smtx, vec);
2173 protectedTransBits(td->protectflag, vec);
2176 TransDataIpokey *tdi= td->tdi;
2177 add_tdi_poin(tdi->locx, tdi->oldloc, vec[0]);
2178 add_tdi_poin(tdi->locy, tdi->oldloc+1, vec[1]);
2179 add_tdi_poin(tdi->locz, tdi->oldloc+2, vec[2]);
2181 else VecAddf(td->loc, td->iloc, vec);
2183 constraintTransLim(t, td);
2186 int Resize(TransInfo *t, short mval[2])
2189 float size[3], mat[3][3];
2194 /* for manipulator, center handle, the scaling can't be done relative to center */
2195 if( (t->flag & T_USES_MANIPULATOR) && t->con.mode==0)
2197 ratio = 1.0f - ((t->imval[0] - mval[0]) + (t->imval[1] - mval[1]))/100.0f;
2201 ratio = t->values[0];
2204 size[0] = size[1] = size[2] = ratio;
2208 if (hasNumInput(&t->num)) {
2209 applyNumInput(&t->num, size);
2210 constraintNumInput(t, size);
2213 applySnapping(t, size);
2215 SizeToMat3(size, mat);
2217 if (t->con.applySize) {
2218 t->con.applySize(t, NULL, mat);
2221 Mat3CpyMat3(t->mat, mat); // used in manipulator
2223 headerResize(t, size, str);
2225 for(i = 0, td=t->data; i < t->total; i++, td++) {
2226 if (td->flag & TD_NOACTION)
2229 if (td->flag & TD_SKIP)
2232 ElementResize(t, td, mat);
2235 /* evil hack - redo resize if cliping needed */
2236 if (t->flag & T_CLIP_UV && clipUVTransform(t, size, 1)) {
2237 SizeToMat3(size, mat);
2239 if (t->con.applySize)
2240 t->con.applySize(t, NULL, mat);
2242 for(i = 0, td=t->data; i < t->total; i++, td++)
2243 ElementResize(t, td, mat);
2248 ED_area_headerprint(t->sa, str);
2252 if(!(t->flag & T_USES_MANIPULATOR)) helpline (t, t->center);
2257 /* ************************** TOSPHERE *************************** */
2259 void initToSphere(TransInfo *t)
2261 TransData *td = t->data;
2264 t->mode = TFM_TOSPHERE;
2265 t->transform = ToSphere;
2267 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_RATIO);
2273 t->snap[2] = t->snap[1] * 0.1f;
2275 t->num.flag |= NUM_NULL_ONE | NUM_NO_NEGATIVE;
2276 t->flag |= T_NO_CONSTRAINT;
2278 // Calculate average radius
2279 for(i = 0 ; i < t->total; i++, td++) {
2280 t->val += VecLenf(t->center, td->iloc);
2283 t->val /= (float)t->total;
2286 int ToSphere(TransInfo *t, short mval[2])
2289 float ratio, radius;
2292 TransData *td = t->data;
2294 ratio = t->values[0];
2296 snapGrid(t, &ratio);
2298 applyNumInput(&t->num, &ratio);
2305 /* header print for NumInput */
2306 if (hasNumInput(&t->num)) {
2309 outputNumInput(&(t->num), c);
2311 sprintf(str, "To Sphere: %s %s", c, t->proptext);
2314 /* default header print */
2315 sprintf(str, "To Sphere: %.4f %s", ratio, t->proptext);
2319 for(i = 0 ; i < t->total; i++, td++) {
2321 if (td->flag & TD_NOACTION)
2324 if (td->flag & TD_SKIP)
2327 VecSubf(vec, td->iloc, t->center);
2329 radius = Normalize(vec);
2331 tratio = ratio * td->factor;
2333 VecMulf(vec, radius * (1.0f - tratio) + t->val * tratio);
2335 VecAddf(td->loc, t->center, vec);
2341 ED_area_headerprint(t->sa, str);
2348 /* ************************** ROTATION *************************** */
2351 void initRotation(TransInfo *t)
2353 t->mode = TFM_ROTATION;
2354 t->transform = Rotation;
2356 initMouseInputMode(t, &t->mouse, INPUT_ANGLE);
2359 /* Scale down and flip input for rotation */
2360 t->ndof.factor[0] = -0.2f;
2365 t->snap[1] = (float)((5.0/180)*M_PI);
2366 t->snap[2] = t->snap[1] * 0.2f;
2368 if (t->flag & T_2D_EDIT)
2369 t->flag |= T_NO_CONSTRAINT;
2372 static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short around) {
2373 float vec[3], totmat[3][3], smat[3][3];
2374 float eul[3], fmat[3][3], quat[4];
2375 float *center = t->center;
2377 /* local constraint shouldn't alter center */
2378 if (around == V3D_LOCAL) {
2379 if (t->flag & (T_OBJECT|T_POSE)) {
2380 center = td->center;
2383 /* !TODO! Make this if not rely on G */
2384 if(around==V3D_LOCAL && (G.scene->selectmode & SCE_SELECT_FACE)) {
2385 center = td->center;
2390 if (t->flag & T_POINTS) {
2391 Mat3MulMat3(totmat, mat, td->mtx);
2392 Mat3MulMat3(smat, td->smtx, totmat);
2394 VecSubf(vec, td->iloc, center);
2395 Mat3MulVecfl(smat, vec);
2397 VecAddf(td->loc, vec, center);
2399 VecSubf(vec,td->loc,td->iloc);
2400 protectedTransBits(td->protectflag, vec);
2401 VecAddf(td->loc, td->iloc, vec);
2403 if(td->flag & TD_USEQUAT) {
2404 Mat3MulSerie(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0);
2405 Mat3ToQuat(fmat, quat); // Actual transform
2408 QuatMul(td->ext->quat, quat, td->ext->iquat);
2410 /* is there a reason not to have this here? -jahka */
2411 protectedQuaternionBits(td->protectflag, td->ext->quat, td->ext->iquat);
2418 * This is some VERY ugly special case to deal with pose mode.
2420 * The problem is that mtx and smtx include each bone orientation.
2422 * That is needed to rotate each bone properly, HOWEVER, to calculate
2423 * the translation component, we only need the actual armature object's
2424 * matrix (and inverse). That is not all though. Once the proper translation
2425 * has been computed, it has to be converted back into the bone's space.
2427 else if (t->flag & T_POSE) {
2428 float pmtx[3][3], imtx[3][3];
2430 // Extract and invert armature object matrix
2431 Mat3CpyMat4(pmtx, t->poseobj->obmat);
2432 Mat3Inv(imtx, pmtx);
2434 if ((td->flag & TD_NO_LOC) == 0)
2436 VecSubf(vec, td->center, center);
2438 Mat3MulVecfl(pmtx, vec); // To Global space
2439 Mat3MulVecfl(mat, vec); // Applying rotation
2440 Mat3MulVecfl(imtx, vec); // To Local space
2442 VecAddf(vec, vec, center);
2443 /* vec now is the location where the object has to be */
2445 VecSubf(vec, vec, td->center); // Translation needed from the initial location
2447 Mat3MulVecfl(pmtx, vec); // To Global space
2448 Mat3MulVecfl(td->smtx, vec);// To Pose space
2450 protectedTransBits(td->protectflag, vec);
2452 VecAddf(td->loc, td->iloc, vec);
2454 constraintTransLim(t, td);
2458 if ((t->flag & T_V3D_ALIGN)==0) { // align mode doesn't rotate objects itself
2459 Mat3MulSerie(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0);
2461 Mat3ToQuat(fmat, quat); // Actual transform
2463 QuatMul(td->ext->quat, quat, td->ext->iquat);
2464 /* this function works on end result */
2465 protectedQuaternionBits(td->protectflag, td->ext->quat, td->ext->iquat);
2467 constraintRotLim(t, td);
2472 if ((td->flag & TD_NO_LOC) == 0)
2475 VecSubf(vec, td->center, center);
2476 Mat3MulVecfl(mat, vec);
2477 VecAddf(vec, vec, center);
2478 /* vec now is the location where the object has to be */
2479 VecSubf(vec, vec, td->center);
2480 Mat3MulVecfl(td->smtx, vec);
2482 protectedTransBits(td->protectflag, vec);
2485 TransDataIpokey *tdi= td->tdi;
2486 add_tdi_poin(tdi->locx, tdi->oldloc, vec[0]);
2487 add_tdi_poin(tdi->locy, tdi->oldloc+1, vec[1]);
2488 add_tdi_poin(tdi->locz, tdi->oldloc+2, vec[2]);
2490 else VecAddf(td->loc, td->iloc, vec);
2494 constraintTransLim(t, td);
2497 if ((t->flag & T_V3D_ALIGN)==0) { // align mode doesn't rotate objects itself
2498 if(td->flag & TD_USEQUAT) {
2499 Mat3MulSerie(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0);
2500 Mat3ToQuat(fmat, quat); // Actual transform
2502 QuatMul(td->ext->quat, quat, td->ext->iquat);
2503 /* this function works on end result */
2504 protectedQuaternionBits(td->protectflag, td->ext->quat, td->ext->iquat);
2509 /* are there ipo keys? */
2511 TransDataIpokey *tdi= td->tdi;
2512 float current_rot[3];
2515 /* current IPO value for compatible euler */
2516 current_rot[0] = (tdi->rotx) ? tdi->rotx[0] : 0.0f;
2517 current_rot[1] = (tdi->roty) ? tdi->roty[0] : 0.0f;
2518 current_rot[2] = (tdi->rotz) ? tdi->rotz[0] : 0.0f;
2519 VecMulf(current_rot, (float)(M_PI_2 / 9.0));
2521 /* calculate the total rotatation in eulers */
2522 VecAddf(eul, td->ext->irot, td->ext->drot);
2523 EulToMat3(eul, obmat);
2524 /* mat = transform, obmat = object rotation */
2525 Mat3MulMat3(fmat, mat, obmat);
2527 Mat3ToCompatibleEul(fmat, eul, current_rot);
2529 /* correct back for delta rot */
2530 if(tdi->flag & TOB_IPODROT) {
2531 VecSubf(rot, eul, td->ext->irot);
2534 VecSubf(rot, eul, td->ext->drot);
2537 VecMulf(rot, (float)(9.0/M_PI_2));
2538 VecSubf(rot, rot, tdi->oldrot);
2540 protectedRotateBits(td->protectflag, rot, tdi->oldrot);
2542 add_tdi_poin(tdi->rotx, tdi->oldrot, rot[0]);
2543 add_tdi_poin(tdi->roty, tdi->oldrot+1, rot[1]);
2544 add_tdi_poin(tdi->rotz, tdi->oldrot+2, rot[2]);
2547 Mat3MulMat3(totmat, mat, td->mtx);
2548 Mat3MulMat3(smat, td->smtx, totmat);
2550 /* calculate the total rotatation in eulers */
2551 VecAddf(eul, td->ext->irot, td->ext->drot); /* we have to correct for delta rot */
2552 EulToMat3(eul, obmat);
2553 /* mat = transform, obmat = object rotation */
2554 Mat3MulMat3(fmat, smat, obmat);
2556 Mat3ToCompatibleEul(fmat, eul, td->ext->rot);
2558 /* correct back for delta rot */
2559 VecSubf(eul, eul, td->ext->drot);
2562 protectedRotateBits(td->protectflag, eul, td->ext->irot);
2563 VECCOPY(td->ext->rot, eul);
2567 constraintRotLim(t, td);
2572 static void applyRotation(TransInfo *t, float angle, float axis[3])
2574 TransData *td = t->data;
2578 VecRotToMat3(axis, angle, mat);
2580 for(i = 0 ; i < t->total; i++, td++) {
2582 if (td->flag & TD_NOACTION)
2585 if (td->flag & TD_SKIP)
2588 if (t->con.applyRot) {
2589 t->con.applyRot(t, td, axis, NULL);
2590 VecRotToMat3(axis, angle * td->factor, mat);
2592 else if (t->flag & T_PROP_EDIT) {
2593 VecRotToMat3(axis, angle * td->factor, mat);
2596 ElementRotation(t, td, mat, t->around);
2600 int Rotation(TransInfo *t, short mval[2])
2609 VECCOPY(axis, t->viewinv[2]);
2610 VecMulf(axis, -1.0f);
2613 final = t->values[0];
2615 applyNDofInput(&t->ndof, &final);
2617 snapGrid(t, &final);
2619 if (t->con.applyRot) {
2620 t->con.applyRot(t, NULL, axis, &final);
2623 applySnapping(t, &final);
2625 if (hasNumInput(&t->num)) {
2628 applyNumInput(&t->num, &final);
2630 outputNumInput(&(t->num), c);
2632 sprintf(str, "Rot: %s %s %s", &c[0], t->con.text, t->proptext);
2634 /* Clamp between -180 and 180 */
2635 while (final >= 180.0)
2638 while (final <= -180.0)
2641 final *= (float)(M_PI / 180.0);
2644 sprintf(str, "Rot: %.2f%s %s", 180.0*final/M_PI, t->con.text, t->proptext);
2647 VecRotToMat3(axis, final, mat);
2650 // t->values[0] = final; // used in manipulator
2651 // Mat3CpyMat3(t->mat, mat); // used in manipulator
2653 applyRotation(t, final, axis);
2657 ED_area_headerprint(t->sa, str);
2661 if(!(t->flag & T_USES_MANIPULATOR)) helpline (t, t->center);
2667 /* ************************** TRACKBALL *************************** */
2669 void initTrackball(TransInfo *t)
2671 t->mode = TFM_TRACKBALL;
2672 t->transform = Trackball;
2674 initMouseInputMode(t, &t->mouse, INPUT_TRACKBALL);
2677 /* Scale down input for rotation */
2678 t->ndof.factor[0] = 0.2f;
2679 t->ndof.factor[1] = 0.2f;
2684 t->snap[1] = (float)((5.0/180)*M_PI);
2685 t->snap[2] = t->snap[1] * 0.2f;
2687 t->flag |= T_NO_CONSTRAINT;
2690 static void applyTrackball(TransInfo *t, float axis1[3], float axis2[3], float angles[2])
2692 TransData *td = t->data;
2693 float mat[3][3], smat[3][3], totmat[3][3];
2696 VecRotToMat3(axis1, angles[0], smat);
2697 VecRotToMat3(axis2, angles[1], totmat);
2699 Mat3MulMat3(mat, smat, totmat);
2701 for(i = 0 ; i < t->total; i++, td++) {
2702 if (td->flag & TD_NOACTION)
2705 if (td->flag & TD_SKIP)
2708 if (t->flag & T_PROP_EDIT) {
2709 VecRotToMat3(axis1, td->factor * angles[0], smat);
2710 VecRotToMat3(axis2, td->factor * angles[1], totmat);
2712 Mat3MulMat3(mat, smat, totmat);
2715 ElementRotation(t, td, mat, t->around);
2719 int Trackball(TransInfo *t, short mval[2])
2722 float axis1[3], axis2[3];
2723 float mat[3][3], totmat[3][3], smat[3][3];
2726 VECCOPY(axis1, t->persinv[0]);
2727 VECCOPY(axis2, t->persinv[1]);
2731 phi[0] = t->values[0];
2732 phi[1] = t->values[1];
2734 applyNDofInput(&t->ndof, phi);
2738 if (hasNumInput(&t->num)) {
2741 applyNumInput(&t->num, phi);
2743 outputNumInput(&(t->num), c);
2745 sprintf(str, "Trackball: %s %s %s", &c[0], &c[20], t->proptext);
2747 phi[0] *= (float)(M_PI / 180.0);
2748 phi[1] *= (float)(M_PI / 180.0);
2751 sprintf(str, "Trackball: %.2f %.2f %s", 180.0*phi[0]/M_PI, 180.0*phi[1]/M_PI, t->proptext);
2754 VecRotToMat3(axis1, phi[0], smat);
2755 VecRotToMat3(axis2, phi[1], totmat);
2757 Mat3MulMat3(mat, smat, totmat);
2760 //Mat3CpyMat3(t->mat, mat); // used in manipulator
2762 applyTrackball(t, axis1, axis2, phi);
2766 ED_area_headerprint(t->sa, str);
2770 if(!(t->flag & T_USES_MANIPULATOR)) helpline (t, t->center);
2775 /* ************************** TRANSLATION *************************** */
2777 void initTranslation(TransInfo *t)
2779 t->mode = TFM_TRANSLATION;
2780 t->transform = Translation;
2782 initMouseInputMode(t, &t->mouse, INPUT_VECTOR);
2784 t->idx_max = (t->flag & T_2D_EDIT)? 1: 2;
2786 t->num.idx_max = t->idx_max;
2788 t->ndof.axis = 1|2|4;
2790 if(t->spacetype == SPACE_VIEW3D) {
2791 View3D *v3d = t->view;
2794 t->snap[1] = v3d->gridview * 1.0f;
2795 t->snap[2] = t->snap[1] * 0.1f;
2797 else if(t->spacetype == SPACE_IMAGE) {
2799 t->snap[1] = 0.125f;
2800 t->snap[2] = 0.0625f;
2804 t->snap[1] = t->snap[2] = 1.0f;
2808 static void headerTranslation(TransInfo *t, float vec[3], char *str) {
2815 convertVecToDisplayNum(vec, dvec);
2817 if (hasNumInput(&t->num)) {
2818 outputNumInput(&(t->num), tvec);
2819 dist = VecLength(t->num.val);
2822 dist = VecLength(vec);
2823 sprintf(&tvec[0], "%.4f", dvec[0]);
2824 sprintf(&tvec[20], "%.4f", dvec[1]);
2825 sprintf(&tvec[40], "%.4f", dvec[2]);
2828 if( dist > 1e10 || dist < -1e10 ) /* prevent string buffer overflow */
2829 sprintf(distvec, "%.4e", dist);
2831 sprintf(distvec, "%.4f", dist);
2833 if(t->flag & T_AUTOIK) {
2834 short chainlen= G.scene->toolsettings->autoik_chainlen;
2837 sprintf(autoik, "AutoIK-Len: %d", chainlen);
2844 if (t->con.mode & CON_APPLY) {
2845 switch(t->num.idx_max) {
2847 sprintf(str, "D: %s (%s)%s %s %s", &tvec[0], distvec, t->con.text, t->proptext, &autoik[0]);
2850 sprintf(str, "D: %s D: %s (%s)%s %s %s", &tvec[0], &tvec[20], distvec, t->con.text, t->proptext, &autoik[0]);
2853 sprintf(str, "D: %s D: %s D: %s (%s)%s %s %s", &tvec[0], &tvec[20], &tvec[40], distvec, t->con.text, t->proptext, &autoik[0]);
2857 if(t->flag & T_2D_EDIT)
2858 sprintf(str, "Dx: %s Dy: %s (%s)%s %s", &tvec[0], &tvec[20], distvec, t->con.text, t->proptext);
2860 sprintf(str, "Dx: %s Dy: %s Dz: %s (%s)%s %s %s", &tvec[0], &tvec[20], &tvec[40], distvec, t->con.text, t->proptext, &autoik[0]);
2864 static void applyTranslation(TransInfo *t, float vec[3]) {
2865 TransData *td = t->data;
2869 for(i = 0 ; i < t->total; i++, td++) {
2870 if (td->flag & TD_NOACTION)
2873 if (td->flag & TD_SKIP)
2876 /* handle snapping rotation before doing the translation */
2877 if (usingSnappingNormal(t))
2879 if (validSnappingNormal(t))
2881 float *original_normal = td->axismtx[2];
2887 Crossf(axis, original_normal, t->tsnap.snapNormal);
2888 angle = saacos(Inpf(original_normal, t->tsnap.snapNormal));
2890 AxisAngleToQuat(quat, axis, angle);
2892 QuatToMat3(quat, mat);
2894 ElementRotation(t, td, mat, V3D_LOCAL);
2902 ElementRotation(t, td, mat, V3D_LOCAL);
2906 if (t->con.applyVec) {
2908 t->con.applyVec(t, td, vec, tvec, pvec);
2914 Mat3MulVecfl(td->smtx, tvec);
2915 VecMulf(tvec, td->factor);
2917 protectedTransBits(td->protectflag, tvec);
2919 /* transdata ipokey */
2921 TransDataIpokey *tdi= td->tdi;
2922 add_tdi_poin(tdi->locx, tdi->oldloc, tvec[0]);
2923 add_tdi_poin(tdi->locy, tdi->oldloc+1, tvec[1]);
2924 add_tdi_poin(tdi->locz, tdi->oldloc+2, tvec[2]);
2926 else VecAddf(td->loc, td->iloc, tvec);
2928 constraintTransLim(t, td);
2932 /* uses t->vec to store actual translation in */
2933 int Translation(TransInfo *t, short mval[2])
2938 if (t->con.mode & CON_APPLY) {
2939 float pvec[3] = {0.0f, 0.0f, 0.0f};
2940 applySnapping(t, t->values);
2941 t->con.applyVec(t, NULL, t->values, tvec, pvec);
2942 VECCOPY(t->values, tvec);
2943 headerTranslation(t, pvec, str);
2946 applyNDofInput(&t->ndof, t->values);
2947 snapGrid(t, t->values);
2948 applyNumInput(&t->num, t->values);
2949 applySnapping(t, t->values);
2950 headerTranslation(t, t->values, str);
2953 applyTranslation(t, t->values);
2955 /* evil hack - redo translation if clipping needed */
2956 if (t->flag & T_CLIP_UV && clipUVTransform(t, t->values, 0))
2957 applyTranslation(t, t->values);
2961 ED_area_headerprint(t->sa, str);
2970 /* ************************** SHRINK/FATTEN *************************** */
2972 void initShrinkFatten(TransInfo *t)
2974 // If not in mesh edit mode, fallback to Resize
2975 if (t->obedit==NULL || t->obedit->type != OB_MESH) {
2979 t->mode = TFM_SHRINKFATTEN;
2980 t->transform = ShrinkFatten;
2982 initMouseInputMode(t, &t->mouse, INPUT_VERTICAL_ABSOLUTE);
2988 t->snap[2] = t->snap[1] * 0.1f;
2990 t->flag |= T_NO_CONSTRAINT;
2996 int ShrinkFatten(TransInfo *t, short mval[2])
3002 TransData *td = t->data;
3004 distance = -t->values[0];
3006 snapGrid(t, &distance);
3008 applyNumInput(&t->num, &distance);
3010 /* header print for NumInput */
3011 if (hasNumInput(&t->num)) {
3014 outputNumInput(&(t->num), c);
3016 sprintf(str, "Shrink/Fatten: %s %s", c, t->proptext);
3019 /* default header print */
3020 sprintf(str, "Shrink/Fatten: %.4f %s", distance, t->proptext);
3024 for(i = 0 ; i < t->total; i++, td++) {
3025 if (td->flag & TD_NOACTION)