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_editaction.h"
81 #include "BKE_action.h" /* get_action_frame */
82 //#include "BKE_bad_level_calls.h"/* popmenu and error */
83 #include "BKE_bmesh.h"
84 #include "BKE_context.h"
85 #include "BKE_constraint.h"
86 #include "BKE_global.h"
87 #include "BKE_particle.h"
88 #include "BKE_pointcache.h"
89 #include "BKE_utildefines.h"
90 #include "BKE_context.h"
92 //#include "BSE_drawipo.h"
93 //#include "BSE_editnla_types.h" /* for NLAWIDTH */
94 //#include "BSE_editaction_types.h"
95 //#include "BSE_time.h"
96 //#include "BSE_view.h"
99 #include "ED_screen.h"
100 #include "ED_space_api.h"
102 #include "ED_view3d.h"
104 #include "UI_view2d.h"
105 #include "WM_types.h"
108 #include "BLI_arithb.h"
109 #include "BLI_blenlib.h"
110 #include "BLI_editVert.h"
112 #include "PIL_time.h" /* sleep */
114 //#include "blendef.h"
116 //#include "mydevice.h"
118 #include "transform.h"
120 /* ************************** Dashed help line **************************** */
123 /* bad frontbuffer call... because it is used in transform after force_draw() */
124 static void helpline(TransInfo *t, float *vec)
126 #if 0 // TRANSFORM_FIX_ME
127 float vecrot[3], cent[2];
130 VECCOPY(vecrot, vec);
131 if(t->flag & T_EDIT) {
132 Object *ob= t->obedit;
133 if(ob) Mat4MulVecfl(ob->obmat, vecrot);
135 else if(t->flag & T_POSE) {
136 Object *ob=t->poseobj;
137 if(ob) Mat4MulVecfl(ob->obmat, vecrot);
140 getmouseco_areawin(mval);
141 projectFloatView(t, vecrot, cent); // no overflow in extreme cases
145 glDrawBuffer(GL_FRONT);
147 BIF_ThemeColor(TH_WIRE);
150 glBegin(GL_LINE_STRIP);
157 bglFlush(); // flush display for frontbuffer
158 glDrawBuffer(GL_BACK);
162 /* ************************** SPACE DEPENDANT CODE **************************** */
164 void setTransformViewMatrices(TransInfo *t)
166 if(t->spacetype==SPACE_VIEW3D) {
167 RegionView3D *rv3d = t->ar->regiondata;
169 Mat4CpyMat4(t->viewmat, rv3d->viewmat);
170 Mat4CpyMat4(t->viewinv, rv3d->viewinv);
171 Mat4CpyMat4(t->persmat, rv3d->persmat);
172 Mat4CpyMat4(t->persinv, rv3d->persinv);
173 t->persp = rv3d->persp;
180 t->persp = V3D_ORTHO;
183 calculateCenter2D(t);
186 void convertViewVec(TransInfo *t, float *vec, short dx, short dy)
188 if (t->spacetype==SPACE_VIEW3D) {
189 window_to_3d_delta(t->ar, vec, dx, dy);
191 else if(t->spacetype==SPACE_IMAGE) {
192 View2D *v2d = t->view;
193 float divx, divy, aspx, aspy;
195 ED_space_image_uv_aspect(t->sa->spacedata.first, &aspx, &aspy);
197 divx= v2d->mask.xmax-v2d->mask.xmin;
198 divy= v2d->mask.ymax-v2d->mask.ymin;
200 vec[0]= aspx*(v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx;
201 vec[1]= aspy*(v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy;
204 else if(t->spacetype==SPACE_IPO) {
205 View2D *v2d = t->view;
208 divx= v2d->mask.xmax-v2d->mask.xmin;
209 divy= v2d->mask.ymax-v2d->mask.ymin;
211 vec[0]= (v2d->cur.xmax-v2d->cur.xmin)*(dx) / (divx);
212 vec[1]= (v2d->cur.ymax-v2d->cur.ymin)*(dy) / (divy);
215 else if(t->spacetype==SPACE_NODE) {
216 View2D *v2d = &t->ar->v2d;
219 divx= v2d->mask.xmax-v2d->mask.xmin;
220 divy= v2d->mask.ymax-v2d->mask.ymin;
222 vec[0]= (v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx;
223 vec[1]= (v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy;
226 else if(t->spacetype==SPACE_SEQ) {
227 View2D *v2d = &t->ar->v2d;
230 divx= v2d->mask.xmax-v2d->mask.xmin;
231 divy= v2d->mask.ymax-v2d->mask.ymin;
233 vec[0]= (v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx;
234 vec[1]= (v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy;
239 void projectIntView(TransInfo *t, float *vec, int *adr)
241 if (t->spacetype==SPACE_VIEW3D) {
242 project_int_noclip(t->ar, vec, adr);
244 else if(t->spacetype==SPACE_IMAGE) {
245 float aspx, aspy, v[2];
247 ED_space_image_uv_aspect(t->sa->spacedata.first, &aspx, &aspy);
251 UI_view2d_to_region_no_clip(t->view, v[0], v[1], adr, adr+1);
253 else if(t->spacetype==SPACE_IPO) {
256 UI_view2d_view_to_region((View2D *)t->view, vec[0], vec[1], out, out+1);
260 else if(t->spacetype==SPACE_SEQ) { /* XXX not tested yet, but should work */
263 UI_view2d_view_to_region((View2D *)t->view, vec[0], vec[1], out, out+1);
269 void projectFloatView(TransInfo *t, float *vec, float *adr)
271 if (t->spacetype==SPACE_VIEW3D) {
272 project_float_noclip(t->ar, vec, adr);
274 else if(t->spacetype==SPACE_IMAGE) {
277 projectIntView(t, vec, a);
281 else if(t->spacetype==SPACE_IPO) {
284 projectIntView(t, vec, a);
290 void applyAspectRatio(TransInfo *t, float *vec)
292 SpaceImage *sima= t->sa->spacedata.first;
294 if ((t->spacetype==SPACE_IMAGE) && (t->mode==TFM_TRANSLATION)) {
297 if((sima->flag & SI_COORDFLOATS)==0) {
299 ED_space_image_size(sima, &width, &height);
305 ED_space_image_uv_aspect(sima, &aspx, &aspy);
311 void removeAspectRatio(TransInfo *t, float *vec)
313 SpaceImage *sima= t->sa->spacedata.first;
315 if ((t->spacetype==SPACE_IMAGE) && (t->mode==TFM_TRANSLATION)) {
318 if((sima->flag & SI_COORDFLOATS)==0) {
320 ED_space_image_size(sima, &width, &height);
326 ED_space_image_uv_aspect(sima, &aspx, &aspy);
332 static void viewRedrawForce(bContext *C, TransInfo *t)
334 if (t->spacetype == SPACE_VIEW3D)
336 /* Do we need more refined tags? */
337 WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
339 else if (t->spacetype == SPACE_ACTION) {
340 SpaceAction *saction= (SpaceAction *)t->sa->spacedata.first;
347 ED_area_tag_redraw(t->sa);
349 else if (t->spacetype == SPACE_IPO) {
350 SpaceIpo *sipo= (SpaceIpo *)t->sa->spacedata.first;
357 ED_area_tag_redraw(t->sa);
359 else if(t->spacetype == SPACE_NODE)
361 //ED_area_tag_redraw(t->sa);
362 WM_event_add_notifier(C, NC_SCENE|ND_NODES, NULL);
364 else if(t->spacetype == SPACE_SEQ)
366 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, NULL);
368 else if (t->spacetype==SPACE_IMAGE) {
369 // XXX how to deal with lock?
371 SpaceImage *sima= (SpaceImage*)t->sa->spacedata.first;
372 if(sima->lock) force_draw_plus(SPACE_VIEW3D, 0);
376 WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_DATA, t->obedit);
380 static void viewRedrawPost(TransInfo *t)
382 ED_area_headerprint(t->sa, NULL);
384 #if 0 // TRANSFORM_FIX_ME
385 if(t->spacetype==SPACE_VIEW3D) {
386 allqueue(REDRAWBUTSOBJECT, 0);
387 allqueue(REDRAWVIEW3D, 0);
389 else if(t->spacetype==SPACE_IMAGE) {
390 allqueue(REDRAWIMAGE, 0);
391 allqueue(REDRAWVIEW3D, 0);
393 else if(ELEM3(t->spacetype, SPACE_ACTION, SPACE_NLA, SPACE_IPO)) {
394 allqueue(REDRAWVIEW3D, 0);
395 allqueue(REDRAWACTION, 0);
396 allqueue(REDRAWNLA, 0);
397 allqueue(REDRAWIPO, 0);
398 allqueue(REDRAWTIME, 0);
399 allqueue(REDRAWBUTSOBJECT, 0);
402 scrarea_queue_headredraw(curarea);
406 /* ************************** TRANSFORMATIONS **************************** */
408 void BIF_selectOrientation() {
409 #if 0 // TRANSFORM_FIX_ME
411 char *str_menu = BIF_menustringTransformOrientation("Orientation");
412 val= pupmenu(str_menu);
421 static void view_editmove(unsigned short event)
423 #if 0 // TRANSFORM_FIX_ME
425 /* Regular: Zoom in */
426 /* Shift: Scroll up */
427 /* Ctrl: Scroll right */
428 /* Alt-Shift: Rotate up */
429 /* Alt-Ctrl: Rotate right */
431 /* only work in 3D window for now
432 * In the end, will have to send to event to a 2D window handler instead
434 if (Trans.flag & T_2D_EDIT)
440 if( G.qual & LR_SHIFTKEY ) {
441 if( G.qual & LR_ALTKEY ) {
442 G.qual &= ~LR_SHIFTKEY;
444 G.qual |= LR_SHIFTKEY;
448 } else if( G.qual & LR_CTRLKEY ) {
449 if( G.qual & LR_ALTKEY ) {
450 G.qual &= ~LR_CTRLKEY;
452 G.qual |= LR_CTRLKEY;
456 } else if(U.uiflag & USER_WHEELZOOMDIR)
457 persptoetsen(PADMINUS);
459 persptoetsen(PADPLUSKEY);
464 if( G.qual & LR_SHIFTKEY ) {
465 if( G.qual & LR_ALTKEY ) {
466 G.qual &= ~LR_SHIFTKEY;
468 G.qual |= LR_SHIFTKEY;
472 } else if( G.qual & LR_CTRLKEY ) {
473 if( G.qual & LR_ALTKEY ) {
474 G.qual &= ~LR_CTRLKEY;
476 G.qual |= LR_CTRLKEY;
480 } else if(U.uiflag & USER_WHEELZOOMDIR)
481 persptoetsen(PADPLUSKEY);
483 persptoetsen(PADMINUS);
490 setTransformViewMatrices(&Trans);
494 static char *transform_to_undostr(TransInfo *t)
497 case TFM_TRANSLATION:
509 case TFM_SHRINKFATTEN:
510 return "Shrink/Fatten";
520 return "Bevel Weight";
525 case TFM_BONE_ENVELOPE:
526 return "Bone Envelope";
527 case TFM_TIME_TRANSLATE:
528 return "Translate Anim. Data";
530 return "Scale Anim. Data";
541 /* ************************************************* */
543 void transformEvent(TransInfo *t, wmEvent *event)
545 float mati[3][3] = {{1.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 1.0f}};
546 char cmode = constraintModeToChar(t);
548 t->redraw |= handleMouseInput(t, &t->mouse, event);
550 if (event->type == MOUSEMOVE)
552 t->mval[0] = event->x - t->ar->winrct.xmin;
553 t->mval[1] = event->y - t->ar->winrct.ymin;
557 applyMouseInput(t, &t->mouse, t->mval, t->values);
561 switch (event->type){
562 /* enforce redraw of transform when modifiers are used */
565 t->modifiers |= MOD_SNAP_GEARS;
571 t->modifiers |= MOD_CONSTRAINT_PLANE;
576 if ((t->spacetype==SPACE_VIEW3D) && event->alt) {
577 #if 0 // TRANSFORM_FIX_ME
581 BIF_selectOrientation();
582 calc_manipulator_stats(curarea);
583 Mat3CpyMat4(t->spacemtx, G.vd->twmat);
584 warp_pointer(mval[0], mval[1]);
588 t->state = TRANS_CONFIRM;
593 if ((t->flag & T_NO_CONSTRAINT)==0) {
594 /* exception for switching to dolly, or trackball, in camera view */
595 if (t->flag & T_CAMERA) {
596 if (t->mode==TFM_TRANSLATION)
597 setLocalConstraint(t, (CON_AXIS2), "along local Z");
598 else if (t->mode==TFM_ROTATION) {
599 restoreTransObjects(t);
604 t->modifiers |= MOD_CONSTRAINT_SELECT;
605 if (t->con.mode & CON_APPLY) {
610 initSelectConstraint(t, t->spacemtx);
613 /* bit hackish... but it prevents mmb select to print the orientation from menu */
614 strcpy(t->spacename, "global");
615 initSelectConstraint(t, mati);
617 postSelectConstraint(t);
625 printf("cancelled\n");
626 t->state = TRANS_CANCEL;
631 t->state = TRANS_CONFIRM;
634 /* only switch when... */
635 if( ELEM3(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL) ) {
636 resetTransRestrictions(t);
637 restoreTransObjects(t);
643 /* only switch when... */
644 if( ELEM3(t->mode, TFM_ROTATION, TFM_TRANSLATION, TFM_TRACKBALL) ) {
645 resetTransRestrictions(t);
646 restoreTransObjects(t);
652 /* only switch when... */
653 if( ELEM4(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL, TFM_TRANSLATION) ) {
655 resetTransRestrictions(t);
657 if (t->mode == TFM_ROTATION) {
658 restoreTransObjects(t);
662 restoreTransObjects(t);
670 t->flag ^= T_PROP_CONNECTED;
671 sort_trans_data_dist(t);
672 calculatePropRatio(t);
681 if ((t->flag & T_NO_CONSTRAINT)==0) {
683 if (t->flag & T_2D_EDIT) {
687 if (t->con.mode & CON_USER) {
691 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
692 setUserConstraint(t, (CON_AXIS0), "along %s X");
693 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
694 setUserConstraint(t, (CON_AXIS1|CON_AXIS2), "locking %s X");
699 if (t->flag & T_2D_EDIT) {
700 setConstraint(t, mati, (CON_AXIS0), "along X axis");
703 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
704 setConstraint(t, mati, (CON_AXIS0), "along global X");
705 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
706 setConstraint(t, mati, (CON_AXIS1|CON_AXIS2), "locking global X");
713 if ((t->flag & T_NO_CONSTRAINT)==0) {
715 if (t->flag & T_2D_EDIT) {
719 if (t->con.mode & CON_USER) {
723 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
724 setUserConstraint(t, (CON_AXIS1), "along %s Y");
725 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
726 setUserConstraint(t, (CON_AXIS0|CON_AXIS2), "locking %s Y");
731 if (t->flag & T_2D_EDIT) {
732 setConstraint(t, mati, (CON_AXIS1), "along Y axis");
735 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
736 setConstraint(t, mati, (CON_AXIS1), "along global Y");
737 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
738 setConstraint(t, mati, (CON_AXIS0|CON_AXIS2), "locking global Y");
745 if ((t->flag & T_NO_CONSTRAINT)==0) {
747 if (t->con.mode & CON_USER) {
751 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
752 setUserConstraint(t, (CON_AXIS2), "along %s Z");
753 else if ((t->modifiers & MOD_CONSTRAINT_PLANE) && ((t->flag & T_2D_EDIT)==0))
754 setUserConstraint(t, (CON_AXIS0|CON_AXIS1), "locking %s Z");
757 else if ((t->flag & T_2D_EDIT)==0) {
758 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
759 setConstraint(t, mati, (CON_AXIS2), "along global Z");
760 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
761 setConstraint(t, mati, (CON_AXIS0|CON_AXIS1), "locking global Z");
767 if (t->flag & T_PROP_EDIT && event->keymodifier == KM_SHIFT) {
768 t->scene->prop_mode = (t->scene->prop_mode+1)%6;
769 calculatePropRatio(t);
774 if(event->keymodifier & KM_ALT && t->flag & T_PROP_EDIT) {
776 calculatePropRatio(t);
782 if (t->flag & T_AUTOIK) {
783 transform_autoik_update(t, 1);
785 else if(t->flag & T_PROP_EDIT) {
787 calculatePropRatio(t);
789 else view_editmove(event->type);
793 if(event->keymodifier & KM_ALT && t->flag & T_PROP_EDIT) {
794 t->prop_size*= 0.90909090f;
795 calculatePropRatio(t);
801 if (t->flag & T_AUTOIK) {
802 transform_autoik_update(t, -1);
804 else if (t->flag & T_PROP_EDIT) {
805 t->prop_size*= 0.90909090f;
806 calculatePropRatio(t);
808 else view_editmove(event->type);
816 // Numerical input events
817 t->redraw |= handleNumInput(&(t->num), event);
820 switch(handleNDofInput(&(t->ndof), event))
823 if ((t->options & CTX_NDOF) == 0)
825 /* Confirm on normal transform only */
826 t->state = TRANS_CONFIRM;
830 if (t->options & CTX_NDOF)
832 /* Cancel on pure NDOF transform */
833 t->state = TRANS_CANCEL;
837 /* Otherwise, just redraw, NDof input was cancelled */
842 if (t->options & CTX_NDOF)
844 /* Confirm on pure NDOF transform */
845 t->state = TRANS_CONFIRM;
855 t->redraw |= handleSnapping(t, event);
857 //arrows_move_cursor(event->type);
860 switch (event->type){
863 t->modifiers &= ~MOD_CONSTRAINT_PLANE;
869 t->modifiers &= ~MOD_SNAP_GEARS;
870 /* no redraw on release modifier keys! this makes sure you can assign the 'grid' still
871 after releasing modifer key */
875 if ((t->flag & T_NO_CONSTRAINT)==0) {
876 t->modifiers &= ~MOD_CONSTRAINT_SELECT;
877 postSelectConstraint(t);
883 if(WM_modal_tweak_exit(event, t->event_type))
884 // if (t->options & CTX_TWEAK)
885 t->state = TRANS_CONFIRM;
890 // Per transform event, if present
892 t->redraw |= t->handleEvent(t, event);
895 int calculateTransformCenter(bContext *C, wmEvent *event, int centerMode, float *vec)
897 TransInfo *t = MEM_callocN(sizeof(TransInfo), "TransInfo data");
900 t->state = TRANS_RUNNING;
902 t->options = CTX_NONE;
906 initTransInfo(C, t, NULL, event); // internal data, mouse, vectors
908 createTransData(C, t); // make TransData structs from selection
910 t->around = centerMode; // override userdefined mode
920 // Copy center from constraint center. Transform center can be local
921 VECCOPY(vec, t->con.center);
926 /* aftertrans does insert ipos and action channels, and clears base flags, doesnt read transdata */
927 special_aftertrans_update(t);
934 void drawTransform(const struct bContext *C, struct ARegion *ar, void *arg)
943 void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
945 Scene *sce = CTX_data_scene(C);
946 int constraint_axis[3] = {0, 0, 0};
947 int proportional = 0;
949 RNA_int_set(op->ptr, "mode", t->mode);
950 RNA_int_set(op->ptr, "options", t->options);
952 if (t->flag & T_AUTOVALUES)
954 RNA_float_set_array(op->ptr, "value", t->auto_values);
958 RNA_float_set_array(op->ptr, "value", t->values);
961 /* XXX convert stupid flag to enum */
962 switch(t->flag & (T_PROP_EDIT|T_PROP_CONNECTED))
964 case (T_PROP_EDIT|T_PROP_CONNECTED):
974 if (RNA_struct_find_property(op->ptr, "proportional"))
976 RNA_enum_set(op->ptr, "proportional", proportional);
977 RNA_enum_set(op->ptr, "proportional_mode", t->prop_mode);
978 RNA_float_set(op->ptr, "proportional_size", t->prop_size);
981 if (RNA_struct_find_property(op->ptr, "mirror"))
983 RNA_boolean_set(op->ptr, "mirror", t->flag & T_MIRROR);
986 if (RNA_struct_find_property(op->ptr, "constraint_mode"))
988 RNA_int_set(op->ptr, "constraint_mode", t->con.mode);
989 RNA_int_set(op->ptr, "constraint_orientation", t->current_orientation);
991 if (t->con.mode & CON_APPLY)
993 if (t->con.mode & CON_AXIS0) {
994 constraint_axis[0] = 1;
996 if (t->con.mode & CON_AXIS1) {
997 constraint_axis[1] = 1;
999 if (t->con.mode & CON_AXIS2) {
1000 constraint_axis[2] = 1;
1004 RNA_boolean_set_array(op->ptr, "constraint_axis", constraint_axis);
1007 // XXX If modal, save settings back in scene
1008 if (t->flag & T_MODAL)
1010 sce->prop_mode = t->prop_mode;
1011 sce->proportional = proportional;
1013 if(t->spacetype == SPACE_VIEW3D)
1015 View3D *v3d = t->view;
1017 v3d->twmode = t->current_orientation;
1022 void initTransform(bContext *C, TransInfo *t, wmOperator *op, wmEvent *event, int mode)
1024 int options = RNA_int_get(op->ptr, "options");
1026 /* added initialize, for external calls to set stuff in TransInfo, like undo string */
1028 t->state = TRANS_RUNNING;
1030 t->options = options;
1034 initTransInfo(C, t, op, event); // internal data, mouse, vectors
1036 initTransformOrientation(C, t);
1038 if(t->spacetype == SPACE_VIEW3D)
1040 RegionView3D *rv3d = t->ar->regiondata;
1041 //calc_manipulator_stats(curarea);
1042 Mat3CpyMat4(t->spacemtx, rv3d->twmat);
1043 Mat3Ortho(t->spacemtx);
1045 t->draw_handle = ED_region_draw_cb_activate(t->ar->type, drawTransform, t, REGION_DRAW_POST);
1047 else if(t->spacetype == SPACE_IMAGE) {
1048 Mat3One(t->spacemtx);
1049 t->draw_handle = ED_region_draw_cb_activate(t->ar->type, drawTransform, t, REGION_DRAW_POST);
1052 Mat3One(t->spacemtx);
1054 createTransData(C, t); // make TransData structs from selection
1056 initSnapping(t); // Initialize snapping data AFTER mode flags
1058 if (t->total == 0) {
1063 /* EVIL! posemode code can switch translation to rotate when 1 bone is selected. will be removed (ton) */
1064 /* EVIL2: we gave as argument also texture space context bit... was cleared */
1065 /* EVIL3: extend mode for animation editors also switches modes... but is best way to avoid duplicate code */
1068 calculatePropRatio(t);
1071 initMouseInput(t, &t->mouse, t->center2d, t->imval);
1074 case TFM_TRANSLATION:
1092 case TFM_SHRINKFATTEN:
1093 initShrinkFatten(t);
1098 case TFM_CURVE_SHRINKFATTEN:
1099 initCurveShrinkFatten(t);
1111 { /* used for both B-Bone width (bonesize) as for deform-dist (envelope) */
1112 bArmature *arm= t->poseobj->data;
1113 if(arm->drawtype==ARM_ENVELOPE)
1114 initBoneEnvelope(t);
1119 case TFM_BONE_ENVELOPE:
1120 initBoneEnvelope(t);
1125 case TFM_TIME_TRANSLATE:
1126 initTimeTranslate(t);
1128 case TFM_TIME_SLIDE:
1131 case TFM_TIME_SCALE:
1134 case TFM_TIME_EXTEND:
1135 /* now that transdata has been made, do like for TFM_TIME_TRANSLATE (for most Animation
1136 * Editors because they have only 1D transforms for time values) or TFM_TRANSLATION
1137 * (for Graph Editor only since it uses 'standard' transforms to get 2D movement)
1138 * depending on which editor this was called from
1140 if (t->spacetype == SPACE_IPO)
1143 initTimeTranslate(t);
1162 /* overwrite initial values if operator supplied a non-null vector */
1163 if (RNA_property_is_set(op->ptr, "value"))
1166 RNA_float_get_array(op->ptr, "value", values);
1167 QUATCOPY(t->values, values);
1168 QUATCOPY(t->auto_values, values);
1169 t->flag |= T_AUTOVALUES;
1172 /* Constraint init from operator */
1173 if (RNA_property_is_set(op->ptr, "constraint_axis"))
1175 int constraint_axis[3];
1177 RNA_boolean_get_array(op->ptr, "constraint_axis", constraint_axis);
1179 if (constraint_axis[0] || constraint_axis[1] || constraint_axis[2])
1181 t->con.mode |= CON_APPLY;
1183 if (constraint_axis[0]) {
1184 t->con.mode |= CON_AXIS0;
1186 if (constraint_axis[1]) {
1187 t->con.mode |= CON_AXIS1;
1189 if (constraint_axis[2]) {
1190 t->con.mode |= CON_AXIS2;
1193 setUserConstraint(t, t->con.mode, "%s");
1198 void transformApply(bContext *C, TransInfo *t)
1202 if (t->modifiers & MOD_CONSTRAINT_SELECT)
1203 t->con.mode |= CON_SELECT;
1205 selectConstraint(t);
1207 t->transform(t, t->mval); // calls recalcData()
1208 viewRedrawForce(C, t);
1213 /* If auto confirm is on, break after one pass */
1214 if (t->options & CTX_AUTOCONFIRM)
1216 t->state = TRANS_CONFIRM;
1219 if (BKE_ptcache_get_continue_physics())
1222 //do_screenhandlers(G.curscreen);
1227 int transformEnd(bContext *C, TransInfo *t)
1229 int exit_code = OPERATOR_RUNNING_MODAL;
1231 if (t->state != TRANS_RUNNING)
1233 /* handle restoring objects */
1234 if(t->state == TRANS_CANCEL)
1236 exit_code = OPERATOR_CANCELLED;
1237 restoreTransObjects(t); // calls recalcData()
1241 exit_code = OPERATOR_FINISHED;
1247 /* aftertrans does insert keyframes, and clears base flags, doesnt read transdata */
1248 special_aftertrans_update(t);
1250 /* send events out for redraws */
1253 /* Undo as last, certainly after special_trans_update! */
1255 if(t->state == TRANS_CANCEL) {
1256 // if(t->undostr) ED_undo_push(C, t->undostr);
1259 // if(t->undostr) ED_undo_push(C, t->undostr);
1260 // else ED_undo_push(C, transform_to_undostr(t));
1264 viewRedrawForce(C, t);
1270 /* ************************** Manipulator init and main **************************** */
1272 void initManipulator(int mode)
1274 #if 0 // TRANSFORM_FIX_ME
1275 Trans.state = TRANS_RUNNING;
1277 Trans.options = CTX_NONE;
1281 /* automatic switch to scaling bone envelopes */
1282 if(mode==TFM_RESIZE && t->obedit && t->obedit->type==OB_ARMATURE) {
1283 bArmature *arm= t->obedit->data;
1284 if(arm->drawtype==ARM_ENVELOPE)
1285 mode= TFM_BONE_ENVELOPE;
1288 initTrans(&Trans); // internal data, mouse, vectors
1290 G.moving |= G_TRANSFORM_MANIP; // signal to draw manipuls while transform
1291 createTransData(&Trans); // make TransData structs from selection
1293 if (Trans.total == 0)
1296 initSnapping(&Trans); // Initialize snapping data AFTER mode flags
1298 /* EVIL! posemode code can switch translation to rotate when 1 bone is selected. will be removed (ton) */
1299 /* EVIL2: we gave as argument also texture space context bit... was cleared */
1302 calculatePropRatio(&Trans);
1303 calculateCenter(&Trans);
1306 case TFM_TRANSLATION:
1307 initTranslation(&Trans);
1310 initRotation(&Trans);
1316 initTrackball(&Trans);
1320 Trans.flag |= T_USES_MANIPULATOR;
1324 void ManipulatorTransform()
1326 #if 0 // TRANSFORM_FIX_ME
1327 int mouse_moved = 0;
1328 short pmval[2] = {0, 0}, mval[2], val;
1329 unsigned short event;
1331 if (Trans.total == 0)
1334 Trans.redraw = 1; /* initial draw */
1336 while (Trans.state == TRANS_RUNNING) {
1338 getmouseco_areawin(mval);
1340 if (mval[0] != pmval[0] || mval[1] != pmval[1]) {
1347 //selectConstraint(&Trans); needed?
1348 if (Trans.transform) {
1349 Trans.transform(&Trans, mval);
1354 /* essential for idling subloop */
1355 if( qtest()==0) PIL_sleep_ms(2);
1358 event= extern_qread(&val);
1365 /* enforce redraw of transform when modifiers are used */
1368 if(val) Trans.redraw = 1;
1372 /* shift is modifier for higher resolution transform, works nice to store this mouse position */
1374 getmouseco_areawin(Trans.shiftmval);
1375 Trans.flag |= T_SHIFT_MOD;
1378 else Trans.flag &= ~T_SHIFT_MOD;
1383 Trans.state = TRANS_CANCEL;
1386 if(mouse_moved==0 && val==0) break;
1387 // else we pass on event to next, which cancels
1391 Trans.state = TRANS_CONFIRM;
1400 if(G.qual & LR_ALTKEY && Trans.flag & T_PROP_EDIT) {
1401 Trans.propsize*= 1.1f;
1402 calculatePropRatio(&Trans);
1407 case WHEELDOWNMOUSE:
1408 if (Trans.flag & T_AUTOIK) {
1409 transform_autoik_update(&Trans, 1);
1411 else if(Trans.flag & T_PROP_EDIT) {
1412 Trans.propsize*= 1.1f;
1413 calculatePropRatio(&Trans);
1415 else view_editmove(event);
1419 if(G.qual & LR_ALTKEY && Trans.flag & T_PROP_EDIT) {
1420 Trans.propsize*= 0.90909090f;
1421 calculatePropRatio(&Trans);
1427 if (Trans.flag & T_AUTOIK) {
1428 transform_autoik_update(&Trans, -1);
1430 else if (Trans.flag & T_PROP_EDIT) {
1431 Trans.propsize*= 0.90909090f;
1432 calculatePropRatio(&Trans);
1434 else view_editmove(event);
1439 // Numerical input events
1440 Trans.redraw |= handleNumInput(&(Trans.num), event);
1445 if(Trans.state == TRANS_CANCEL) {
1446 restoreTransObjects(&Trans);
1449 /* free data, reset vars */
1452 /* aftertrans does insert ipos and action channels, and clears base flags */
1453 special_aftertrans_update(&Trans);
1455 /* send events out for redraws */
1456 viewRedrawPost(&Trans);
1458 if(Trans.state != TRANS_CANCEL) {
1459 BIF_undo_push(transform_to_undostr(&Trans));
1464 /* ************************** TRANSFORM LOCKS **************************** */
1466 static void protectedTransBits(short protectflag, float *vec)
1468 if(protectflag & OB_LOCK_LOCX)
1470 if(protectflag & OB_LOCK_LOCY)
1472 if(protectflag & OB_LOCK_LOCZ)
1476 static void protectedSizeBits(short protectflag, float *size)
1478 if(protectflag & OB_LOCK_SCALEX)
1480 if(protectflag & OB_LOCK_SCALEY)
1482 if(protectflag & OB_LOCK_SCALEZ)
1486 static void protectedRotateBits(short protectflag, float *eul, float *oldeul)
1488 if(protectflag & OB_LOCK_ROTX)
1490 if(protectflag & OB_LOCK_ROTY)
1492 if(protectflag & OB_LOCK_ROTZ)
1496 static void protectedQuaternionBits(short protectflag, float *quat, float *oldquat)
1498 /* quaternions get limited with euler... */
1499 /* this function only does the delta rotation */
1502 float eul[3], oldeul[3], quat1[4];
1504 QUATCOPY(quat1, quat);
1505 QuatToEul(quat, eul);
1506 QuatToEul(oldquat, oldeul);
1508 if(protectflag & OB_LOCK_ROTX)
1510 if(protectflag & OB_LOCK_ROTY)
1512 if(protectflag & OB_LOCK_ROTZ)
1515 EulToQuat(eul, quat);
1516 /* quaternions flip w sign to accumulate rotations correctly */
1517 if( (quat1[0]<0.0f && quat[0]>0.0f) || (quat1[0]>0.0f && quat[0]<0.0f) ) {
1518 QuatMulf(quat, -1.0f);
1523 /* ******************* TRANSFORM LIMITS ********************** */
1525 static void constraintTransLim(TransInfo *t, TransData *td)
1528 bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_LOCLIMIT);
1532 /* Make a temporary bConstraintOb for using these limit constraints
1533 * - they only care that cob->matrix is correctly set ;-)
1534 * - current space should be local
1536 memset(&cob, 0, sizeof(bConstraintOb));
1537 Mat4One(cob.matrix);
1539 TransDataIpokey *tdi= td->tdi;
1540 cob.matrix[3][0]= tdi->locx[0];
1541 cob.matrix[3][1]= tdi->locy[0];
1542 cob.matrix[3][2]= tdi->locz[0];
1545 VECCOPY(cob.matrix[3], td->loc);
1548 /* Evaluate valid constraints */
1549 for (con= td->con; con; con= con->next) {
1552 /* only consider constraint if enabled */
1553 if (con->flag & CONSTRAINT_DISABLE) continue;
1554 if (con->enforce == 0.0f) continue;
1556 /* only use it if it's tagged for this purpose (and the right type) */
1557 if (con->type == CONSTRAINT_TYPE_LOCLIMIT) {
1558 bLocLimitConstraint *data= con->data;
1560 if ((data->flag2 & LIMIT_TRANSFORM)==0)
1563 /* do space conversions */
1564 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1565 /* just multiply by td->mtx (this should be ok) */
1566 Mat4CpyMat4(tmat, cob.matrix);
1567 Mat4MulMat34(cob.matrix, td->mtx, tmat);
1569 else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) {
1570 /* skip... incompatable spacetype */
1575 cti->evaluate_constraint(con, &cob, NULL);
1577 /* convert spaces again */
1578 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1579 /* just multiply by td->mtx (this should be ok) */
1580 Mat4CpyMat4(tmat, cob.matrix);
1581 Mat4MulMat34(cob.matrix, td->smtx, tmat);
1586 /* copy results from cob->matrix */
1588 TransDataIpokey *tdi= td->tdi;
1589 tdi->locx[0]= cob.matrix[3][0];
1590 tdi->locy[0]= cob.matrix[3][1];
1591 tdi->locz[0]= cob.matrix[3][2];
1594 VECCOPY(td->loc, cob.matrix[3]);
1599 static void constraintRotLim(TransInfo *t, TransData *td)
1602 bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_ROTLIMIT);
1606 /* Make a temporary bConstraintOb for using these limit constraints
1607 * - they only care that cob->matrix is correctly set ;-)
1608 * - current space should be local
1610 memset(&cob, 0, sizeof(bConstraintOb));
1611 if (td->flag & TD_USEQUAT) {
1614 QuatToMat4(td->ext->quat, cob.matrix);
1619 /* ipo-keys eulers */
1620 TransDataIpokey *tdi= td->tdi;
1623 eul[0]= tdi->rotx[0];
1624 eul[1]= tdi->roty[0];
1625 eul[2]= tdi->rotz[0];
1627 EulToMat4(eul, cob.matrix);
1632 EulToMat4(td->ext->rot, cob.matrix);
1637 /* Evaluate valid constraints */
1638 for (con= td->con; con; con= con->next) {
1639 /* only consider constraint if enabled */
1640 if (con->flag & CONSTRAINT_DISABLE) continue;
1641 if (con->enforce == 0.0f) continue;
1643 /* we're only interested in Limit-Rotation constraints */
1644 if (con->type == CONSTRAINT_TYPE_ROTLIMIT) {
1645 bRotLimitConstraint *data= con->data;
1648 /* only use it if it's tagged for this purpose */
1649 if ((data->flag2 & LIMIT_TRANSFORM)==0)
1652 /* do space conversions */
1653 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1654 /* just multiply by td->mtx (this should be ok) */
1655 Mat4CpyMat4(tmat, cob.matrix);
1656 Mat4MulMat34(cob.matrix, td->mtx, tmat);
1658 else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) {
1659 /* skip... incompatable spacetype */
1664 cti->evaluate_constraint(con, &cob, NULL);
1666 /* convert spaces again */
1667 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1668 /* just multiply by td->mtx (this should be ok) */
1669 Mat4CpyMat4(tmat, cob.matrix);
1670 Mat4MulMat34(cob.matrix, td->smtx, tmat);
1675 /* copy results from cob->matrix */
1676 if (td->flag & TD_USEQUAT) {
1678 Mat4ToQuat(cob.matrix, td->ext->quat);
1681 /* ipo-keys eulers */
1682 TransDataIpokey *tdi= td->tdi;
1685 Mat4ToEul(cob.matrix, eul);
1687 tdi->rotx[0]= eul[0];
1688 tdi->roty[0]= eul[1];
1689 tdi->rotz[0]= eul[2];
1693 Mat4ToEul(cob.matrix, td->ext->rot);
1698 static void constraintSizeLim(TransInfo *t, TransData *td)
1700 if (td->con && td->ext) {
1701 bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_SIZELIMIT);
1705 /* Make a temporary bConstraintOb for using these limit constraints
1706 * - they only care that cob->matrix is correctly set ;-)
1707 * - current space should be local
1709 memset(&cob, 0, sizeof(bConstraintOb));
1711 TransDataIpokey *tdi= td->tdi;
1714 size[0]= tdi->sizex[0];
1715 size[1]= tdi->sizey[0];
1716 size[2]= tdi->sizez[0];
1717 SizeToMat4(size, cob.matrix);
1719 else if ((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)) {
1720 /* scale val and reset size */
1721 return; // TODO: fix this case
1724 /* Reset val if SINGLESIZE but using a constraint */
1725 if (td->flag & TD_SINGLESIZE)
1728 SizeToMat4(td->ext->size, cob.matrix);
1731 /* Evaluate valid constraints */
1732 for (con= td->con; con; con= con->next) {
1733 /* only consider constraint if enabled */
1734 if (con->flag & CONSTRAINT_DISABLE) continue;
1735 if (con->enforce == 0.0f) continue;
1737 /* we're only interested in Limit-Scale constraints */
1738 if (con->type == CONSTRAINT_TYPE_SIZELIMIT) {
1739 bSizeLimitConstraint *data= con->data;
1742 /* only use it if it's tagged for this purpose */
1743 if ((data->flag2 & LIMIT_TRANSFORM)==0)
1746 /* do space conversions */
1747 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1748 /* just multiply by td->mtx (this should be ok) */
1749 Mat4CpyMat4(tmat, cob.matrix);
1750 Mat4MulMat34(cob.matrix, td->mtx, tmat);
1752 else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) {
1753 /* skip... incompatable spacetype */
1758 cti->evaluate_constraint(con, &cob, NULL);
1760 /* convert spaces again */
1761 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1762 /* just multiply by td->mtx (this should be ok) */
1763 Mat4CpyMat4(tmat, cob.matrix);
1764 Mat4MulMat34(cob.matrix, td->smtx, tmat);
1769 /* copy results from cob->matrix */
1771 TransDataIpokey *tdi= td->tdi;
1774 Mat4ToSize(cob.matrix, size);
1776 tdi->sizex[0]= size[0];
1777 tdi->sizey[0]= size[1];
1778 tdi->sizez[0]= size[2];
1780 else if ((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)) {
1781 /* scale val and reset size */
1782 return; // TODO: fix this case
1785 /* Reset val if SINGLESIZE but using a constraint */
1786 if (td->flag & TD_SINGLESIZE)
1789 Mat4ToSize(cob.matrix, td->ext->size);
1794 /* ************************** WARP *************************** */
1796 void initWarp(TransInfo *t)
1798 float max[3], min[3];
1802 t->transform = Warp;
1803 t->handleEvent = handleEventWarp;
1805 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_RATIO);
1813 t->flag |= T_NO_CONSTRAINT;
1815 /* we need min/max in view space */
1816 for(i = 0; i < t->total; i++) {
1818 VECCOPY(center, t->data[i].center);
1819 Mat3MulVecfl(t->data[i].mtx, center);
1820 Mat4MulVecfl(t->viewmat, center);
1821 VecSubf(center, center, t->viewmat[3]);
1823 MinMax3(min, max, center);
1825 VECCOPY(max, center);
1826 VECCOPY(min, center);
1830 t->center[0]= (min[0]+max[0])/2.0f;
1831 t->center[1]= (min[1]+max[1])/2.0f;
1832 t->center[2]= (min[2]+max[2])/2.0f;
1834 if (max[0] == min[0]) max[0] += 0.1; /* not optimal, but flipping is better than invalid garbage (i.e. division by zero!) */
1835 t->val= (max[0]-min[0])/2.0f; /* t->val is X dimension projected boundbox */
1838 int handleEventWarp(TransInfo *t, wmEvent *event)
1842 if (event->type == MIDDLEMOUSE && event->val)
1844 // Use customData pointer to signal warp direction
1845 if (t->customData == 0)
1846 t->customData = (void*)1;
1856 int Warp(TransInfo *t, short mval[2])
1858 TransData *td = t->data;
1859 float vec[3], circumfac, dist, phi0, co, si, *curs, cursor[3], gcursor[3];
1863 curs= give_cursor(t->scene, t->view);
1865 * gcursor is the one used for helpline.
1866 * It has to be in the same space as the drawing loop
1867 * (that means it needs to be in the object's space when in edit mode and
1868 * in global space in object mode)
1870 * cursor is used for calculations.
1871 * It needs to be in view space, but we need to take object's offset
1872 * into account if in Edit mode.
1874 VECCOPY(cursor, curs);
1875 VECCOPY(gcursor, cursor);
1876 if (t->flag & T_EDIT) {
1877 VecSubf(cursor, cursor, t->obedit->obmat[3]);
1878 VecSubf(gcursor, gcursor, t->obedit->obmat[3]);
1879 Mat3MulVecfl(t->data->smtx, gcursor);
1881 Mat4MulVecfl(t->viewmat, cursor);
1882 VecSubf(cursor, cursor, t->viewmat[3]);
1884 /* amount of degrees for warp */
1885 circumfac = 360.0f * t->values[0];
1887 if (t->customData) /* non-null value indicates reversed input */
1892 snapGrid(t, &circumfac);
1893 applyNumInput(&t->num, &circumfac);
1895 /* header print for NumInput */
1896 if (hasNumInput(&t->num)) {
1899 outputNumInput(&(t->num), c);
1901 sprintf(str, "Warp: %s", c);
1904 /* default header print */
1905 sprintf(str, "Warp: %.3f", circumfac);
1908 circumfac*= (float)(-M_PI/360.0);
1910 for(i = 0; i < t->total; i++, td++) {
1912 if (td->flag & TD_NOACTION)
1915 if (td->flag & TD_SKIP)
1918 /* translate point to center, rotate in such a way that outline==distance */
1919 VECCOPY(vec, td->iloc);
1920 Mat3MulVecfl(td->mtx, vec);
1921 Mat4MulVecfl(t->viewmat, vec);
1922 VecSubf(vec, vec, t->viewmat[3]);
1924 dist= vec[0]-cursor[0];
1926 /* t->val is X dimension projected boundbox */
1927 phi0= (circumfac*dist/t->val);
1929 vec[1]= (vec[1]-cursor[1]);
1931 co= (float)cos(phi0);
1932 si= (float)sin(phi0);
1933 loc[0]= -si*vec[1]+cursor[0];
1934 loc[1]= co*vec[1]+cursor[1];
1937 Mat4MulVecfl(t->viewinv, loc);
1938 VecSubf(loc, loc, t->viewinv[3]);
1939 Mat3MulVecfl(td->smtx, loc);
1941 VecSubf(loc, loc, td->iloc);
1942 VecMulf(loc, td->factor);
1943 VecAddf(td->loc, td->iloc, loc);
1948 ED_area_headerprint(t->sa, str);
1950 helpline(t, gcursor);
1955 /* ************************** SHEAR *************************** */
1957 void initShear(TransInfo *t)
1959 t->mode = TFM_SHEAR;
1960 t->transform = Shear;
1961 t->handleEvent = handleEventShear;
1963 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_ABSOLUTE);
1969 t->snap[2] = t->snap[1] * 0.1f;
1971 t->flag |= T_NO_CONSTRAINT;
1974 int handleEventShear(TransInfo *t, wmEvent *event)
1978 if (event->type == MIDDLEMOUSE && event->val)
1980 // Use customData pointer to signal Shear direction
1981 if (t->customData == 0)
1983 initMouseInputMode(t, &t->mouse, INPUT_VERTICAL_ABSOLUTE);
1984 t->customData = (void*)1;
1988 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_ABSOLUTE);
1999 int Shear(TransInfo *t, short mval[2])
2001 TransData *td = t->data;
2003 float smat[3][3], tmat[3][3], totmat[3][3], persmat[3][3], persinv[3][3];
2008 Mat3CpyMat4(persmat, t->viewmat);
2009 Mat3Inv(persinv, persmat);
2011 value = 0.05f * t->values[0];
2013 snapGrid(t, &value);
2015 applyNumInput(&t->num, &value);
2017 /* header print for NumInput */
2018 if (hasNumInput(&t->num)) {
2021 outputNumInput(&(t->num), c);
2023 sprintf(str, "Shear: %s %s", c, t->proptext);
2026 /* default header print */
2027 sprintf(str, "Shear: %.3f %s", value, t->proptext);
2032 // Custom data signals shear direction
2033 if (t->customData == 0)
2038 Mat3MulMat3(tmat, smat, persmat);
2039 Mat3MulMat3(totmat, persinv, tmat);
2041 for(i = 0 ; i < t->total; i++, td++) {
2042 if (td->flag & TD_NOACTION)
2045 if (td->flag & TD_SKIP)
2050 Mat3MulMat3(mat3, totmat, td->mtx);
2051 Mat3MulMat3(tmat, td->smtx, mat3);
2054 Mat3CpyMat3(tmat, totmat);
2056 VecSubf(vec, td->center, t->center);
2058 Mat3MulVecfl(tmat, vec);
2060 VecAddf(vec, vec, t->center);
2061 VecSubf(vec, vec, td->center);
2063 VecMulf(vec, td->factor);
2065 VecAddf(td->loc, td->iloc, vec);
2070 ED_area_headerprint(t->sa, str);
2072 helpline (t, t->center);
2077 /* ************************** RESIZE *************************** */
2079 void initResize(TransInfo *t)
2081 t->mode = TFM_RESIZE;
2082 t->transform = Resize;
2084 initMouseInputMode(t, &t->mouse, INPUT_SPRING_FLIP);
2086 t->flag |= T_NULL_ONE;
2087 t->num.flag |= NUM_NULL_ONE;
2088 t->num.flag |= NUM_AFFECT_ALL;
2090 t->flag |= T_NO_ZERO;
2091 t->num.flag |= NUM_NO_ZERO;
2098 t->snap[2] = t->snap[1] * 0.1f;
2101 static void headerResize(TransInfo *t, float vec[3], char *str) {
2103 if (hasNumInput(&t->num)) {
2104 outputNumInput(&(t->num), tvec);
2107 sprintf(&tvec[0], "%.4f", vec[0]);
2108 sprintf(&tvec[20], "%.4f", vec[1]);
2109 sprintf(&tvec[40], "%.4f", vec[2]);
2112 if (t->con.mode & CON_APPLY) {
2113 switch(t->num.idx_max) {
2115 sprintf(str, "Scale: %s%s %s", &tvec[0], t->con.text, t->proptext);
2118 sprintf(str, "Scale: %s : %s%s %s", &tvec[0], &tvec[20], t->con.text, t->proptext);
2121 sprintf(str, "Scale: %s : %s : %s%s %s", &tvec[0], &tvec[20], &tvec[40], t->con.text, t->proptext);
2125 if (t->flag & T_2D_EDIT)
2126 sprintf(str, "Scale X: %s Y: %s%s %s", &tvec[0], &tvec[20], t->con.text, t->proptext);
2128 sprintf(str, "Scale X: %s Y: %s Z: %s%s %s", &tvec[0], &tvec[20], &tvec[40], t->con.text, t->proptext);
2132 #define SIGN(a) (a<-FLT_EPSILON?1:a>FLT_EPSILON?2:3)
2133 #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)
2135 /* smat is reference matrix, only scaled */
2136 static void TransMat3ToSize( float mat[][3], float smat[][3], float *size)
2140 VecCopyf(vec, mat[0]);
2141 size[0]= Normalize(vec);
2142 VecCopyf(vec, mat[1]);
2143 size[1]= Normalize(vec);
2144 VecCopyf(vec, mat[2]);
2145 size[2]= Normalize(vec);
2147 /* first tried with dotproduct... but the sign flip is crucial */
2148 if( VECSIGNFLIP(mat[0], smat[0]) ) size[0]= -size[0];
2149 if( VECSIGNFLIP(mat[1], smat[1]) ) size[1]= -size[1];
2150 if( VECSIGNFLIP(mat[2], smat[2]) ) size[2]= -size[2];
2154 static void ElementResize(TransInfo *t, TransData *td, float mat[3][3]) {
2155 float tmat[3][3], smat[3][3], center[3];
2158 if (t->flag & T_EDIT) {
2159 Mat3MulMat3(smat, mat, td->mtx);
2160 Mat3MulMat3(tmat, td->smtx, smat);
2163 Mat3CpyMat3(tmat, mat);
2166 if (t->con.applySize) {
2167 t->con.applySize(t, td, tmat);
2170 /* local constraint shouldn't alter center */
2171 if (t->around == V3D_LOCAL) {
2172 if (t->flag & T_OBJECT) {
2173 VECCOPY(center, td->center);
2175 else if (t->flag & T_EDIT) {
2177 if(t->around==V3D_LOCAL && (t->scene->selectmode & SCE_SELECT_FACE)) {
2178 VECCOPY(center, td->center);
2181 VECCOPY(center, t->center);
2185 VECCOPY(center, t->center);
2189 VECCOPY(center, t->center);
2195 if (t->flag & (T_OBJECT|T_TEXTURE|T_POSE)) {
2196 float obsizemat[3][3];
2197 // Reorient the size mat to fit the oriented object.
2198 Mat3MulMat3(obsizemat, tmat, td->axismtx);
2199 //printmatrix3("obsizemat", obsizemat);
2200 TransMat3ToSize(obsizemat, td->axismtx, fsize);
2201 //printvecf("fsize", fsize);
2204 Mat3ToSize(tmat, fsize);
2207 protectedSizeBits(td->protectflag, fsize);
2209 if ((t->flag & T_V3D_ALIGN)==0) { // align mode doesn't resize objects itself
2210 /* handle ipokeys? */
2212 TransDataIpokey *tdi= td->tdi;
2213 /* calculate delta size (equal for size and dsize) */
2215 vec[0]= (tdi->oldsize[0])*(fsize[0] -1.0f) * td->factor;
2216 vec[1]= (tdi->oldsize[1])*(fsize[1] -1.0f) * td->factor;
2217 vec[2]= (tdi->oldsize[2])*(fsize[2] -1.0f) * td->factor;
2219 add_tdi_poin(tdi->sizex, tdi->oldsize, vec[0]);
2220 add_tdi_poin(tdi->sizey, tdi->oldsize+1, vec[1]);
2221 add_tdi_poin(tdi->sizez, tdi->oldsize+2, vec[2]);
2224 else if((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)){
2225 /* scale val and reset size */
2226 *td->val = td->ival * fsize[0] * td->factor;
2228 td->ext->size[0] = td->ext->isize[0];
2229 td->ext->size[1] = td->ext->isize[1];
2230 td->ext->size[2] = td->ext->isize[2];
2233 /* Reset val if SINGLESIZE but using a constraint */
2234 if (td->flag & TD_SINGLESIZE)
2235 *td->val = td->ival;
2237 td->ext->size[0] = td->ext->isize[0] * (fsize[0]) * td->factor;
2238 td->ext->size[1] = td->ext->isize[1] * (fsize[1]) * td->factor;
2239 td->ext->size[2] = td->ext->isize[2] * (fsize[2]) * td->factor;
2243 constraintSizeLim(t, td);
2246 /* For individual element center, Editmode need to use iloc */
2247 if (t->flag & T_POINTS)
2248 VecSubf(vec, td->iloc, center);
2250 VecSubf(vec, td->center, center);
2252 Mat3MulVecfl(tmat, vec);
2254 VecAddf(vec, vec, center);
2255 if (t->flag & T_POINTS)
2256 VecSubf(vec, vec, td->iloc);
2258 VecSubf(vec, vec, td->center);
2260 VecMulf(vec, td->factor);
2262 if (t->flag & (T_OBJECT|T_POSE)) {
2263 Mat3MulVecfl(td->smtx, vec);
2266 protectedTransBits(td->protectflag, vec);
2269 TransDataIpokey *tdi= td->tdi;
2270 add_tdi_poin(tdi->locx, tdi->oldloc, vec[0]);
2271 add_tdi_poin(tdi->locy, tdi->oldloc+1, vec[1]);
2272 add_tdi_poin(tdi->locz, tdi->oldloc+2, vec[2]);
2274 else VecAddf(td->loc, td->iloc, vec);
2276 constraintTransLim(t, td);
2279 int Resize(TransInfo *t, short mval[2])
2282 float size[3], mat[3][3];
2287 /* for manipulator, center handle, the scaling can't be done relative to center */
2288 if( (t->flag & T_USES_MANIPULATOR) && t->con.mode==0)
2290 ratio = 1.0f - ((t->imval[0] - mval[0]) + (t->imval[1] - mval[1]))/100.0f;
2294 ratio = t->values[0];
2297 size[0] = size[1] = size[2] = ratio;
2301 if (hasNumInput(&t->num)) {
2302 applyNumInput(&t->num, size);
2303 constraintNumInput(t, size);
2306 applySnapping(t, size);
2308 if (t->flag & T_AUTOVALUES)
2310 VECCOPY(size, t->auto_values);
2313 VECCOPY(t->values, size);
2315 SizeToMat3(size, mat);
2317 if (t->con.applySize) {
2318 t->con.applySize(t, NULL, mat);
2321 Mat3CpyMat3(t->mat, mat); // used in manipulator
2323 headerResize(t, size, str);
2325 for(i = 0, td=t->data; i < t->total; i++, td++) {
2326 if (td->flag & TD_NOACTION)
2329 if (td->flag & TD_SKIP)
2332 ElementResize(t, td, mat);
2335 /* evil hack - redo resize if cliping needed */
2336 if (t->flag & T_CLIP_UV && clipUVTransform(t, size, 1)) {
2337 SizeToMat3(size, mat);
2339 if (t->con.applySize)
2340 t->con.applySize(t, NULL, mat);
2342 for(i = 0, td=t->data; i < t->total; i++, td++)
2343 ElementResize(t, td, mat);
2348 ED_area_headerprint(t->sa, str);
2350 if(!(t->flag & T_USES_MANIPULATOR)) helpline (t, t->center);
2355 /* ************************** TOSPHERE *************************** */
2357 void initToSphere(TransInfo *t)
2359 TransData *td = t->data;
2362 t->mode = TFM_TOSPHERE;
2363 t->transform = ToSphere;
2365 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_RATIO);
2371 t->snap[2] = t->snap[1] * 0.1f;
2373 t->num.flag |= NUM_NULL_ONE | NUM_NO_NEGATIVE;
2374 t->flag |= T_NO_CONSTRAINT;
2376 // Calculate average radius
2377 for(i = 0 ; i < t->total; i++, td++) {
2378 t->val += VecLenf(t->center, td->iloc);
2381 t->val /= (float)t->total;
2384 int ToSphere(TransInfo *t, short mval[2])
2387 float ratio, radius;
2390 TransData *td = t->data;
2392 ratio = t->values[0];
2394 snapGrid(t, &ratio);
2396 applyNumInput(&t->num, &ratio);
2403 /* header print for NumInput */
2404 if (hasNumInput(&t->num)) {
2407 outputNumInput(&(t->num), c);
2409 sprintf(str, "To Sphere: %s %s", c, t->proptext);
2412 /* default header print */
2413 sprintf(str, "To Sphere: %.4f %s", ratio, t->proptext);
2417 for(i = 0 ; i < t->total; i++, td++) {
2419 if (td->flag & TD_NOACTION)
2422 if (td->flag & TD_SKIP)
2425 VecSubf(vec, td->iloc, t->center);
2427 radius = Normalize(vec);
2429 tratio = ratio * td->factor;
2431 VecMulf(vec, radius * (1.0f - tratio) + t->val * tratio);
2433 VecAddf(td->loc, t->center, vec);
2439 ED_area_headerprint(t->sa, str);
2444 /* ************************** ROTATION *************************** */
2447 void initRotation(TransInfo *t)
2449 t->mode = TFM_ROTATION;
2450 t->transform = Rotation;
2452 initMouseInputMode(t, &t->mouse, INPUT_ANGLE);
2455 /* Scale down and flip input for rotation */
2456 t->ndof.factor[0] = -0.2f;
2461 t->snap[1] = (float)((5.0/180)*M_PI);
2462 t->snap[2] = t->snap[1] * 0.2f;
2464 if (t->flag & T_2D_EDIT)
2465 t->flag |= T_NO_CONSTRAINT;
2468 static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short around) {
2469 float vec[3], totmat[3][3], smat[3][3];
2470 float eul[3], fmat[3][3], quat[4];
2471 float *center = t->center;
2473 /* local constraint shouldn't alter center */
2474 if (around == V3D_LOCAL) {
2475 if (t->flag & (T_OBJECT|T_POSE)) {
2476 center = td->center;
2479 /* !TODO! Make this if not rely on G */
2480 if(around==V3D_LOCAL && (t->scene->selectmode & SCE_SELECT_FACE)) {
2481 center = td->center;
2486 if (t->flag & T_POINTS) {
2487 Mat3MulMat3(totmat, mat, td->mtx);
2488 Mat3MulMat3(smat, td->smtx, totmat);
2490 VecSubf(vec, td->iloc, center);
2491 Mat3MulVecfl(smat, vec);
2493 VecAddf(td->loc, vec, center);
2495 VecSubf(vec,td->loc,td->iloc);
2496 protectedTransBits(td->protectflag, vec);
2497 VecAddf(td->loc, td->iloc, vec);
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
2504 QuatMul(td->ext->quat, quat, td->ext->iquat);
2506 /* is there a reason not to have this here? -jahka */
2507 protectedQuaternionBits(td->protectflag, td->ext->quat, td->ext->iquat);
2514 * This is some VERY ugly special case to deal with pose mode.
2516 * The problem is that mtx and smtx include each bone orientation.
2518 * That is needed to rotate each bone properly, HOWEVER, to calculate
2519 * the translation component, we only need the actual armature object's
2520 * matrix (and inverse). That is not all though. Once the proper translation
2521 * has been computed, it has to be converted back into the bone's space.
2523 else if (t->flag & T_POSE) {
2524 float pmtx[3][3], imtx[3][3];
2526 // Extract and invert armature object matrix
2527 Mat3CpyMat4(pmtx, t->poseobj->obmat);
2528 Mat3Inv(imtx, pmtx);
2530 if ((td->flag & TD_NO_LOC) == 0)
2532 VecSubf(vec, td->center, center);
2534 Mat3MulVecfl(pmtx, vec); // To Global space
2535 Mat3MulVecfl(mat, vec); // Applying rotation
2536 Mat3MulVecfl(imtx, vec); // To Local space
2538 VecAddf(vec, vec, center);
2539 /* vec now is the location where the object has to be */
2541 VecSubf(vec, vec, td->center); // Translation needed from the initial location
2543 Mat3MulVecfl(pmtx, vec); // To Global space
2544 Mat3MulVecfl(td->smtx, vec);// To Pose space
2546 protectedTransBits(td->protectflag, vec);
2548 VecAddf(td->loc, td->iloc, vec);
2550 constraintTransLim(t, td);
2554 if ((t->flag & T_V3D_ALIGN)==0) { // align mode doesn't rotate objects itself
2555 /* euler or quaternion? */
2556 if (td->flag & TD_USEQUAT) {
2557 Mat3MulSerie(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0);
2559 Mat3ToQuat(fmat, quat); // Actual transform
2561 QuatMul(td->ext->quat, quat, td->ext->iquat);
2562 /* this function works on end result */
2563 protectedQuaternionBits(td->protectflag, td->ext->quat, td->ext->iquat);
2568 Mat3MulMat3(totmat, mat, td->mtx);
2569 Mat3MulMat3(smat, td->smtx, totmat);
2571 /* calculate the total rotatation in eulers */
2572 VECCOPY(eul, td->ext->irot);
2573 EulToMat3(eul, eulmat);
2575 /* mat = transform, obmat = bone rotation */
2576 Mat3MulMat3(fmat, smat, eulmat);
2578 Mat3ToCompatibleEul(fmat, eul, td->ext->rot);
2580 /* and apply (to end result only) */
2581 protectedRotateBits(td->protectflag, eul, td->ext->irot);
2582 VECCOPY(td->ext->rot, eul);
2585 constraintRotLim(t, td);
2589 if ((td->flag & TD_NO_LOC) == 0)
2592 VecSubf(vec, td->center, center);
2593 Mat3MulVecfl(mat, vec);
2594 VecAddf(vec, vec, center);
2595 /* vec now is the location where the object has to be */
2596 VecSubf(vec, vec, td->center);
2597 Mat3MulVecfl(td->smtx, vec);
2599 protectedTransBits(td->protectflag, vec);
2602 TransDataIpokey *tdi= td->tdi;
2603 add_tdi_poin(tdi->locx, tdi->oldloc, vec[0]);
2604 add_tdi_poin(tdi->locy, tdi->oldloc+1, vec[1]);
2605 add_tdi_poin(tdi->locz, tdi->oldloc+2, vec[2]);
2607 else VecAddf(td->loc, td->iloc, vec);
2611 constraintTransLim(t, td);
2614 if ((t->flag & T_V3D_ALIGN)==0) { // align mode doesn't rotate objects itself
2615 /* euler or quaternion? */
2616 if (td->flag & TD_USEQUAT) {
2617 Mat3MulSerie(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0);
2618 Mat3ToQuat(fmat, quat); // Actual transform
2620 QuatMul(td->ext->quat, quat, td->ext->iquat);
2621 /* this function works on end result */
2622 protectedQuaternionBits(td->protectflag, td->ext->quat, td->ext->iquat);
2627 /* are there ipo keys? */
2629 TransDataIpokey *tdi= td->tdi;
2630 float current_rot[3];
2633 /* current IPO value for compatible euler */
2634 current_rot[0] = (tdi->rotx) ? tdi->rotx[0] : 0.0f;
2635 current_rot[1] = (tdi->roty) ? tdi->roty[0] : 0.0f;
2636 current_rot[2] = (tdi->rotz) ? tdi->rotz[0] : 0.0f;
2637 VecMulf(current_rot, (float)(M_PI_2 / 9.0));
2639 /* calculate the total rotatation in eulers */
2640 VecAddf(eul, td->ext->irot, td->ext->drot);
2641 EulToMat3(eul, obmat);
2642 /* mat = transform, obmat = object rotation */
2643 Mat3MulMat3(fmat, mat, obmat);
2645 Mat3ToCompatibleEul(fmat, eul, current_rot);
2647 /* correct back for delta rot */
2648 if(tdi->flag & TOB_IPODROT) {
2649 VecSubf(rot, eul, td->ext->irot);
2652 VecSubf(rot, eul, td->ext->drot);
2655 VecMulf(rot, (float)(9.0/M_PI_2));
2656 VecSubf(rot, rot, tdi->oldrot);
2658 protectedRotateBits(td->protectflag, rot, tdi->oldrot);
2660 add_tdi_poin(tdi->rotx, tdi->oldrot, rot[0]);
2661 add_tdi_poin(tdi->roty, tdi->oldrot+1, rot[1]);
2662 add_tdi_poin(tdi->rotz, tdi->oldrot+2, rot[2]);
2665 Mat3MulMat3(totmat, mat, td->mtx);
2666 Mat3MulMat3(smat, td->smtx, totmat);
2668 /* calculate the total rotatation in eulers */
2669 VecAddf(eul, td->ext->irot, td->ext->drot); /* we have to correct for delta rot */
2670 EulToMat3(eul, obmat);
2671 /* mat = transform, obmat = object rotation */
2672 Mat3MulMat3(fmat, smat, obmat);
2674 Mat3ToCompatibleEul(fmat, eul, td->ext->rot);
2676 /* correct back for delta rot */
2677 VecSubf(eul, eul, td->ext->drot);
2680 protectedRotateBits(td->protectflag, eul, td->ext->irot);
2681 VECCOPY(td->ext->rot, eul);
2685 constraintRotLim(t, td);
2690 static void applyRotation(TransInfo *t, float angle, float axis[3])
2692 TransData *td = t->data;
2696 VecRotToMat3(axis, angle, mat);
2698 for(i = 0 ; i < t->total; i++, td++) {
2700 if (td->flag & TD_NOACTION)
2703 if (td->flag & TD_SKIP)
2706 if (t->con.applyRot) {
2707 t->con.applyRot(t, td, axis, NULL);
2708 VecRotToMat3(axis, angle * td->factor, mat);
2710 else if (t->flag & T_PROP_EDIT) {
2711 VecRotToMat3(axis, angle * td->factor, mat);
2714 ElementRotation(t, td, mat, t->around);
2718 int Rotation(TransInfo *t, short mval[2])
2727 VECCOPY(axis, t->viewinv[2]);
2728 VecMulf(axis, -1.0f);
2731 final = t->values[0];
2733 applyNDofInput(&t->ndof, &final);
2735 snapGrid(t, &final);
2737 if (t->con.applyRot) {
2738 t->con.applyRot(t, NULL, axis, &final);
2741 applySnapping(t, &final);
2743 if (hasNumInput(&t->num)) {
2746 applyNumInput(&t->num, &final);
2748 outputNumInput(&(t->num), c);
2750 sprintf(str, "Rot: %s %s %s", &c[0], t->con.text, t->proptext);
2752 /* Clamp between -180 and 180 */
2753 while (final >= 180.0)
2756 while (final <= -180.0)
2759 final *= (float)(M_PI / 180.0);
2762 sprintf(str, "Rot: %.2f%s %s", 180.0*final/M_PI, t->con.text, t->proptext);
2765 VecRotToMat3(axis, final, mat);
2768 // t->values[0] = final; // used in manipulator
2769 // Mat3CpyMat3(t->mat, mat); // used in manipulator
2771 applyRotation(t, final, axis);
2775 ED_area_headerprint(t->sa, str);
2777 if(!(t->flag & T_USES_MANIPULATOR)) helpline (t, t->center);
2783 /* ************************** TRACKBALL *************************** */
2785 void initTrackball(TransInfo *t)
2787 t->mode = TFM_TRACKBALL;
2788 t->transform = Trackball;
2790 initMouseInputMode(t, &t->mouse, INPUT_TRACKBALL);
2793 /* Scale down input for rotation */
2794 t->ndof.factor[0] = 0.2f;
2795 t->ndof.factor[1] = 0.2f;
2800 t->snap[1] = (float)((5.0/180)*M_PI);
2801 t->snap[2] = t->snap[1] * 0.2f;
2803 t->flag |= T_NO_CONSTRAINT;
2806 static void applyTrackball(TransInfo *t, float axis1[3], float axis2[3], float angles[2])
2808 TransData *td = t->data;
2809 float mat[3][3], smat[3][3], totmat[3][3];
2812 VecRotToMat3(axis1, angles[0], smat);
2813 VecRotToMat3(axis2, angles[1], totmat);
2815 Mat3MulMat3(mat, smat, totmat);
2817 for(i = 0 ; i < t->total; i++, td++) {
2818 if (td->flag & TD_NOACTION)
2821 if (td->flag & TD_SKIP)
2824 if (t->flag & T_PROP_EDIT) {
2825 VecRotToMat3(axis1, td->factor * angles[0], smat);
2826 VecRotToMat3(axis2, td->factor * angles[1], totmat);
2828 Mat3MulMat3(mat, smat, totmat);
2831 ElementRotation(t, td, mat, t->around);
2835 int Trackball(TransInfo *t, short mval[2])
2838 float axis1[3], axis2[3];
2839 float mat[3][3], totmat[3][3], smat[3][3];
2842 VECCOPY(axis1, t->persinv[0]);
2843 VECCOPY(axis2, t->persinv[1]);
2847 phi[0] = t->values[0];
2848 phi[1] = t->values[1];
2850 applyNDofInput(&t->ndof, phi);
2854 if (hasNumInput(&t->num)) {
2857 applyNumInput(&t->num, phi);
2859 outputNumInput(&(t->num), c);
2861 sprintf(str, "Trackball: %s %s %s", &c[0], &c[20], t->proptext);
2863 phi[0] *= (float)(M_PI / 180.0);
2864 phi[1] *= (float)(M_PI / 180.0);
2867 sprintf(str, "Trackball: %.2f %.2f %s", 180.0*phi[0]/M_PI, 180.0*phi[1]/M_PI, t->proptext);
2870 VecRotToMat3(axis1, phi[0], smat);
2871 VecRotToMat3(axis2, phi[1], totmat);
2873 Mat3MulMat3(mat, smat, totmat);
2876 //Mat3CpyMat3(t->mat, mat); // used in manipulator
2878 applyTrackball(t, axis1, axis2, phi);
2882 ED_area_headerprint(t->sa, str);
2884 if(!(t->flag & T_USES_MANIPULATOR)) helpline (t, t->center);
2889 /* ************************** TRANSLATION *************************** */
2891 void initTranslation(TransInfo *t)
2893 t->mode = TFM_TRANSLATION;
2894 t->transform = Translation;
2896 initMouseInputMode(t, &t->mouse, INPUT_VECTOR);
2898 t->idx_max = (t->flag & T_2D_EDIT)? 1: 2;
2900 t->num.idx_max = t->idx_max;
2902 t->ndof.axis = (t->flag & T_2D_EDIT)? 1|2: 1|2|4;
2904 if(t->spacetype == SPACE_VIEW3D) {
2905 View3D *v3d = t->view;
2908 t->snap[1] = v3d->gridview * 1.0f;
2909 t->snap[2] = t->snap[1] * 0.1f;
2911 else if(t->spacetype == SPACE_IMAGE) {
2913 t->snap[1] = 0.125f;
2914 t->snap[2] = 0.0625f;
2918 t->snap[1] = t->snap[2] = 1.0f;
2922 static void headerTranslation(TransInfo *t, float vec[3], char *str) {
2928 if (hasNumInput(&t->num)) {
2929 outputNumInput(&(t->num), tvec);
2930 dist = VecLength(t->num.val);
2936 applyAspectRatio(t, dvec);
2938 dist = VecLength(vec);
2939 sprintf(&tvec[0], "%.4f", dvec[0]);
2940 sprintf(&tvec[20], "%.4f", dvec[1]);
2941 sprintf(&tvec[40], "%.4f", dvec[2]);
2944 if( dist > 1e10 || dist < -1e10 ) /* prevent string buffer overflow */