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);
225 void projectIntView(TransInfo *t, float *vec, int *adr)
227 if (t->spacetype==SPACE_VIEW3D) {
228 project_int_noclip(t->ar, t->view, vec, adr);
230 else if(t->spacetype==SPACE_IMAGE) {
231 float aspx, aspy, v[2];
234 //transform_aspect_ratio_tface_uv(&aspx, &aspy);
239 //uvco_to_areaco_noclip(v, adr);
241 else if(t->spacetype==SPACE_IPO) {
242 short out[2] = {0.0f, 0.0f};
244 UI_view2d_view_to_region((View2D *)t->view, vec[0], vec[1], out, out+1);
250 void projectFloatView(TransInfo *t, float *vec, float *adr)
252 if (t->spacetype==SPACE_VIEW3D) {
253 project_float_noclip(t->ar, t->view, vec, adr);
255 else if(t->spacetype==SPACE_IMAGE) {
258 projectIntView(t, vec, a);
262 else if(t->spacetype==SPACE_IPO) {
265 projectIntView(t, vec, a);
271 void convertVecToDisplayNum(float *vec, float *num)
275 #if 0 // TRANSFORM_FIX_ME
276 TransInfo *t = BIF_GetTransInfo();
278 if ((t->spacetype==SPACE_IMAGE) && (t->mode==TFM_TRANSLATION)) {
281 if((G.sima->flag & SI_COORDFLOATS)==0) {
283 transform_width_height_tface_uv(&width, &height);
289 transform_aspect_ratio_tface_uv(&aspx, &aspy);
296 void convertDisplayNumToVec(float *num, float *vec)
300 #if 0 // TRANSFORM_FIX_ME
301 TransInfo *t = BIF_GetTransInfo();
303 if ((t->spacetype==SPACE_IMAGE) && (t->mode==TFM_TRANSLATION)) {
306 if((G.sima->flag & SI_COORDFLOATS)==0) {
308 transform_width_height_tface_uv(&width, &height);
314 transform_aspect_ratio_tface_uv(&aspx, &aspy);
321 static void viewRedrawForce(TransInfo *t)
323 if (t->spacetype == SPACE_VIEW3D)
326 // need to redraw ALL 3d view
327 ED_area_tag_redraw(t->sa);
329 else if (t->spacetype == SPACE_ACTION) {
330 SpaceAction *saction= (SpaceAction *)t->sa->spacedata.first;
337 ED_area_tag_redraw(t->sa);
339 else if(t->spacetype == SPACE_NODE) {
340 ED_area_tag_redraw(t->sa);
342 #if 0 // TRANSFORM_FIX_ME
343 else if (t->spacetype==SPACE_IMAGE) {
344 if (G.sima->lock) force_draw_plus(SPACE_VIEW3D, 0);
347 else if (t->spacetype == SPACE_ACTION) {
348 if (G.saction->lock) {
351 /* we ignore the pointer this function returns (not needed) */
352 get_action_context(&context);
354 if (context == ACTCONT_ACTION)
355 force_draw_plus(SPACE_VIEW3D, 0);
356 else if (context == ACTCONT_SHAPEKEY)
365 else if (t->spacetype == SPACE_NLA) {
371 else if (t->spacetype == SPACE_IPO) {
372 /* update realtime */
374 if (G.sipo->blocktype==ID_MA || G.sipo->blocktype==ID_TE)
375 force_draw_plus(SPACE_BUTS, 0);
376 else if (G.sipo->blocktype==ID_CA)
377 force_draw_plus(SPACE_VIEW3D, 0);
378 else if (G.sipo->blocktype==ID_KE)
379 force_draw_plus(SPACE_VIEW3D, 0);
380 else if (G.sipo->blocktype==ID_PO)
381 force_draw_plus(SPACE_VIEW3D, 0);
382 else if (G.sipo->blocktype==ID_OB)
383 force_draw_plus(SPACE_VIEW3D, 0);
384 else if (G.sipo->blocktype==ID_SEQ)
385 force_draw_plus(SPACE_SEQ, 0);
396 static void viewRedrawPost(TransInfo *t)
398 ED_area_headerprint(t->sa, NULL);
400 #if 0 // TRANSFORM_FIX_ME
401 if(t->spacetype==SPACE_VIEW3D) {
402 allqueue(REDRAWBUTSOBJECT, 0);
403 allqueue(REDRAWVIEW3D, 0);
405 else if(t->spacetype==SPACE_IMAGE) {
406 allqueue(REDRAWIMAGE, 0);
407 allqueue(REDRAWVIEW3D, 0);
409 else if(ELEM3(t->spacetype, SPACE_ACTION, SPACE_NLA, SPACE_IPO)) {
410 allqueue(REDRAWVIEW3D, 0);
411 allqueue(REDRAWACTION, 0);
412 allqueue(REDRAWNLA, 0);
413 allqueue(REDRAWIPO, 0);
414 allqueue(REDRAWTIME, 0);
415 allqueue(REDRAWBUTSOBJECT, 0);
418 scrarea_queue_headredraw(curarea);
422 /* ************************** TRANSFORMATIONS **************************** */
424 void BIF_selectOrientation() {
425 #if 0 // TRANSFORM_FIX_ME
427 char *str_menu = BIF_menustringTransformOrientation("Orientation");
428 val= pupmenu(str_menu);
437 static void view_editmove(unsigned short event)
439 #if 0 // TRANSFORM_FIX_ME
441 /* Regular: Zoom in */
442 /* Shift: Scroll up */
443 /* Ctrl: Scroll right */
444 /* Alt-Shift: Rotate up */
445 /* Alt-Ctrl: Rotate right */
447 /* only work in 3D window for now
448 * In the end, will have to send to event to a 2D window handler instead
450 if (Trans.flag & T_2D_EDIT)
456 if( G.qual & LR_SHIFTKEY ) {
457 if( G.qual & LR_ALTKEY ) {
458 G.qual &= ~LR_SHIFTKEY;
460 G.qual |= LR_SHIFTKEY;
464 } else if( G.qual & LR_CTRLKEY ) {
465 if( G.qual & LR_ALTKEY ) {
466 G.qual &= ~LR_CTRLKEY;
468 G.qual |= LR_CTRLKEY;
472 } else if(U.uiflag & USER_WHEELZOOMDIR)
473 persptoetsen(PADMINUS);
475 persptoetsen(PADPLUSKEY);
480 if( G.qual & LR_SHIFTKEY ) {
481 if( G.qual & LR_ALTKEY ) {
482 G.qual &= ~LR_SHIFTKEY;
484 G.qual |= LR_SHIFTKEY;
488 } else if( G.qual & LR_CTRLKEY ) {
489 if( G.qual & LR_ALTKEY ) {
490 G.qual &= ~LR_CTRLKEY;
492 G.qual |= LR_CTRLKEY;
496 } else if(U.uiflag & USER_WHEELZOOMDIR)
497 persptoetsen(PADPLUSKEY);
499 persptoetsen(PADMINUS);
506 setTransformViewMatrices(&Trans);
510 static char *transform_to_undostr(TransInfo *t)
513 case TFM_TRANSLATION:
525 case TFM_SHRINKFATTEN:
526 return "Shrink/Fatten";
536 return "Bevel Weight";
541 case TFM_BONE_ENVELOPE:
542 return "Bone Envelope";
543 case TFM_TIME_TRANSLATE:
544 return "Translate Anim. Data";
546 return "Scale Anim. Data";
553 case TFM_NODE_TRANSLATE:
554 return "Node Translate";
559 /* ************************************************* */
561 void transformEvent(TransInfo *t, wmEvent *event)
563 float mati[3][3] = {{1.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 1.0f}};
564 char cmode = constraintModeToChar(t);
566 t->redraw |= handleMouseInput(t, &t->mouse, event);
568 if (event->type == MOUSEMOVE)
570 t->mval[0] = event->x - t->ar->winrct.xmin;
571 t->mval[1] = event->y - t->ar->winrct.ymin;
575 applyMouseInput(t, &t->mouse, t->mval, t->values);
579 switch (event->type){
580 /* enforce redraw of transform when modifiers are used */
583 t->modifiers |= MOD_SNAP_GEARS;
589 t->modifiers |= MOD_CONSTRAINT_PLANE;
594 if ((t->spacetype==SPACE_VIEW3D) && event->alt) {
595 #if 0 // TRANSFORM_FIX_ME
599 BIF_selectOrientation();
600 calc_manipulator_stats(curarea);
601 Mat3CpyMat4(t->spacemtx, G.vd->twmat);
602 warp_pointer(mval[0], mval[1]);
606 t->state = TRANS_CONFIRM;
611 if ((t->flag & T_NO_CONSTRAINT)==0) {
612 /* exception for switching to dolly, or trackball, in camera view */
613 if (t->flag & T_CAMERA) {
614 if (t->mode==TFM_TRANSLATION)
615 setLocalConstraint(t, (CON_AXIS2), "along local Z");
616 else if (t->mode==TFM_ROTATION) {
617 restoreTransObjects(t);
622 t->modifiers |= MOD_CONSTRAINT_SELECT;
623 if (t->con.mode & CON_APPLY) {
628 initSelectConstraint(t, t->spacemtx);
631 /* bit hackish... but it prevents mmb select to print the orientation from menu */
632 strcpy(t->spacename, "global");
633 initSelectConstraint(t, mati);
635 postSelectConstraint(t);
643 printf("cancelled\n");
644 t->state = TRANS_CANCEL;
649 t->state = TRANS_CONFIRM;
652 /* only switch when... */
653 if( ELEM3(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL) ) {
654 resetTransRestrictions(t);
655 restoreTransObjects(t);
661 /* only switch when... */
662 if( ELEM3(t->mode, TFM_ROTATION, TFM_TRANSLATION, TFM_TRACKBALL) ) {
663 resetTransRestrictions(t);
664 restoreTransObjects(t);
670 /* only switch when... */
671 if( ELEM4(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL, TFM_TRANSLATION) ) {
673 resetTransRestrictions(t);
675 if (t->mode == TFM_ROTATION) {
676 restoreTransObjects(t);
680 restoreTransObjects(t);
688 t->flag ^= T_PROP_CONNECTED;
689 sort_trans_data_dist(t);
690 calculatePropRatio(t);
699 if ((t->flag & T_NO_CONSTRAINT)==0) {
701 if (t->flag & T_2D_EDIT) {
705 if (t->con.mode & CON_USER) {
709 if (event->keymodifier == 0)
710 setUserConstraint(t, (CON_AXIS0), "along %s X");
711 else if (event->keymodifier == KM_SHIFT)
712 setUserConstraint(t, (CON_AXIS1|CON_AXIS2), "locking %s X");
717 if (t->flag & T_2D_EDIT) {
718 setConstraint(t, mati, (CON_AXIS0), "along X axis");
721 if (event->keymodifier == 0)
722 setConstraint(t, mati, (CON_AXIS0), "along global X");
723 else if (event->keymodifier == KM_SHIFT)
724 setConstraint(t, mati, (CON_AXIS1|CON_AXIS2), "locking global X");
731 if ((t->flag & T_NO_CONSTRAINT)==0) {
733 if (t->flag & T_2D_EDIT) {
737 if (t->con.mode & CON_USER) {
741 if (event->keymodifier == 0)
742 setUserConstraint(t, (CON_AXIS1), "along %s Y");
743 else if (event->keymodifier == KM_SHIFT)
744 setUserConstraint(t, (CON_AXIS0|CON_AXIS2), "locking %s Y");
749 if (t->flag & T_2D_EDIT) {
750 setConstraint(t, mati, (CON_AXIS1), "along Y axis");
753 if (event->keymodifier == 0)
754 setConstraint(t, mati, (CON_AXIS1), "along global Y");
755 else if (event->keymodifier == KM_SHIFT)
756 setConstraint(t, mati, (CON_AXIS0|CON_AXIS2), "locking global Y");
763 if ((t->flag & T_NO_CONSTRAINT)==0) {
765 if (t->con.mode & CON_USER) {
769 if (event->keymodifier == 0)
770 setUserConstraint(t, (CON_AXIS2), "along %s Z");
771 else if ((event->keymodifier == KM_SHIFT) && ((t->flag & T_2D_EDIT)==0))
772 setUserConstraint(t, (CON_AXIS0|CON_AXIS1), "locking %s Z");
775 else if ((t->flag & T_2D_EDIT)==0) {
776 if (event->keymodifier == 0)
777 setConstraint(t, mati, (CON_AXIS2), "along global Z");
778 else if (event->keymodifier == KM_SHIFT)
779 setConstraint(t, mati, (CON_AXIS0|CON_AXIS1), "locking global Z");
785 if (t->flag & T_PROP_EDIT && event->keymodifier == KM_SHIFT) {
786 G.scene->prop_mode = (G.scene->prop_mode+1)%6;
787 calculatePropRatio(t);
792 if(event->keymodifier & KM_ALT && t->flag & T_PROP_EDIT) {
794 calculatePropRatio(t);
800 if (t->flag & T_AUTOIK) {
801 transform_autoik_update(t, 1);
803 else if(t->flag & T_PROP_EDIT) {
805 calculatePropRatio(t);
807 else view_editmove(event->type);
811 if(event->keymodifier & KM_ALT && t->flag & T_PROP_EDIT) {
812 t->propsize*= 0.90909090f;
813 calculatePropRatio(t);
819 if (t->flag & T_AUTOIK) {
820 transform_autoik_update(t, -1);
822 else if (t->flag & T_PROP_EDIT) {
823 t->propsize*= 0.90909090f;
824 calculatePropRatio(t);
826 else view_editmove(event->type);
834 // Numerical input events
835 t->redraw |= handleNumInput(&(t->num), event);
838 switch(handleNDofInput(&(t->ndof), event))
841 if ((t->options & CTX_NDOF) == 0)
843 /* Confirm on normal transform only */
844 t->state = TRANS_CONFIRM;
848 if (t->options & CTX_NDOF)
850 /* Cancel on pure NDOF transform */
851 t->state = TRANS_CANCEL;
855 /* Otherwise, just redraw, NDof input was cancelled */
860 if (t->options & CTX_NDOF)
862 /* Confirm on pure NDOF transform */
863 t->state = TRANS_CONFIRM;
873 t->redraw |= handleSnapping(t, event);
875 //arrows_move_cursor(event->type);
878 switch (event->type){
881 t->modifiers &= ~MOD_CONSTRAINT_PLANE;
887 t->modifiers &= ~MOD_SNAP_GEARS;
888 /* no redraw on release modifier keys! this makes sure you can assign the 'grid' still
889 after releasing modifer key */
893 if ((t->flag & T_NO_CONSTRAINT)==0) {
894 t->modifiers &= ~MOD_CONSTRAINT_SELECT;
895 postSelectConstraint(t);
901 if (t->options & CTX_TWEAK)
902 t->state = TRANS_CONFIRM;
907 // Per transform event, if present
909 t->redraw |= t->handleEvent(t, event);
912 int calculateTransformCenter(bContext *C, wmEvent *event, int centerMode, float *vec)
914 TransInfo *t = MEM_callocN(sizeof(TransInfo), "TransInfo data");
917 t->state = TRANS_RUNNING;
919 t->options = CTX_NONE;
923 initTransInfo(C, t, event); // internal data, mouse, vectors
925 createTransData(C, t); // make TransData structs from selection
927 t->around = centerMode; // override userdefined mode
937 // Copy center from constraint center. Transform center can be local
938 VECCOPY(vec, t->con.center);
943 /* aftertrans does insert ipos and action channels, and clears base flags, doesnt read transdata */
944 special_aftertrans_update(t);
951 void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
953 RNA_int_set(op->ptr, "mode", t->mode);
954 RNA_int_set(op->ptr, "options", t->options);
955 RNA_float_set_array(op->ptr, "values", t->values);
958 void initTransform(bContext *C, TransInfo *t, wmOperator *op, wmEvent *event)
960 int mode = RNA_int_get(op->ptr, "mode");
961 int options = RNA_int_get(op->ptr, "options");
964 /* added initialize, for external calls to set stuff in TransInfo, like undo string */
966 t->state = TRANS_RUNNING;
968 t->options = options;
972 initTransInfo(C, t, event); // internal data, mouse, vectors
974 if(t->spacetype == SPACE_VIEW3D)
976 View3D *v3d = t->view;
977 //calc_manipulator_stats(curarea);
978 Mat3CpyMat4(t->spacemtx, v3d->twmat);
979 Mat3Ortho(t->spacemtx);
982 Mat3One(t->spacemtx);
984 createTransData(C, t); // make TransData structs from selection
986 initSnapping(t); // Initialize snapping data AFTER mode flags
993 /* EVIL! posemode code can switch translation to rotate when 1 bone is selected. will be removed (ton) */
994 /* EVIL2: we gave as argument also texture space context bit... was cleared */
995 /* EVIL3: extend mode for animation editors also switches modes... but is best way to avoid duplicate code */
998 calculatePropRatio(t);
1001 initMouseInput(t, &t->mouse, t->center2d, t->imval);
1004 case TFM_TRANSLATION:
1022 case TFM_SHRINKFATTEN:
1023 initShrinkFatten(t);
1028 case TFM_CURVE_SHRINKFATTEN:
1029 initCurveShrinkFatten(t);
1041 { /* used for both B-Bone width (bonesize) as for deform-dist (envelope) */
1042 bArmature *arm= t->poseobj->data;
1043 if(arm->drawtype==ARM_ENVELOPE)
1044 initBoneEnvelope(t);
1049 case TFM_BONE_ENVELOPE:
1050 initBoneEnvelope(t);
1055 case TFM_TIME_TRANSLATE:
1056 initTimeTranslate(t);
1058 case TFM_TIME_SLIDE:
1061 case TFM_TIME_SCALE:
1064 case TFM_TIME_EXTEND:
1065 /* now that transdata has been made, do like for TFM_TIME_TRANSLATE */
1066 initTimeTranslate(t);
1083 case TFM_NODE_TRANSLATE:
1084 initNodeTranslate(t);
1090 RNA_float_get_array(op->ptr, "values", values);
1092 /* overwrite initial values if operator supplied a non-null vector */
1093 if (!QuatIsNul(values))
1095 QUATCOPY(t->values, values); /* vec-4 */
1100 void transformApply(TransInfo *t)
1104 if (t->modifiers & MOD_CONSTRAINT_SELECT)
1105 t->con.mode |= CON_SELECT;
1107 selectConstraint(t);
1109 t->transform(t, t->mval); // calls recalcData()
1114 /* If auto confirm is on, break after one pass */
1115 if (t->options & CTX_AUTOCONFIRM)
1117 t->state = TRANS_CONFIRM;
1120 if (BKE_ptcache_get_continue_physics())
1123 //do_screenhandlers(G.curscreen);
1128 int transformEnd(bContext *C, TransInfo *t)
1130 int exit_code = OPERATOR_RUNNING_MODAL;
1132 if (t->state != TRANS_RUNNING)
1134 /* handle restoring objects */
1135 if(t->state == TRANS_CANCEL)
1137 exit_code = OPERATOR_CANCELLED;
1139 /* TRANSFORM_FIX_ME fix jesty's node stuff, shouldn't be exceptional at this level */
1140 if(t->spacetype == SPACE_NODE)
1141 restoreTransNodes(t);
1143 restoreTransObjects(t); // calls recalcData()
1147 exit_code = OPERATOR_FINISHED;
1153 /* aftertrans does insert ipos and action channels, and clears base flags, doesnt read transdata */
1154 special_aftertrans_update(t);
1156 /* send events out for redraws */
1159 /* Undo as last, certainly after special_trans_update! */
1161 if(t->state == TRANS_CANCEL) {
1162 if(t->undostr) ED_undo_push(C, t->undostr);
1165 if(t->undostr) ED_undo_push(C, t->undostr);
1166 else ED_undo_push(C, transform_to_undostr(t));
1174 /* ************************** Manipulator init and main **************************** */
1176 void initManipulator(int mode)
1178 #if 0 // TRANSFORM_FIX_ME
1179 Trans.state = TRANS_RUNNING;
1181 Trans.options = CTX_NONE;
1185 /* automatic switch to scaling bone envelopes */
1186 if(mode==TFM_RESIZE && t->obedit && t->obedit->type==OB_ARMATURE) {
1187 bArmature *arm= t->obedit->data;
1188 if(arm->drawtype==ARM_ENVELOPE)
1189 mode= TFM_BONE_ENVELOPE;
1192 initTrans(&Trans); // internal data, mouse, vectors
1194 G.moving |= G_TRANSFORM_MANIP; // signal to draw manipuls while transform
1195 createTransData(&Trans); // make TransData structs from selection
1197 if (Trans.total == 0)
1200 initSnapping(&Trans); // Initialize snapping data AFTER mode flags
1202 /* EVIL! posemode code can switch translation to rotate when 1 bone is selected. will be removed (ton) */
1203 /* EVIL2: we gave as argument also texture space context bit... was cleared */
1206 calculatePropRatio(&Trans);
1207 calculateCenter(&Trans);
1210 case TFM_TRANSLATION:
1211 initTranslation(&Trans);
1214 initRotation(&Trans);
1220 initTrackball(&Trans);
1224 Trans.flag |= T_USES_MANIPULATOR;
1228 void ManipulatorTransform()
1230 #if 0 // TRANSFORM_FIX_ME
1231 int mouse_moved = 0;
1232 short pmval[2] = {0, 0}, mval[2], val;
1233 unsigned short event;
1235 if (Trans.total == 0)
1238 Trans.redraw = 1; /* initial draw */
1240 while (Trans.state == TRANS_RUNNING) {
1242 getmouseco_areawin(mval);
1244 if (mval[0] != pmval[0] || mval[1] != pmval[1]) {
1251 //selectConstraint(&Trans); needed?
1252 if (Trans.transform) {
1253 Trans.transform(&Trans, mval);
1258 /* essential for idling subloop */
1259 if( qtest()==0) PIL_sleep_ms(2);
1262 event= extern_qread(&val);
1269 /* enforce redraw of transform when modifiers are used */
1272 if(val) Trans.redraw = 1;
1276 /* shift is modifier for higher resolution transform, works nice to store this mouse position */
1278 getmouseco_areawin(Trans.shiftmval);
1279 Trans.flag |= T_SHIFT_MOD;
1282 else Trans.flag &= ~T_SHIFT_MOD;
1287 Trans.state = TRANS_CANCEL;
1290 if(mouse_moved==0 && val==0) break;
1291 // else we pass on event to next, which cancels
1295 Trans.state = TRANS_CONFIRM;
1304 if(G.qual & LR_ALTKEY && Trans.flag & T_PROP_EDIT) {
1305 Trans.propsize*= 1.1f;
1306 calculatePropRatio(&Trans);
1311 case WHEELDOWNMOUSE:
1312 if (Trans.flag & T_AUTOIK) {
1313 transform_autoik_update(&Trans, 1);
1315 else if(Trans.flag & T_PROP_EDIT) {
1316 Trans.propsize*= 1.1f;
1317 calculatePropRatio(&Trans);
1319 else view_editmove(event);
1323 if(G.qual & LR_ALTKEY && Trans.flag & T_PROP_EDIT) {
1324 Trans.propsize*= 0.90909090f;
1325 calculatePropRatio(&Trans);
1331 if (Trans.flag & T_AUTOIK) {
1332 transform_autoik_update(&Trans, -1);
1334 else if (Trans.flag & T_PROP_EDIT) {
1335 Trans.propsize*= 0.90909090f;
1336 calculatePropRatio(&Trans);
1338 else view_editmove(event);
1343 // Numerical input events
1344 Trans.redraw |= handleNumInput(&(Trans.num), event);
1349 if(Trans.state == TRANS_CANCEL) {
1350 restoreTransObjects(&Trans);
1353 /* free data, reset vars */
1356 /* aftertrans does insert ipos and action channels, and clears base flags */
1357 special_aftertrans_update(&Trans);
1359 /* send events out for redraws */
1360 viewRedrawPost(&Trans);
1362 if(Trans.state != TRANS_CANCEL) {
1363 BIF_undo_push(transform_to_undostr(&Trans));
1368 /* ************************** TRANSFORM LOCKS **************************** */
1370 static void protectedTransBits(short protectflag, float *vec)
1372 if(protectflag & OB_LOCK_LOCX)
1374 if(protectflag & OB_LOCK_LOCY)
1376 if(protectflag & OB_LOCK_LOCZ)
1380 static void protectedSizeBits(short protectflag, float *size)
1382 if(protectflag & OB_LOCK_SCALEX)
1384 if(protectflag & OB_LOCK_SCALEY)
1386 if(protectflag & OB_LOCK_SCALEZ)
1390 static void protectedRotateBits(short protectflag, float *eul, float *oldeul)
1392 if(protectflag & OB_LOCK_ROTX)
1394 if(protectflag & OB_LOCK_ROTY)
1396 if(protectflag & OB_LOCK_ROTZ)
1400 static void protectedQuaternionBits(short protectflag, float *quat, float *oldquat)
1402 /* quaternions get limited with euler... */
1403 /* this function only does the delta rotation */
1406 float eul[3], oldeul[3], quat1[4];
1408 QUATCOPY(quat1, quat);
1409 QuatToEul(quat, eul);
1410 QuatToEul(oldquat, oldeul);
1412 if(protectflag & OB_LOCK_ROTX)
1414 if(protectflag & OB_LOCK_ROTY)
1416 if(protectflag & OB_LOCK_ROTZ)
1419 EulToQuat(eul, quat);
1420 /* quaternions flip w sign to accumulate rotations correctly */
1421 if( (quat1[0]<0.0f && quat[0]>0.0f) || (quat1[0]>0.0f && quat[0]<0.0f) ) {
1422 QuatMulf(quat, -1.0f);
1427 /* ******************* TRANSFORM LIMITS ********************** */
1429 static void constraintTransLim(TransInfo *t, TransData *td)
1432 bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_LOCLIMIT);
1436 /* Make a temporary bConstraintOb for using these limit constraints
1437 * - they only care that cob->matrix is correctly set ;-)
1438 * - current space should be local
1440 memset(&cob, 0, sizeof(bConstraintOb));
1441 Mat4One(cob.matrix);
1443 TransDataIpokey *tdi= td->tdi;
1444 cob.matrix[3][0]= tdi->locx[0];
1445 cob.matrix[3][1]= tdi->locy[0];
1446 cob.matrix[3][2]= tdi->locz[0];
1449 VECCOPY(cob.matrix[3], td->loc);
1452 /* Evaluate valid constraints */
1453 for (con= td->con; con; con= con->next) {
1456 /* only consider constraint if enabled */
1457 if (con->flag & CONSTRAINT_DISABLE) continue;
1458 if (con->enforce == 0.0f) continue;
1460 /* only use it if it's tagged for this purpose (and the right type) */
1461 if (con->type == CONSTRAINT_TYPE_LOCLIMIT) {
1462 bLocLimitConstraint *data= con->data;
1464 if ((data->flag2 & LIMIT_TRANSFORM)==0)
1467 /* do space conversions */
1468 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1469 /* just multiply by td->mtx (this should be ok) */
1470 Mat4CpyMat4(tmat, cob.matrix);
1471 Mat4MulMat34(cob.matrix, td->mtx, tmat);
1473 else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) {
1474 /* skip... incompatable spacetype */
1479 cti->evaluate_constraint(con, &cob, NULL);
1481 /* convert spaces again */
1482 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1483 /* just multiply by td->mtx (this should be ok) */
1484 Mat4CpyMat4(tmat, cob.matrix);
1485 Mat4MulMat34(cob.matrix, td->smtx, tmat);
1490 /* copy results from cob->matrix */
1492 TransDataIpokey *tdi= td->tdi;
1493 tdi->locx[0]= cob.matrix[3][0];
1494 tdi->locy[0]= cob.matrix[3][1];
1495 tdi->locz[0]= cob.matrix[3][2];
1498 VECCOPY(td->loc, cob.matrix[3]);
1503 static void constraintRotLim(TransInfo *t, TransData *td)
1506 bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_ROTLIMIT);
1510 /* Make a temporary bConstraintOb for using these limit constraints
1511 * - they only care that cob->matrix is correctly set ;-)
1512 * - current space should be local
1514 memset(&cob, 0, sizeof(bConstraintOb));
1515 if (td->flag & TD_USEQUAT) {
1518 QuatToMat4(td->ext->quat, cob.matrix);
1523 /* ipo-keys eulers */
1524 TransDataIpokey *tdi= td->tdi;
1527 eul[0]= tdi->rotx[0];
1528 eul[1]= tdi->roty[0];
1529 eul[2]= tdi->rotz[0];
1531 EulToMat4(eul, cob.matrix);
1536 EulToMat4(td->ext->rot, cob.matrix);
1541 /* Evaluate valid constraints */
1542 for (con= td->con; con; con= con->next) {
1543 /* only consider constraint if enabled */
1544 if (con->flag & CONSTRAINT_DISABLE) continue;
1545 if (con->enforce == 0.0f) continue;
1547 /* we're only interested in Limit-Rotation constraints */
1548 if (con->type == CONSTRAINT_TYPE_ROTLIMIT) {
1549 bRotLimitConstraint *data= con->data;
1552 /* only use it if it's tagged for this purpose */
1553 if ((data->flag2 & LIMIT_TRANSFORM)==0)
1556 /* do space conversions */
1557 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1558 /* just multiply by td->mtx (this should be ok) */
1559 Mat4CpyMat4(tmat, cob.matrix);
1560 Mat4MulMat34(cob.matrix, td->mtx, tmat);
1562 else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) {
1563 /* skip... incompatable spacetype */
1568 cti->evaluate_constraint(con, &cob, NULL);
1570 /* convert spaces again */
1571 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1572 /* just multiply by td->mtx (this should be ok) */
1573 Mat4CpyMat4(tmat, cob.matrix);
1574 Mat4MulMat34(cob.matrix, td->smtx, tmat);
1579 /* copy results from cob->matrix */
1580 if (td->flag & TD_USEQUAT) {
1582 Mat4ToQuat(cob.matrix, td->ext->quat);
1585 /* ipo-keys eulers */
1586 TransDataIpokey *tdi= td->tdi;
1589 Mat4ToEul(cob.matrix, eul);
1591 tdi->rotx[0]= eul[0];
1592 tdi->roty[0]= eul[1];
1593 tdi->rotz[0]= eul[2];
1597 Mat4ToEul(cob.matrix, td->ext->rot);
1602 static void constraintSizeLim(TransInfo *t, TransData *td)
1604 if (td->con && td->ext) {
1605 bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_SIZELIMIT);
1609 /* Make a temporary bConstraintOb for using these limit constraints
1610 * - they only care that cob->matrix is correctly set ;-)
1611 * - current space should be local
1613 memset(&cob, 0, sizeof(bConstraintOb));
1615 TransDataIpokey *tdi= td->tdi;
1618 size[0]= tdi->sizex[0];
1619 size[1]= tdi->sizey[0];
1620 size[2]= tdi->sizez[0];
1621 SizeToMat4(size, cob.matrix);
1623 else if ((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)) {
1624 /* scale val and reset size */
1625 return; // TODO: fix this case
1628 /* Reset val if SINGLESIZE but using a constraint */
1629 if (td->flag & TD_SINGLESIZE)
1632 SizeToMat4(td->ext->size, cob.matrix);
1635 /* Evaluate valid constraints */
1636 for (con= td->con; con; con= con->next) {
1637 /* only consider constraint if enabled */
1638 if (con->flag & CONSTRAINT_DISABLE) continue;
1639 if (con->enforce == 0.0f) continue;
1641 /* we're only interested in Limit-Scale constraints */
1642 if (con->type == CONSTRAINT_TYPE_SIZELIMIT) {
1643 bSizeLimitConstraint *data= con->data;
1646 /* only use it if it's tagged for this purpose */
1647 if ((data->flag2 & LIMIT_TRANSFORM)==0)
1650 /* do space conversions */
1651 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1652 /* just multiply by td->mtx (this should be ok) */
1653 Mat4CpyMat4(tmat, cob.matrix);
1654 Mat4MulMat34(cob.matrix, td->mtx, tmat);
1656 else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) {
1657 /* skip... incompatable spacetype */
1662 cti->evaluate_constraint(con, &cob, NULL);
1664 /* convert spaces again */
1665 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1666 /* just multiply by td->mtx (this should be ok) */
1667 Mat4CpyMat4(tmat, cob.matrix);
1668 Mat4MulMat34(cob.matrix, td->smtx, tmat);
1673 /* copy results from cob->matrix */
1675 TransDataIpokey *tdi= td->tdi;
1678 Mat4ToSize(cob.matrix, size);
1680 tdi->sizex[0]= size[0];
1681 tdi->sizey[0]= size[1];
1682 tdi->sizez[0]= size[2];
1684 else if ((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)) {
1685 /* scale val and reset size */
1686 return; // TODO: fix this case
1689 /* Reset val if SINGLESIZE but using a constraint */
1690 if (td->flag & TD_SINGLESIZE)
1693 Mat4ToSize(cob.matrix, td->ext->size);
1698 /* ************************** WARP *************************** */
1700 void initWarp(TransInfo *t)
1702 float max[3], min[3];
1706 t->transform = Warp;
1707 t->handleEvent = handleEventWarp;
1709 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_RATIO);
1717 t->flag |= T_NO_CONSTRAINT;
1719 /* we need min/max in view space */
1720 for(i = 0; i < t->total; i++) {
1722 VECCOPY(center, t->data[i].center);
1723 Mat3MulVecfl(t->data[i].mtx, center);
1724 Mat4MulVecfl(t->viewmat, center);
1725 VecSubf(center, center, t->viewmat[3]);
1727 MinMax3(min, max, center);
1729 VECCOPY(max, center);
1730 VECCOPY(min, center);
1734 t->center[0]= (min[0]+max[0])/2.0f;
1735 t->center[1]= (min[1]+max[1])/2.0f;
1736 t->center[2]= (min[2]+max[2])/2.0f;
1738 if (max[0] == min[0]) max[0] += 0.1; /* not optimal, but flipping is better than invalid garbage (i.e. division by zero!) */
1739 t->val= (max[0]-min[0])/2.0f; /* t->val is X dimension projected boundbox */
1742 int handleEventWarp(TransInfo *t, wmEvent *event)
1746 if (event->type == MIDDLEMOUSE && event->val)
1748 // Use customData pointer to signal warp direction
1749 if (t->customData == 0)
1750 t->customData = (void*)1;
1760 int Warp(TransInfo *t, short mval[2])
1762 TransData *td = t->data;
1763 float vec[3], circumfac, dist, phi0, co, si, *curs, cursor[3], gcursor[3];
1767 curs= give_cursor(t->scene, t->view);
1769 * gcursor is the one used for helpline.
1770 * It has to be in the same space as the drawing loop
1771 * (that means it needs to be in the object's space when in edit mode and
1772 * in global space in object mode)
1774 * cursor is used for calculations.
1775 * It needs to be in view space, but we need to take object's offset
1776 * into account if in Edit mode.
1778 VECCOPY(cursor, curs);
1779 VECCOPY(gcursor, cursor);
1780 if (t->flag & T_EDIT) {
1781 VecSubf(cursor, cursor, t->obedit->obmat[3]);
1782 VecSubf(gcursor, gcursor, t->obedit->obmat[3]);
1783 Mat3MulVecfl(t->data->smtx, gcursor);
1785 Mat4MulVecfl(t->viewmat, cursor);
1786 VecSubf(cursor, cursor, t->viewmat[3]);
1788 /* amount of degrees for warp */
1789 circumfac = 360.0f * t->values[0];
1791 if (t->customData) /* non-null value indicates reversed input */
1796 snapGrid(t, &circumfac);
1797 applyNumInput(&t->num, &circumfac);
1799 /* header print for NumInput */
1800 if (hasNumInput(&t->num)) {
1803 outputNumInput(&(t->num), c);
1805 sprintf(str, "Warp: %s", c);
1808 /* default header print */
1809 sprintf(str, "Warp: %.3f", circumfac);
1812 circumfac*= (float)(-M_PI/360.0);
1814 for(i = 0; i < t->total; i++, td++) {
1816 if (td->flag & TD_NOACTION)
1819 if (td->flag & TD_SKIP)
1822 /* translate point to center, rotate in such a way that outline==distance */
1823 VECCOPY(vec, td->iloc);
1824 Mat3MulVecfl(td->mtx, vec);
1825 Mat4MulVecfl(t->viewmat, vec);
1826 VecSubf(vec, vec, t->viewmat[3]);
1828 dist= vec[0]-cursor[0];
1830 /* t->val is X dimension projected boundbox */
1831 phi0= (circumfac*dist/t->val);
1833 vec[1]= (vec[1]-cursor[1]);
1835 co= (float)cos(phi0);
1836 si= (float)sin(phi0);
1837 loc[0]= -si*vec[1]+cursor[0];
1838 loc[1]= co*vec[1]+cursor[1];
1841 Mat4MulVecfl(t->viewinv, loc);
1842 VecSubf(loc, loc, t->viewinv[3]);
1843 Mat3MulVecfl(td->smtx, loc);
1845 VecSubf(loc, loc, td->iloc);
1846 VecMulf(loc, td->factor);
1847 VecAddf(td->loc, td->iloc, loc);
1852 ED_area_headerprint(t->sa, str);
1856 helpline(t, gcursor);
1861 /* ************************** SHEAR *************************** */
1863 void initShear(TransInfo *t)
1865 t->mode = TFM_SHEAR;
1866 t->transform = Shear;
1867 t->handleEvent = handleEventShear;
1869 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_ABSOLUTE);
1875 t->snap[2] = t->snap[1] * 0.1f;
1877 t->flag |= T_NO_CONSTRAINT;
1880 int handleEventShear(TransInfo *t, wmEvent *event)
1884 if (event->type == MIDDLEMOUSE && event->val)
1886 // Use customData pointer to signal Shear direction
1887 if (t->customData == 0)
1889 initMouseInputMode(t, &t->mouse, INPUT_VERTICAL_ABSOLUTE);
1890 t->customData = (void*)1;
1894 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_ABSOLUTE);
1905 int Shear(TransInfo *t, short mval[2])
1907 TransData *td = t->data;
1909 float smat[3][3], tmat[3][3], totmat[3][3], persmat[3][3], persinv[3][3];
1914 Mat3CpyMat4(persmat, t->viewmat);
1915 Mat3Inv(persinv, persmat);
1917 value = 0.05f * t->values[0];
1919 snapGrid(t, &value);
1921 applyNumInput(&t->num, &value);
1923 /* header print for NumInput */
1924 if (hasNumInput(&t->num)) {
1927 outputNumInput(&(t->num), c);
1929 sprintf(str, "Shear: %s %s", c, t->proptext);
1932 /* default header print */
1933 sprintf(str, "Shear: %.3f %s", value, t->proptext);
1938 // Custom data signals shear direction
1939 if (t->customData == 0)
1944 Mat3MulMat3(tmat, smat, persmat);
1945 Mat3MulMat3(totmat, persinv, tmat);
1947 for(i = 0 ; i < t->total; i++, td++) {
1948 if (td->flag & TD_NOACTION)
1951 if (td->flag & TD_SKIP)
1956 Mat3MulMat3(mat3, totmat, td->mtx);
1957 Mat3MulMat3(tmat, td->smtx, mat3);
1960 Mat3CpyMat3(tmat, totmat);
1962 VecSubf(vec, td->center, t->center);
1964 Mat3MulVecfl(tmat, vec);
1966 VecAddf(vec, vec, t->center);
1967 VecSubf(vec, vec, td->center);
1969 VecMulf(vec, td->factor);
1971 VecAddf(td->loc, td->iloc, vec);
1976 ED_area_headerprint(t->sa, str);
1980 helpline (t, t->center);
1985 /* ************************** RESIZE *************************** */
1987 void initResize(TransInfo *t)
1989 t->mode = TFM_RESIZE;
1990 t->transform = Resize;
1992 initMouseInputMode(t, &t->mouse, INPUT_SPRING_FLIP);
1994 t->flag |= T_NULL_ONE;
1995 t->num.flag |= NUM_NULL_ONE;
1996 t->num.flag |= NUM_AFFECT_ALL;
1998 t->flag |= T_NO_ZERO;
1999 t->num.flag |= NUM_NO_ZERO;
2006 t->snap[2] = t->snap[1] * 0.1f;
2009 static void headerResize(TransInfo *t, float vec[3], char *str) {
2011 if (hasNumInput(&t->num)) {
2012 outputNumInput(&(t->num), tvec);
2015 sprintf(&tvec[0], "%.4f", vec[0]);
2016 sprintf(&tvec[20], "%.4f", vec[1]);
2017 sprintf(&tvec[40], "%.4f", vec[2]);
2020 if (t->con.mode & CON_APPLY) {
2021 switch(t->num.idx_max) {
2023 sprintf(str, "Scale: %s%s %s", &tvec[0], t->con.text, t->proptext);
2026 sprintf(str, "Scale: %s : %s%s %s", &tvec[0], &tvec[20], t->con.text, t->proptext);
2029 sprintf(str, "Scale: %s : %s : %s%s %s", &tvec[0], &tvec[20], &tvec[40], t->con.text, t->proptext);
2033 if (t->flag & T_2D_EDIT)
2034 sprintf(str, "Scale X: %s Y: %s%s %s", &tvec[0], &tvec[20], t->con.text, t->proptext);
2036 sprintf(str, "Scale X: %s Y: %s Z: %s%s %s", &tvec[0], &tvec[20], &tvec[40], t->con.text, t->proptext);
2040 #define SIGN(a) (a<-FLT_EPSILON?1:a>FLT_EPSILON?2:3)
2041 #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)
2043 /* smat is reference matrix, only scaled */
2044 static void TransMat3ToSize( float mat[][3], float smat[][3], float *size)
2048 VecCopyf(vec, mat[0]);
2049 size[0]= Normalize(vec);
2050 VecCopyf(vec, mat[1]);
2051 size[1]= Normalize(vec);
2052 VecCopyf(vec, mat[2]);
2053 size[2]= Normalize(vec);
2055 /* first tried with dotproduct... but the sign flip is crucial */
2056 if( VECSIGNFLIP(mat[0], smat[0]) ) size[0]= -size[0];
2057 if( VECSIGNFLIP(mat[1], smat[1]) ) size[1]= -size[1];
2058 if( VECSIGNFLIP(mat[2], smat[2]) ) size[2]= -size[2];
2062 static void ElementResize(TransInfo *t, TransData *td, float mat[3][3]) {
2063 float tmat[3][3], smat[3][3], center[3];
2066 if (t->flag & T_EDIT) {
2067 Mat3MulMat3(smat, mat, td->mtx);
2068 Mat3MulMat3(tmat, td->smtx, smat);
2071 Mat3CpyMat3(tmat, mat);
2074 if (t->con.applySize) {
2075 t->con.applySize(t, td, tmat);
2078 /* local constraint shouldn't alter center */
2079 if (t->around == V3D_LOCAL) {
2080 if (t->flag & T_OBJECT) {
2081 VECCOPY(center, td->center);
2083 else if (t->flag & T_EDIT) {
2085 if(t->around==V3D_LOCAL && (G.scene->selectmode & SCE_SELECT_FACE)) {
2086 VECCOPY(center, td->center);
2089 VECCOPY(center, t->center);
2093 VECCOPY(center, t->center);
2097 VECCOPY(center, t->center);
2103 if (t->flag & (T_OBJECT|T_TEXTURE|T_POSE)) {
2104 float obsizemat[3][3];
2105 // Reorient the size mat to fit the oriented object.
2106 Mat3MulMat3(obsizemat, tmat, td->axismtx);
2107 //printmatrix3("obsizemat", obsizemat);
2108 TransMat3ToSize(obsizemat, td->axismtx, fsize);
2109 //printvecf("fsize", fsize);
2112 Mat3ToSize(tmat, fsize);
2115 protectedSizeBits(td->protectflag, fsize);
2117 if ((t->flag & T_V3D_ALIGN)==0) { // align mode doesn't resize objects itself
2118 /* handle ipokeys? */
2120 TransDataIpokey *tdi= td->tdi;
2121 /* calculate delta size (equal for size and dsize) */
2123 vec[0]= (tdi->oldsize[0])*(fsize[0] -1.0f) * td->factor;
2124 vec[1]= (tdi->oldsize[1])*(fsize[1] -1.0f) * td->factor;
2125 vec[2]= (tdi->oldsize[2])*(fsize[2] -1.0f) * td->factor;
2127 add_tdi_poin(tdi->sizex, tdi->oldsize, vec[0]);
2128 add_tdi_poin(tdi->sizey, tdi->oldsize+1, vec[1]);
2129 add_tdi_poin(tdi->sizez, tdi->oldsize+2, vec[2]);
2132 else if((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)){
2133 /* scale val and reset size */
2134 *td->val = td->ival * fsize[0] * td->factor;
2136 td->ext->size[0] = td->ext->isize[0];
2137 td->ext->size[1] = td->ext->isize[1];
2138 td->ext->size[2] = td->ext->isize[2];
2141 /* Reset val if SINGLESIZE but using a constraint */
2142 if (td->flag & TD_SINGLESIZE)
2143 *td->val = td->ival;
2145 td->ext->size[0] = td->ext->isize[0] * (fsize[0]) * td->factor;
2146 td->ext->size[1] = td->ext->isize[1] * (fsize[1]) * td->factor;
2147 td->ext->size[2] = td->ext->isize[2] * (fsize[2]) * td->factor;
2151 constraintSizeLim(t, td);
2154 /* For individual element center, Editmode need to use iloc */
2155 if (t->flag & T_POINTS)
2156 VecSubf(vec, td->iloc, center);
2158 VecSubf(vec, td->center, center);
2160 Mat3MulVecfl(tmat, vec);
2162 VecAddf(vec, vec, center);
2163 if (t->flag & T_POINTS)
2164 VecSubf(vec, vec, td->iloc);
2166 VecSubf(vec, vec, td->center);
2168 VecMulf(vec, td->factor);
2170 if (t->flag & (T_OBJECT|T_POSE)) {
2171 Mat3MulVecfl(td->smtx, vec);
2174 protectedTransBits(td->protectflag, vec);
2177 TransDataIpokey *tdi= td->tdi;
2178 add_tdi_poin(tdi->locx, tdi->oldloc, vec[0]);
2179 add_tdi_poin(tdi->locy, tdi->oldloc+1, vec[1]);
2180 add_tdi_poin(tdi->locz, tdi->oldloc+2, vec[2]);
2182 else VecAddf(td->loc, td->iloc, vec);
2184 constraintTransLim(t, td);
2187 int Resize(TransInfo *t, short mval[2])
2190 float size[3], mat[3][3];
2195 /* for manipulator, center handle, the scaling can't be done relative to center */
2196 if( (t->flag & T_USES_MANIPULATOR) && t->con.mode==0)
2198 ratio = 1.0f - ((t->imval[0] - mval[0]) + (t->imval[1] - mval[1]))/100.0f;
2202 ratio = t->values[0];
2205 size[0] = size[1] = size[2] = ratio;
2209 if (hasNumInput(&t->num)) {
2210 applyNumInput(&t->num, size);
2211 constraintNumInput(t, size);
2214 applySnapping(t, size);
2216 SizeToMat3(size, mat);
2218 if (t->con.applySize) {
2219 t->con.applySize(t, NULL, mat);
2222 Mat3CpyMat3(t->mat, mat); // used in manipulator
2224 headerResize(t, size, str);
2226 for(i = 0, td=t->data; i < t->total; i++, td++) {
2227 if (td->flag & TD_NOACTION)
2230 if (td->flag & TD_SKIP)
2233 ElementResize(t, td, mat);
2236 /* evil hack - redo resize if cliping needed */
2237 if (t->flag & T_CLIP_UV && clipUVTransform(t, size, 1)) {
2238 SizeToMat3(size, mat);
2240 if (t->con.applySize)
2241 t->con.applySize(t, NULL, mat);
2243 for(i = 0, td=t->data; i < t->total; i++, td++)
2244 ElementResize(t, td, mat);
2249 ED_area_headerprint(t->sa, str);
2253 if(!(t->flag & T_USES_MANIPULATOR)) helpline (t, t->center);
2258 /* ************************** TOSPHERE *************************** */
2260 void initToSphere(TransInfo *t)
2262 TransData *td = t->data;
2265 t->mode = TFM_TOSPHERE;
2266 t->transform = ToSphere;
2268 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_RATIO);
2274 t->snap[2] = t->snap[1] * 0.1f;
2276 t->num.flag |= NUM_NULL_ONE | NUM_NO_NEGATIVE;
2277 t->flag |= T_NO_CONSTRAINT;
2279 // Calculate average radius
2280 for(i = 0 ; i < t->total; i++, td++) {
2281 t->val += VecLenf(t->center, td->iloc);
2284 t->val /= (float)t->total;
2287 int ToSphere(TransInfo *t, short mval[2])
2290 float ratio, radius;
2293 TransData *td = t->data;
2295 ratio = t->values[0];
2297 snapGrid(t, &ratio);
2299 applyNumInput(&t->num, &ratio);
2306 /* header print for NumInput */
2307 if (hasNumInput(&t->num)) {
2310 outputNumInput(&(t->num), c);
2312 sprintf(str, "To Sphere: %s %s", c, t->proptext);
2315 /* default header print */
2316 sprintf(str, "To Sphere: %.4f %s", ratio, t->proptext);
2320 for(i = 0 ; i < t->total; i++, td++) {
2322 if (td->flag & TD_NOACTION)
2325 if (td->flag & TD_SKIP)
2328 VecSubf(vec, td->iloc, t->center);
2330 radius = Normalize(vec);
2332 tratio = ratio * td->factor;
2334 VecMulf(vec, radius * (1.0f - tratio) + t->val * tratio);
2336 VecAddf(td->loc, t->center, vec);
2342 ED_area_headerprint(t->sa, str);
2349 /* ************************** ROTATION *************************** */
2352 void initRotation(TransInfo *t)
2354 t->mode = TFM_ROTATION;
2355 t->transform = Rotation;
2357 initMouseInputMode(t, &t->mouse, INPUT_ANGLE);
2360 /* Scale down and flip input for rotation */
2361 t->ndof.factor[0] = -0.2f;
2366 t->snap[1] = (float)((5.0/180)*M_PI);
2367 t->snap[2] = t->snap[1] * 0.2f;
2369 if (t->flag & T_2D_EDIT)
2370 t->flag |= T_NO_CONSTRAINT;
2373 static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short around) {
2374 float vec[3], totmat[3][3], smat[3][3];
2375 float eul[3], fmat[3][3], quat[4];
2376 float *center = t->center;
2378 /* local constraint shouldn't alter center */
2379 if (around == V3D_LOCAL) {
2380 if (t->flag & (T_OBJECT|T_POSE)) {
2381 center = td->center;
2384 /* !TODO! Make this if not rely on G */
2385 if(around==V3D_LOCAL && (G.scene->selectmode & SCE_SELECT_FACE)) {
2386 center = td->center;
2391 if (t->flag & T_POINTS) {
2392 Mat3MulMat3(totmat, mat, td->mtx);
2393 Mat3MulMat3(smat, td->smtx, totmat);
2395 VecSubf(vec, td->iloc, center);
2396 Mat3MulVecfl(smat, vec);
2398 VecAddf(td->loc, vec, center);
2400 VecSubf(vec,td->loc,td->iloc);
2401 protectedTransBits(td->protectflag, vec);
2402 VecAddf(td->loc, td->iloc, vec);
2404 if(td->flag & TD_USEQUAT) {
2405 Mat3MulSerie(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0);
2406 Mat3ToQuat(fmat, quat); // Actual transform
2409 QuatMul(td->ext->quat, quat, td->ext->iquat);
2411 /* is there a reason not to have this here? -jahka */
2412 protectedQuaternionBits(td->protectflag, td->ext->quat, td->ext->iquat);
2419 * This is some VERY ugly special case to deal with pose mode.
2421 * The problem is that mtx and smtx include each bone orientation.
2423 * That is needed to rotate each bone properly, HOWEVER, to calculate
2424 * the translation component, we only need the actual armature object's
2425 * matrix (and inverse). That is not all though. Once the proper translation
2426 * has been computed, it has to be converted back into the bone's space.
2428 else if (t->flag & T_POSE) {
2429 float pmtx[3][3], imtx[3][3];
2431 // Extract and invert armature object matrix
2432 Mat3CpyMat4(pmtx, t->poseobj->obmat);
2433 Mat3Inv(imtx, pmtx);
2435 if ((td->flag & TD_NO_LOC) == 0)
2437 VecSubf(vec, td->center, center);
2439 Mat3MulVecfl(pmtx, vec); // To Global space
2440 Mat3MulVecfl(mat, vec); // Applying rotation
2441 Mat3MulVecfl(imtx, vec); // To Local space
2443 VecAddf(vec, vec, center);
2444 /* vec now is the location where the object has to be */
2446 VecSubf(vec, vec, td->center); // Translation needed from the initial location
2448 Mat3MulVecfl(pmtx, vec); // To Global space
2449 Mat3MulVecfl(td->smtx, vec);// To Pose space
2451 protectedTransBits(td->protectflag, vec);
2453 VecAddf(td->loc, td->iloc, vec);
2455 constraintTransLim(t, td);
2459 if ((t->flag & T_V3D_ALIGN)==0) { // align mode doesn't rotate objects itself
2460 Mat3MulSerie(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0);
2462 Mat3ToQuat(fmat, quat); // Actual transform
2464 QuatMul(td->ext->quat, quat, td->ext->iquat);
2465 /* this function works on end result */
2466 protectedQuaternionBits(td->protectflag, td->ext->quat, td->ext->iquat);
2468 constraintRotLim(t, td);
2473 if ((td->flag & TD_NO_LOC) == 0)
2476 VecSubf(vec, td->center, center);
2477 Mat3MulVecfl(mat, vec);
2478 VecAddf(vec, vec, center);
2479 /* vec now is the location where the object has to be */
2480 VecSubf(vec, vec, td->center);
2481 Mat3MulVecfl(td->smtx, vec);
2483 protectedTransBits(td->protectflag, vec);
2486 TransDataIpokey *tdi= td->tdi;
2487 add_tdi_poin(tdi->locx, tdi->oldloc, vec[0]);
2488 add_tdi_poin(tdi->locy, tdi->oldloc+1, vec[1]);
2489 add_tdi_poin(tdi->locz, tdi->oldloc+2, vec[2]);
2491 else VecAddf(td->loc, td->iloc, vec);
2495 constraintTransLim(t, td);
2498 if ((t->flag & T_V3D_ALIGN)==0) { // align mode doesn't rotate objects itself
2499 if(td->flag & TD_USEQUAT) {
2500 Mat3MulSerie(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0);
2501 Mat3ToQuat(fmat, quat); // Actual transform
2503 QuatMul(td->ext->quat, quat, td->ext->iquat);
2504 /* this function works on end result */
2505 protectedQuaternionBits(td->protectflag, td->ext->quat, td->ext->iquat);
2510 /* are there ipo keys? */
2512 TransDataIpokey *tdi= td->tdi;
2513 float current_rot[3];
2516 /* current IPO value for compatible euler */
2517 current_rot[0] = (tdi->rotx) ? tdi->rotx[0] : 0.0f;
2518 current_rot[1] = (tdi->roty) ? tdi->roty[0] : 0.0f;
2519 current_rot[2] = (tdi->rotz) ? tdi->rotz[0] : 0.0f;
2520 VecMulf(current_rot, (float)(M_PI_2 / 9.0));
2522 /* calculate the total rotatation in eulers */
2523 VecAddf(eul, td->ext->irot, td->ext->drot);
2524 EulToMat3(eul, obmat);
2525 /* mat = transform, obmat = object rotation */
2526 Mat3MulMat3(fmat, mat, obmat);
2528 Mat3ToCompatibleEul(fmat, eul, current_rot);
2530 /* correct back for delta rot */
2531 if(tdi->flag & TOB_IPODROT) {
2532 VecSubf(rot, eul, td->ext->irot);
2535 VecSubf(rot, eul, td->ext->drot);
2538 VecMulf(rot, (float)(9.0/M_PI_2));
2539 VecSubf(rot, rot, tdi->oldrot);
2541 protectedRotateBits(td->protectflag, rot, tdi->oldrot);
2543 add_tdi_poin(tdi->rotx, tdi->oldrot, rot[0]);
2544 add_tdi_poin(tdi->roty, tdi->oldrot+1, rot[1]);
2545 add_tdi_poin(tdi->rotz, tdi->oldrot+2, rot[2]);
2548 Mat3MulMat3(totmat, mat, td->mtx);
2549 Mat3MulMat3(smat, td->smtx, totmat);
2551 /* calculate the total rotatation in eulers */
2552 VecAddf(eul, td->ext->irot, td->ext->drot); /* we have to correct for delta rot */
2553 EulToMat3(eul, obmat);
2554 /* mat = transform, obmat = object rotation */
2555 Mat3MulMat3(fmat, smat, obmat);
2557 Mat3ToCompatibleEul(fmat, eul, td->ext->rot);
2559 /* correct back for delta rot */
2560 VecSubf(eul, eul, td->ext->drot);
2563 protectedRotateBits(td->protectflag, eul, td->ext->irot);
2564 VECCOPY(td->ext->rot, eul);
2568 constraintRotLim(t, td);
2573 static void applyRotation(TransInfo *t, float angle, float axis[3])
2575 TransData *td = t->data;
2579 VecRotToMat3(axis, angle, mat);
2581 for(i = 0 ; i < t->total; i++, td++) {
2583 if (td->flag & TD_NOACTION)
2586 if (td->flag & TD_SKIP)
2589 if (t->con.applyRot) {
2590 t->con.applyRot(t, td, axis, NULL);
2591 VecRotToMat3(axis, angle * td->factor, mat);
2593 else if (t->flag & T_PROP_EDIT) {
2594 VecRotToMat3(axis, angle * td->factor, mat);
2597 ElementRotation(t, td, mat, t->around);
2601 int Rotation(TransInfo *t, short mval[2])
2610 VECCOPY(axis, t->viewinv[2]);
2611 VecMulf(axis, -1.0f);
2614 final = t->values[0];
2616 applyNDofInput(&t->ndof, &final);
2618 snapGrid(t, &final);
2620 if (t->con.applyRot) {
2621 t->con.applyRot(t, NULL, axis, &final);
2624 applySnapping(t, &final);
2626 if (hasNumInput(&t->num)) {
2629 applyNumInput(&t->num, &final);
2631 outputNumInput(&(t->num), c);
2633 sprintf(str, "Rot: %s %s %s", &c[0], t->con.text, t->proptext);
2635 /* Clamp between -180 and 180 */
2636 while (final >= 180.0)
2639 while (final <= -180.0)
2642 final *= (float)(M_PI / 180.0);
2645 sprintf(str, "Rot: %.2f%s %s", 180.0*final/M_PI, t->con.text, t->proptext);
2648 VecRotToMat3(axis, final, mat);
2651 // t->values[0] = final; // used in manipulator
2652 // Mat3CpyMat3(t->mat, mat); // used in manipulator
2654 applyRotation(t, final, axis);
2658 ED_area_headerprint(t->sa, str);
2662 if(!(t->flag & T_USES_MANIPULATOR)) helpline (t, t->center);
2668 /* ************************** TRACKBALL *************************** */
2670 void initTrackball(TransInfo *t)
2672 t->mode = TFM_TRACKBALL;
2673 t->transform = Trackball;
2675 initMouseInputMode(t, &t->mouse, INPUT_TRACKBALL);
2678 /* Scale down input for rotation */
2679 t->ndof.factor[0] = 0.2f;
2680 t->ndof.factor[1] = 0.2f;
2685 t->snap[1] = (float)((5.0/180)*M_PI);
2686 t->snap[2] = t->snap[1] * 0.2f;
2688 t->flag |= T_NO_CONSTRAINT;
2691 static void applyTrackball(TransInfo *t, float axis1[3], float axis2[3], float angles[2])
2693 TransData *td = t->data;
2694 float mat[3][3], smat[3][3], totmat[3][3];
2697 VecRotToMat3(axis1, angles[0], smat);
2698 VecRotToMat3(axis2, angles[1], totmat);
2700 Mat3MulMat3(mat, smat, totmat);
2702 for(i = 0 ; i < t->total; i++, td++) {
2703 if (td->flag & TD_NOACTION)
2706 if (td->flag & TD_SKIP)
2709 if (t->flag & T_PROP_EDIT) {
2710 VecRotToMat3(axis1, td->factor * angles[0], smat);
2711 VecRotToMat3(axis2, td->factor * angles[1], totmat);
2713 Mat3MulMat3(mat, smat, totmat);
2716 ElementRotation(t, td, mat, t->around);
2720 int Trackball(TransInfo *t, short mval[2])
2723 float axis1[3], axis2[3];
2724 float mat[3][3], totmat[3][3], smat[3][3];
2727 VECCOPY(axis1, t->persinv[0]);
2728 VECCOPY(axis2, t->persinv[1]);
2732 phi[0] = t->values[0];
2733 phi[1] = t->values[1];
2735 applyNDofInput(&t->ndof, phi);
2739 if (hasNumInput(&t->num)) {
2742 applyNumInput(&t->num, phi);
2744 outputNumInput(&(t->num), c);
2746 sprintf(str, "Trackball: %s %s %s", &c[0], &c[20], t->proptext);
2748 phi[0] *= (float)(M_PI / 180.0);
2749 phi[1] *= (float)(M_PI / 180.0);
2752 sprintf(str, "Trackball: %.2f %.2f %s", 180.0*phi[0]/M_PI, 180.0*phi[1]/M_PI, t->proptext);
2755 VecRotToMat3(axis1, phi[0], smat);
2756 VecRotToMat3(axis2, phi[1], totmat);
2758 Mat3MulMat3(mat, smat, totmat);
2761 //Mat3CpyMat3(t->mat, mat); // used in manipulator
2763 applyTrackball(t, axis1, axis2, phi);
2767 ED_area_headerprint(t->sa, str);
2771 if(!(t->flag & T_USES_MANIPULATOR)) helpline (t, t->center);
2776 /* ************************** TRANSLATION *************************** */
2778 void initTranslation(TransInfo *t)
2780 t->mode = TFM_TRANSLATION;
2781 t->transform = Translation;
2783 initMouseInputMode(t, &t->mouse, INPUT_VECTOR);
2785 t->idx_max = (t->flag & T_2D_EDIT)? 1: 2;
2787 t->num.idx_max = t->idx_max;
2789 t->ndof.axis = 1|2|4;
2791 if(t->spacetype == SPACE_VIEW3D) {
2792 View3D *v3d = t->view;
2795 t->snap[1] = v3d->gridview * 1.0f;
2796 t->snap[2] = t->snap[1] * 0.1f;
2798 else if(t->spacetype == SPACE_IMAGE) {
2800 t->snap[1] = 0.125f;
2801 t->snap[2] = 0.0625f;
2805 t->snap[1] = t->snap[2] = 1.0f;
2809 static void headerTranslation(TransInfo *t, float vec[3], char *str) {
2816 convertVecToDisplayNum(vec, dvec);
2818 if (hasNumInput(&t->num)) {
2819 outputNumInput(&(t->num), tvec);
2820 dist = VecLength(t->num.val);
2823 dist = VecLength(vec);
2824 sprintf(&tvec[0], "%.4f", dvec[0]);
2825 sprintf(&tvec[20], "%.4f", dvec[1]);
2826 sprintf(&tvec[40], "%.4f", dvec[2]);
2829 if( dist > 1e10 || dist < -1e10 ) /* prevent string buffer overflow */
2830 sprintf(distvec, "%.4e", dist);
2832 sprintf(distvec, "%.4f", dist);
2834 if(t->flag & T_AUTOIK) {
2835 short chainlen= G.scene->toolsettings->autoik_chainlen;
2838 sprintf(autoik, "AutoIK-Len: %d", chainlen);
2845 if (t->con.mode & CON_APPLY) {
2846 switch(t->num.idx_max) {
2848 sprintf(str, "D: %s (%s)%s %s %s", &tvec[0], distvec, t->con.text, t->proptext, &autoik[0]);
2851 sprintf(str, "D: %s D: %s (%s)%s %s %s", &tvec[0], &tvec[20], distvec, t->con.text, t->proptext, &autoik[0]);
2854 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]);
2858 if(t->flag & T_2D_EDIT)
2859 sprintf(str, "Dx: %s Dy: %s (%s)%s %s", &tvec[0], &tvec[20], distvec, t->con.text, t->proptext);
2861 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]);
2865 static void applyTranslation(TransInfo *t, float vec[3]) {
2866 TransData *td = t->data;
2870 for(i = 0 ; i < t->total; i++, td++) {
2871 if (td->flag & TD_NOACTION)
2874 if (td->flag & TD_SKIP)
2877 /* handle snapping rotation before doing the translation */
2878 if (usingSnappingNormal(t))
2880 if (validSnappingNormal(t))
2882 float *original_normal = td->axismtx[2];
2888 Crossf(axis, original_normal, t->tsnap.snapNormal);
2889 angle = saacos(Inpf(original_normal, t->tsnap.snapNormal));
2891 AxisAngleToQuat(quat, axis, angle);
2893 QuatToMat3(quat, mat);
2895 ElementRotation(t, td, mat, V3D_LOCAL);
2903 ElementRotation(t, td, mat, V3D_LOCAL);
2907 if (t->con.applyVec) {
2909 t->con.applyVec(t, td, vec, tvec, pvec);
2915 Mat3MulVecfl(td->smtx, tvec);
2916 VecMulf(tvec, td->factor);
2918 protectedTransBits(td->protectflag, tvec);
2920 /* transdata ipokey */
2922 TransDataIpokey *tdi= td->tdi;
2923 add_tdi_poin(tdi->locx, tdi->oldloc, tvec[0]);
2924 add_tdi_poin(tdi->locy, tdi->oldloc+1, tvec[1]);
2925 add_tdi_poin(tdi->locz, tdi->oldloc+2, tvec[2]);
2927 else VecAddf(td->loc, td->iloc, tvec);
2929 constraintTransLim(t, td);
2933 /* uses t->vec to store actual translation in */
2934 int Translation(TransInfo *t, short mval[2])
2939 if (t->con.mode & CON_APPLY) {
2940 float pvec[3] = {0.0f, 0.0f, 0.0f};
2941 applySnapping(t, t->values);
2942 t->con.applyVec(t, NULL, t->values, tvec, pvec);
2943 VECCOPY(t->values, tvec);
2944 headerTranslation(t, pvec, str);
2947 applyNDofInput(&t->ndof, t->values);
2948 snapGrid(t, t->values);
2949 applyNumInput(&t->num, t->values);
2950 applySnapping(t, t->values);
2951 headerTranslation(t, t->values, str);
2954 applyTranslation(t, t->values);
2956 /* evil hack - redo translation if cliiping needeed */
2957 if (t->flag & T_CLIP_UV && clipUVTransform(t, t->values, 0))
2958 applyTranslation(t, t->values);
2962 ED_area_headerprint(t->sa, str);
2971 /* ************************** SHRINK/FATTEN *************************** */
2973 void initShrinkFatten(TransInfo *t)
2975 // If not in mesh edit mode, fallback to Resize
2976 if (t->obedit==NULL || t->obedit->type != OB_MESH) {
2980 t->mode = TFM_SHRINKFATTEN;
2981 t->transform = ShrinkFatten;
2983 initMouseInputMode(t, &t->mouse, INPUT_VERTICAL_ABSOLUTE);
2989 t->snap[2] = t->snap[1] * 0.1f;
2991 t->flag |= T_NO_CONSTRAINT;
2997 int ShrinkFatten(TransInfo *t, short mval[2])
3003 TransData *td = t->data;
3005 distance = -t->values[0];
3007 snapGrid(t, &distance);
3009 applyNumInput(&t->num, &distance);
3011 /* header print for NumInput */
3012 if (hasNumInput(&t->num)) {
3015 outputNumInput(&(t->num), c);
3017 sprintf(str, "Shrink/Fatten: %s %s", c, t->proptext);