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_anim_types.h"
49 #include "DNA_armature_types.h"
50 #include "DNA_action_types.h" /* for some special action-editor settings */
51 #include "DNA_constraint_types.h"
52 #include "DNA_ipo_types.h" /* some silly ipo flag */
53 #include "DNA_listBase.h"
54 #include "DNA_meshdata_types.h"
55 #include "DNA_mesh_types.h"
56 #include "DNA_object_types.h"
57 #include "DNA_scene_types.h" /* PET modes */
58 #include "DNA_screen_types.h" /* area dimensions */
59 #include "DNA_texture_types.h"
60 #include "DNA_userdef_types.h"
61 #include "DNA_view3d_types.h"
62 #include "DNA_space_types.h"
63 #include "DNA_windowmanager_types.h"
65 #include "RNA_access.h"
67 //#include "BIF_editview.h" /* arrows_move_cursor */
69 #include "BIF_glutil.h"
70 //#include "BIF_mywindow.h"
71 //#include "BIF_resources.h"
72 //#include "BIF_screen.h"
73 //#include "BIF_space.h" /* undo */
74 //#include "BIF_toets.h" /* persptoetsen */
75 //#include "BIF_mywindow.h" /* warp_pointer */
76 //#include "BIF_toolbox.h" /* notice */
77 //#include "BIF_editmesh.h"
78 //#include "BIF_editsima.h"
79 //#include "BIF_editparticle.h"
81 #include "BKE_action.h"
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"
94 //#include "BSE_view.h"
97 #include "ED_keyframing.h"
98 #include "ED_screen.h"
99 #include "ED_space_api.h"
100 #include "ED_markers.h"
102 #include "ED_view3d.h"
105 #include "UI_view2d.h"
106 #include "WM_types.h"
109 #include "BLI_math.h"
110 #include "BLI_blenlib.h"
111 #include "BLI_editVert.h"
112 #include "BLI_ghash.h"
113 #include "BLI_linklist.h"
115 #include "PIL_time.h" /* sleep */
117 #include "UI_resources.h"
119 //#include "blendef.h"
121 //#include "mydevice.h"
123 #include "transform.h"
125 /* ************************** SPACE DEPENDANT CODE **************************** */
127 void setTransformViewMatrices(TransInfo *t)
129 if(t->spacetype==SPACE_VIEW3D && t->ar->regiontype == RGN_TYPE_WINDOW) {
130 RegionView3D *rv3d = t->ar->regiondata;
132 copy_m4_m4(t->viewmat, rv3d->viewmat);
133 copy_m4_m4(t->viewinv, rv3d->viewinv);
134 copy_m4_m4(t->persmat, rv3d->persmat);
135 copy_m4_m4(t->persinv, rv3d->persinv);
136 t->persp = rv3d->persp;
143 t->persp = RV3D_ORTHO;
146 calculateCenter2D(t);
149 void convertViewVec(TransInfo *t, float *vec, short dx, short dy)
151 if (t->spacetype==SPACE_VIEW3D) {
152 if (t->ar->regiontype == RGN_TYPE_WINDOW)
154 window_to_3d_delta(t->ar, vec, dx, dy);
157 else if(t->spacetype==SPACE_IMAGE) {
158 View2D *v2d = t->view;
159 float divx, divy, aspx, aspy;
161 ED_space_image_uv_aspect(t->sa->spacedata.first, &aspx, &aspy);
163 divx= v2d->mask.xmax-v2d->mask.xmin;
164 divy= v2d->mask.ymax-v2d->mask.ymin;
166 vec[0]= aspx*(v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx;
167 vec[1]= aspy*(v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy;
170 else if(ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)) {
171 View2D *v2d = t->view;
174 divx= v2d->mask.xmax-v2d->mask.xmin;
175 divy= v2d->mask.ymax-v2d->mask.ymin;
177 vec[0]= (v2d->cur.xmax-v2d->cur.xmin)*(dx) / (divx);
178 vec[1]= (v2d->cur.ymax-v2d->cur.ymin)*(dy) / (divy);
181 else if(t->spacetype==SPACE_NODE) {
182 View2D *v2d = &t->ar->v2d;
185 divx= v2d->mask.xmax-v2d->mask.xmin;
186 divy= v2d->mask.ymax-v2d->mask.ymin;
188 vec[0]= (v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx;
189 vec[1]= (v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy;
192 else if(t->spacetype==SPACE_SEQ) {
193 View2D *v2d = &t->ar->v2d;
196 divx= v2d->mask.xmax-v2d->mask.xmin;
197 divy= v2d->mask.ymax-v2d->mask.ymin;
199 vec[0]= (v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx;
200 vec[1]= (v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy;
205 void projectIntView(TransInfo *t, float *vec, int *adr)
207 if (t->spacetype==SPACE_VIEW3D) {
208 if(t->ar->regiontype == RGN_TYPE_WINDOW)
209 project_int_noclip(t->ar, vec, adr);
211 else if(t->spacetype==SPACE_IMAGE) {
212 float aspx, aspy, v[2];
214 ED_space_image_uv_aspect(t->sa->spacedata.first, &aspx, &aspy);
218 UI_view2d_to_region_no_clip(t->view, v[0], v[1], adr, adr+1);
220 else if(ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)) {
223 UI_view2d_view_to_region((View2D *)t->view, vec[0], vec[1], out, out+1);
227 else if(t->spacetype==SPACE_SEQ) { /* XXX not tested yet, but should work */
230 UI_view2d_view_to_region((View2D *)t->view, vec[0], vec[1], out, out+1);
236 void projectFloatView(TransInfo *t, float *vec, float *adr)
238 if (t->spacetype==SPACE_VIEW3D) {
239 if(t->ar->regiontype == RGN_TYPE_WINDOW)
240 project_float_noclip(t->ar, vec, adr);
242 else if(t->spacetype==SPACE_IMAGE) {
245 projectIntView(t, vec, a);
249 else if(ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)) {
252 projectIntView(t, vec, a);
258 void applyAspectRatio(TransInfo *t, float *vec)
260 SpaceImage *sima= t->sa->spacedata.first;
262 if ((t->spacetype==SPACE_IMAGE) && (t->mode==TFM_TRANSLATION)) {
265 if((sima->flag & SI_COORDFLOATS)==0) {
267 ED_space_image_size(sima, &width, &height);
273 ED_space_image_uv_aspect(sima, &aspx, &aspy);
279 void removeAspectRatio(TransInfo *t, float *vec)
281 SpaceImage *sima= t->sa->spacedata.first;
283 if ((t->spacetype==SPACE_IMAGE) && (t->mode==TFM_TRANSLATION)) {
286 if((sima->flag & SI_COORDFLOATS)==0) {
288 ED_space_image_size(sima, &width, &height);
294 ED_space_image_uv_aspect(sima, &aspx, &aspy);
300 static void viewRedrawForce(bContext *C, TransInfo *t)
302 if (t->spacetype == SPACE_VIEW3D)
304 /* Do we need more refined tags? */
305 WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
307 /* for realtime animation record - send notifiers recognised by animation editors */
308 if ((t->animtimer) && IS_AUTOKEY_ON(t->scene))
309 WM_event_add_notifier(C, NC_OBJECT|ND_KEYS, NULL);
311 else if (t->spacetype == SPACE_ACTION) {
312 //SpaceAction *saction= (SpaceAction *)t->sa->spacedata.first;
313 WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME_EDIT, NULL);
315 else if (t->spacetype == SPACE_IPO) {
316 //SpaceIpo *sipo= (SpaceIpo *)t->sa->spacedata.first;
317 WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME_EDIT, NULL);
319 else if (t->spacetype == SPACE_NLA) {
320 WM_event_add_notifier(C, NC_ANIMATION|ND_NLA_EDIT, NULL);
322 else if(t->spacetype == SPACE_NODE)
324 //ED_area_tag_redraw(t->sa);
325 WM_event_add_notifier(C, NC_SPACE|ND_SPACE_NODE_VIEW, NULL);
327 else if(t->spacetype == SPACE_SEQ)
329 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, NULL);
331 else if (t->spacetype==SPACE_IMAGE) {
332 // XXX how to deal with lock?
333 SpaceImage *sima= (SpaceImage*)t->sa->spacedata.first;
334 if(sima->lock) WM_event_add_notifier(C, NC_GEOM|ND_DATA, t->obedit->data);
335 else ED_area_tag_redraw(t->sa);
339 static void viewRedrawPost(TransInfo *t)
341 ED_area_headerprint(t->sa, NULL);
343 #if 0 // TRANSFORM_FIX_ME
344 if(t->spacetype==SPACE_VIEW3D) {
345 allqueue(REDRAWBUTSOBJECT, 0);
346 allqueue(REDRAWVIEW3D, 0);
348 else if(t->spacetype==SPACE_IMAGE) {
349 allqueue(REDRAWIMAGE, 0);
350 allqueue(REDRAWVIEW3D, 0);
352 else if(ELEM3(t->spacetype, SPACE_ACTION, SPACE_NLA, SPACE_IPO)) {
353 allqueue(REDRAWVIEW3D, 0);
354 allqueue(REDRAWACTION, 0);
355 allqueue(REDRAWNLA, 0);
356 allqueue(REDRAWIPO, 0);
357 allqueue(REDRAWTIME, 0);
358 allqueue(REDRAWBUTSOBJECT, 0);
361 scrarea_queue_headredraw(curarea);
365 /* ************************** TRANSFORMATIONS **************************** */
367 void BIF_selectOrientation() {
368 #if 0 // TRANSFORM_FIX_ME
370 char *str_menu = BIF_menustringTransformOrientation("Orientation");
371 val= pupmenu(str_menu);
380 static void view_editmove(unsigned short event)
382 #if 0 // TRANSFORM_FIX_ME
384 /* Regular: Zoom in */
385 /* Shift: Scroll up */
386 /* Ctrl: Scroll right */
387 /* Alt-Shift: Rotate up */
388 /* Alt-Ctrl: Rotate right */
390 /* only work in 3D window for now
391 * In the end, will have to send to event to a 2D window handler instead
393 if (Trans.flag & T_2D_EDIT)
399 if( G.qual & LR_SHIFTKEY ) {
400 if( G.qual & LR_ALTKEY ) {
401 G.qual &= ~LR_SHIFTKEY;
403 G.qual |= LR_SHIFTKEY;
407 } else if( G.qual & LR_CTRLKEY ) {
408 if( G.qual & LR_ALTKEY ) {
409 G.qual &= ~LR_CTRLKEY;
411 G.qual |= LR_CTRLKEY;
415 } else if(U.uiflag & USER_WHEELZOOMDIR)
416 persptoetsen(PADMINUS);
418 persptoetsen(PADPLUSKEY);
423 if( G.qual & LR_SHIFTKEY ) {
424 if( G.qual & LR_ALTKEY ) {
425 G.qual &= ~LR_SHIFTKEY;
427 G.qual |= LR_SHIFTKEY;
431 } else if( G.qual & LR_CTRLKEY ) {
432 if( G.qual & LR_ALTKEY ) {
433 G.qual &= ~LR_CTRLKEY;
435 G.qual |= LR_CTRLKEY;
439 } else if(U.uiflag & USER_WHEELZOOMDIR)
440 persptoetsen(PADPLUSKEY);
442 persptoetsen(PADMINUS);
449 setTransformViewMatrices(&Trans);
454 static char *transform_to_undostr(TransInfo *t)
457 case TFM_TRANSLATION:
469 case TFM_SHRINKFATTEN:
470 return "Shrink/Fatten";
480 return "Bevel Weight";
485 case TFM_BONE_ENVELOPE:
486 return "Bone Envelope";
487 case TFM_TIME_TRANSLATE:
488 return "Translate Anim. Data";
490 return "Scale Anim. Data";
502 /* ************************************************* */
504 /* NOTE: these defines are saved in keymap files, do not change values but just add new ones */
505 #define TFM_MODAL_CANCEL 1
506 #define TFM_MODAL_CONFIRM 2
507 #define TFM_MODAL_TRANSLATE 3
508 #define TFM_MODAL_ROTATE 4
509 #define TFM_MODAL_RESIZE 5
510 #define TFM_MODAL_SNAP_GEARS 6
511 #define TFM_MODAL_SNAP_GEARS_OFF 7
512 #define TFM_MODAL_SNAP_GEARS_TOGGLE 8
514 /* called in transform_ops.c, on each regeneration of keymaps */
515 void transform_modal_keymap(wmKeyConfig *keyconf)
517 static EnumPropertyItem modal_items[] = {
518 {TFM_MODAL_CANCEL, "CANCEL", 0, "Cancel", ""},
519 {TFM_MODAL_CONFIRM, "CONFIRM", 0, "Confirm", ""},
520 {TFM_MODAL_TRANSLATE, "TRANSLATE", 0, "Translate", ""},
521 {TFM_MODAL_ROTATE, "ROTATE", 0, "Rotate", ""},
522 {TFM_MODAL_RESIZE, "RESIZE", 0, "Resize", ""},
523 {TFM_MODAL_SNAP_GEARS, "SNAP_GEARS", 0, "Snap On", ""},
524 {TFM_MODAL_SNAP_GEARS_OFF, "SNAP_GEARS_OFF", 0, "Snap Off", ""},
525 {TFM_MODAL_SNAP_GEARS_TOGGLE, "SNAP_GEARS_TOGGLE", 0, "Snap Toggle", ""},
526 {0, NULL, 0, NULL, NULL}};
528 wmKeyMap *keymap= WM_modalkeymap_get(keyconf, "Transform Modal Map");
530 /* this function is called for each spacetype, only needs to add map once */
533 keymap= WM_modalkeymap_add(keyconf, "Transform Modal Map", modal_items);
535 /* items for modal map */
536 WM_modalkeymap_add_item(keymap, ESCKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_CANCEL);
537 WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_PRESS, KM_ANY, 0, TFM_MODAL_CONFIRM);
538 WM_modalkeymap_add_item(keymap, RETKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_CONFIRM);
539 WM_modalkeymap_add_item(keymap, PADENTER, KM_PRESS, KM_ANY, 0, TFM_MODAL_CONFIRM);
541 WM_modalkeymap_add_item(keymap, GKEY, KM_PRESS, 0, 0, TFM_MODAL_TRANSLATE);
542 WM_modalkeymap_add_item(keymap, RKEY, KM_PRESS, 0, 0, TFM_MODAL_ROTATE);
543 WM_modalkeymap_add_item(keymap, SKEY, KM_PRESS, 0, 0, TFM_MODAL_RESIZE);
545 WM_modalkeymap_add_item(keymap, LEFTCTRLKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_SNAP_GEARS_TOGGLE);
547 /* assign map to operators */
548 WM_modalkeymap_assign(keymap, "TFM_OT_transform");
549 WM_modalkeymap_assign(keymap, "TFM_OT_translate");
550 WM_modalkeymap_assign(keymap, "TFM_OT_rotate");
551 WM_modalkeymap_assign(keymap, "TFM_OT_tosphere");
552 WM_modalkeymap_assign(keymap, "TFM_OT_resize");
553 WM_modalkeymap_assign(keymap, "TFM_OT_shear");
554 WM_modalkeymap_assign(keymap, "TFM_OT_warp");
555 WM_modalkeymap_assign(keymap, "TFM_OT_shrink_fatten");
556 WM_modalkeymap_assign(keymap, "TFM_OT_tilt");
557 WM_modalkeymap_assign(keymap, "TFM_OT_trackball");
562 void transformEvent(TransInfo *t, wmEvent *event)
564 float mati[3][3] = {{1.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 1.0f}};
565 char cmode = constraintModeToChar(t);
567 t->redraw |= handleMouseInput(t, &t->mouse, event);
569 if (event->type == MOUSEMOVE)
571 t->mval[0] = event->x - t->ar->winrct.xmin;
572 t->mval[1] = event->y - t->ar->winrct.ymin;
576 if (t->state == TRANS_STARTING) {
577 t->state = TRANS_RUNNING;
580 applyMouseInput(t, &t->mouse, t->mval, t->values);
583 /* handle modal keymap first */
584 if (event->type == EVT_MODAL_MAP) {
585 switch (event->val) {
586 case TFM_MODAL_CANCEL:
587 t->state = TRANS_CANCEL;
589 case TFM_MODAL_CONFIRM:
590 t->state = TRANS_CONFIRM;
592 case TFM_MODAL_TRANSLATE:
593 /* only switch when... */
594 if( ELEM3(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL) ) {
595 resetTransRestrictions(t);
596 restoreTransObjects(t);
598 initSnapping(t, NULL); // need to reinit after mode change
602 case TFM_MODAL_ROTATE:
603 /* only switch when... */
604 if( ELEM4(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL, TFM_TRANSLATION) ) {
606 resetTransRestrictions(t);
608 if (t->mode == TFM_ROTATION) {
609 restoreTransObjects(t);
613 restoreTransObjects(t);
616 initSnapping(t, NULL); // need to reinit after mode change
620 case TFM_MODAL_RESIZE:
621 /* only switch when... */
622 if( ELEM3(t->mode, TFM_ROTATION, TFM_TRANSLATION, TFM_TRACKBALL) ) {
623 resetTransRestrictions(t);
624 restoreTransObjects(t);
626 initSnapping(t, NULL); // need to reinit after mode change
631 case TFM_MODAL_SNAP_GEARS:
632 t->modifiers |= MOD_SNAP_GEARS;
635 case TFM_MODAL_SNAP_GEARS_OFF:
636 t->modifiers &= ~MOD_SNAP_GEARS;
639 case TFM_MODAL_SNAP_GEARS_TOGGLE:
640 t->modifiers ^= MOD_SNAP_GEARS;
645 /* else do non-mapped events */
646 else if (event->val==KM_PRESS) {
647 switch (event->type){
649 t->state = TRANS_CANCEL;
651 /* enforce redraw of transform when modifiers are used */
654 t->modifiers |= MOD_CONSTRAINT_PLANE;
659 if ((t->spacetype==SPACE_VIEW3D) && event->alt) {
660 #if 0 // TRANSFORM_FIX_ME
664 BIF_selectOrientation();
665 calc_manipulator_stats(curarea);
666 copy_m3_m4(t->spacemtx, G.vd->twmat);
667 warp_pointer(mval[0], mval[1]);
671 t->state = TRANS_CONFIRM;
676 if ((t->flag & T_NO_CONSTRAINT)==0) {
677 /* exception for switching to dolly, or trackball, in camera view */
678 if (t->flag & T_CAMERA) {
679 if (t->mode==TFM_TRANSLATION)
680 setLocalConstraint(t, (CON_AXIS2), "along local Z");
681 else if (t->mode==TFM_ROTATION) {
682 restoreTransObjects(t);
687 t->modifiers |= MOD_CONSTRAINT_SELECT;
688 if (t->con.mode & CON_APPLY) {
693 initSelectConstraint(t, t->spacemtx);
696 /* bit hackish... but it prevents mmb select to print the orientation from menu */
697 strcpy(t->spacename, "global");
698 initSelectConstraint(t, mati);
700 postSelectConstraint(t);
707 t->state = TRANS_CANCEL;
711 t->state = TRANS_CONFIRM;
714 /* only switch when... */
715 if( ELEM3(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL) ) {
716 resetTransRestrictions(t);
717 restoreTransObjects(t);
719 initSnapping(t, NULL); // need to reinit after mode change
724 /* only switch when... */
725 if( ELEM3(t->mode, TFM_ROTATION, TFM_TRANSLATION, TFM_TRACKBALL) ) {
726 resetTransRestrictions(t);
727 restoreTransObjects(t);
729 initSnapping(t, NULL); // need to reinit after mode change
734 /* only switch when... */
735 if( ELEM4(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL, TFM_TRANSLATION) ) {
737 resetTransRestrictions(t);
739 if (t->mode == TFM_ROTATION) {
740 restoreTransObjects(t);
744 restoreTransObjects(t);
747 initSnapping(t, NULL); // need to reinit after mode change
753 t->flag ^= T_PROP_CONNECTED;
754 sort_trans_data_dist(t);
755 calculatePropRatio(t);
764 if ((t->flag & T_NO_CONSTRAINT)==0) {
766 if (t->flag & T_2D_EDIT) {
770 if (t->con.mode & CON_USER) {
774 short orientation = t->current_orientation != V3D_MANIP_GLOBAL ? t->current_orientation : V3D_MANIP_LOCAL;
775 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
776 setUserConstraint(t, orientation, (CON_AXIS0), "along %s X");
777 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
778 setUserConstraint(t, orientation, (CON_AXIS1|CON_AXIS2), "locking %s X");
783 if (t->flag & T_2D_EDIT) {
784 setConstraint(t, mati, (CON_AXIS0), "along X axis");
787 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
788 setConstraint(t, mati, (CON_AXIS0), "along global X");
789 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
790 setConstraint(t, mati, (CON_AXIS1|CON_AXIS2), "locking global X");
797 if ((t->flag & T_NO_CONSTRAINT)==0) {
799 if (t->flag & T_2D_EDIT) {
803 if (t->con.mode & CON_USER) {
807 short orientation = t->current_orientation != V3D_MANIP_GLOBAL ? t->current_orientation : V3D_MANIP_LOCAL;
808 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
809 setUserConstraint(t, orientation, (CON_AXIS1), "along %s Y");
810 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
811 setUserConstraint(t, orientation, (CON_AXIS0|CON_AXIS2), "locking %s Y");
816 if (t->flag & T_2D_EDIT) {
817 setConstraint(t, mati, (CON_AXIS1), "along Y axis");
820 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
821 setConstraint(t, mati, (CON_AXIS1), "along global Y");
822 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
823 setConstraint(t, mati, (CON_AXIS0|CON_AXIS2), "locking global Y");
830 if ((t->flag & T_NO_CONSTRAINT)==0) {
832 if (t->con.mode & CON_USER) {
836 short orientation = t->current_orientation != V3D_MANIP_GLOBAL ? t->current_orientation : V3D_MANIP_LOCAL;
837 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
838 setUserConstraint(t, orientation, (CON_AXIS2), "along %s Z");
839 else if ((t->modifiers & MOD_CONSTRAINT_PLANE) && ((t->flag & T_2D_EDIT)==0))
840 setUserConstraint(t, orientation, (CON_AXIS0|CON_AXIS1), "locking %s Z");
843 else if ((t->flag & T_2D_EDIT)==0) {
844 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
845 setConstraint(t, mati, (CON_AXIS2), "along global Z");
846 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
847 setConstraint(t, mati, (CON_AXIS0|CON_AXIS1), "locking global Z");
853 if (t->flag & T_PROP_EDIT && event->shift) {
854 t->prop_mode = (t->prop_mode + 1) % 6;
855 calculatePropRatio(t);
860 if(event->alt && t->flag & T_PROP_EDIT) {
861 t->prop_size *= 1.1f;
862 calculatePropRatio(t);
868 if (t->flag & T_AUTOIK) {
869 transform_autoik_update(t, 1);
871 else if(t->flag & T_PROP_EDIT) {
873 calculatePropRatio(t);
875 else view_editmove(event->type);
879 if(event->alt && t->flag & T_PROP_EDIT) {
880 t->prop_size*= 0.90909090f;
881 calculatePropRatio(t);
887 if (t->flag & T_AUTOIK) {
888 transform_autoik_update(t, -1);
890 else if (t->flag & T_PROP_EDIT) {
891 t->prop_size*= 0.90909090f;
892 calculatePropRatio(t);
894 else view_editmove(event->type);
902 // Numerical input events
903 t->redraw |= handleNumInput(&(t->num), event);
906 switch(handleNDofInput(&(t->ndof), event))
909 if ((t->options & CTX_NDOF) == 0)
911 /* Confirm on normal transform only */
912 t->state = TRANS_CONFIRM;
916 if (t->options & CTX_NDOF)
918 /* Cancel on pure NDOF transform */
919 t->state = TRANS_CANCEL;
923 /* Otherwise, just redraw, NDof input was cancelled */
928 if (t->options & CTX_NDOF)
930 /* Confirm on pure NDOF transform */
931 t->state = TRANS_CONFIRM;
941 t->redraw |= handleSnapping(t, event);
943 //arrows_move_cursor(event->type);
945 else if (event->val==KM_RELEASE) {
946 switch (event->type){
949 t->modifiers &= ~MOD_CONSTRAINT_PLANE;
954 if ((t->flag & T_NO_CONSTRAINT)==0) {
955 t->modifiers &= ~MOD_CONSTRAINT_SELECT;
956 postSelectConstraint(t);
962 // if(WM_modal_tweak_exit(event, t->event_type))
963 //// if (t->options & CTX_TWEAK)
964 // t->state = TRANS_CONFIRM;
968 /* confirm transform if launch key is released after mouse move */
969 /* XXX Keyrepeat bug in Xorg fucks this up, will test when fixed */
970 if (event->type == LEFTMOUSE /*t->launch_event*/ && t->state != TRANS_STARTING)
972 t->state = TRANS_CONFIRM;
976 // Per transform event, if present
978 t->redraw |= t->handleEvent(t, event);
981 int calculateTransformCenter(bContext *C, wmEvent *event, int centerMode, float *vec)
983 TransInfo *t = MEM_callocN(sizeof(TransInfo), "TransInfo data");
986 t->state = TRANS_RUNNING;
988 t->options = CTX_NONE;
992 initTransInfo(C, t, NULL, event); // internal data, mouse, vectors
994 createTransData(C, t); // make TransData structs from selection
996 t->around = centerMode; // override userdefined mode
1006 // Copy center from constraint center. Transform center can be local
1007 VECCOPY(vec, t->con.center);
1011 /* aftertrans does insert ipos and action channels, and clears base flags, doesnt read transdata */
1012 special_aftertrans_update(t);
1027 static void drawArrow(ArrowDirection d, short offset, short length, short size)
1037 glVertex2s( offset, 0);
1038 glVertex2s( offset + length, 0);
1039 glVertex2s( offset + length, 0);
1040 glVertex2s( offset + length - size, -size);
1041 glVertex2s( offset + length, 0);
1042 glVertex2s( offset + length - size, size);
1051 glVertex2s( 0, offset);
1052 glVertex2s( 0, offset + length);
1053 glVertex2s( 0, offset + length);
1054 glVertex2s(-size, offset + length - size);
1055 glVertex2s( 0, offset + length);
1056 glVertex2s( size, offset + length - size);
1062 static void drawArrowHead(ArrowDirection d, short size)
1071 glVertex2s( -size, -size);
1073 glVertex2s( -size, size);
1081 glVertex2s(-size, -size);
1083 glVertex2s( size, -size);
1089 static void drawArc(float size, float angle_start, float angle_end, int segments)
1091 float delta = (angle_end - angle_start) / segments;
1094 glBegin(GL_LINE_STRIP);
1096 for( angle = angle_start; angle < angle_end; angle += delta)
1098 glVertex2f( cosf(angle) * size, sinf(angle) * size);
1100 glVertex2f( cosf(angle_end) * size, sinf(angle_end) * size);
1105 void drawHelpline(const struct bContext *C, TransInfo *t)
1107 if (t->helpline != HLP_NONE && !(t->flag & T_USES_MANIPULATOR))
1109 float vecrot[3], cent[2];
1111 VECCOPY(vecrot, t->center);
1112 if(t->flag & T_EDIT) {
1113 Object *ob= t->obedit;
1114 if(ob) mul_m4_v3(ob->obmat, vecrot);
1116 else if(t->flag & T_POSE) {
1117 Object *ob=t->poseobj;
1118 if(ob) mul_m4_v3(ob->obmat, vecrot);
1121 projectFloatView(t, vecrot, cent); // no overflow in extreme cases
1128 UI_ThemeColor(TH_WIRE);
1131 glBegin(GL_LINE_STRIP);
1132 glVertex2sv(t->mval);
1136 glTranslatef(t->mval[0], t->mval[1], 0);
1137 glRotatef(-180 / M_PI * atan2f(cent[0] - t->mval[0], cent[1] - t->mval[1]), 0, 0, 1);
1141 drawArrow(UP, 5, 10, 5);
1142 drawArrow(DOWN, 5, 10, 5);
1146 UI_ThemeColor(TH_WIRE);
1148 glTranslatef(t->mval[0], t->mval[1], 0);
1151 drawArrow(RIGHT, 5, 10, 5);
1152 drawArrow(LEFT, 5, 10, 5);
1156 UI_ThemeColor(TH_WIRE);
1158 glTranslatef(t->mval[0], t->mval[1], 0);
1162 drawArrow(UP, 5, 10, 5);
1163 drawArrow(DOWN, 5, 10, 5);
1168 float dx = t->mval[0] - cent[0], dy = t->mval[1] - cent[1];
1169 float angle = atan2f(dy, dx);
1170 float dist = sqrtf(dx*dx + dy*dy);
1171 float delta_angle = MIN2(15 / dist, M_PI/4);
1172 float spacing_angle = MIN2(5 / dist, M_PI/12);
1173 UI_ThemeColor(TH_WIRE);
1176 glBegin(GL_LINE_STRIP);
1177 glVertex2sv(t->mval);
1181 glTranslatef(cent[0], cent[1], 0);
1185 drawArc(dist, angle - delta_angle, angle - spacing_angle, 10);
1186 drawArc(dist, angle + spacing_angle, angle + delta_angle, 10);
1190 glTranslatef(cosf(angle - delta_angle) * dist, sinf(angle - delta_angle) * dist, 0);
1191 glRotatef(180 / M_PI * (angle - delta_angle), 0, 0, 1);
1193 drawArrowHead(DOWN, 5);
1197 glTranslatef(cosf(angle + delta_angle) * dist, sinf(angle + delta_angle) * dist, 0);
1198 glRotatef(180 / M_PI * (angle + delta_angle), 0, 0, 1);
1200 drawArrowHead(UP, 5);
1207 char col[3], col2[3];
1208 UI_GetThemeColor3ubv(TH_GRID, col);
1210 glTranslatef(t->mval[0], t->mval[1], 0);
1214 UI_make_axis_color(col, col2, 'x');
1215 glColor3ubv((GLubyte *)col2);
1217 drawArrow(RIGHT, 5, 10, 5);
1218 drawArrow(LEFT, 5, 10, 5);
1220 UI_make_axis_color(col, col2, 'y');
1221 glColor3ubv((GLubyte *)col2);
1223 drawArrow(UP, 5, 10, 5);
1224 drawArrow(DOWN, 5, 10, 5);
1234 void drawTransformView(const struct bContext *C, struct ARegion *ar, void *arg)
1238 drawConstraint(C, t);
1239 drawPropCircle(C, t);
1243 void drawTransformPixel(const struct bContext *C, struct ARegion *ar, void *arg)
1250 void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
1252 ToolSettings *ts = CTX_data_tool_settings(C);
1253 int constraint_axis[3] = {0, 0, 0};
1254 int proportional = 0;
1256 if (RNA_struct_find_property(op->ptr, "value"))
1258 if (t->flag & T_AUTOVALUES)
1260 RNA_float_set_array(op->ptr, "value", t->auto_values);
1264 RNA_float_set_array(op->ptr, "value", t->values);
1268 /* XXX convert stupid flag to enum */
1269 switch(t->flag & (T_PROP_EDIT|T_PROP_CONNECTED))
1271 case (T_PROP_EDIT|T_PROP_CONNECTED):
1281 // If modal, save settings back in scene if not set as operator argument
1282 if (t->flag & T_MODAL)
1284 /* save settings if not set in operator */
1285 if (RNA_struct_find_property(op->ptr, "proportional") && !RNA_property_is_set(op->ptr, "proportional"))
1287 ts->proportional = proportional;
1290 if (RNA_struct_find_property(op->ptr, "proportional_size") && !RNA_property_is_set(op->ptr, "proportional_size"))
1292 ts->proportional_size = t->prop_size;
1295 if (RNA_struct_find_property(op->ptr, "proportional_editing_falloff") && !RNA_property_is_set(op->ptr, "proportional_editing_falloff"))
1297 ts->prop_mode = t->prop_mode;
1300 if(t->spacetype == SPACE_VIEW3D)
1302 if (RNA_struct_find_property(op->ptr, "constraint_orientation") && !RNA_property_is_set(op->ptr, "constraint_orientation"))
1304 View3D *v3d = t->view;
1306 v3d->twmode = t->current_orientation;
1311 if (RNA_struct_find_property(op->ptr, "proportional"))
1313 RNA_enum_set(op->ptr, "proportional", proportional);
1314 RNA_enum_set(op->ptr, "proportional_editing_falloff", t->prop_mode);
1315 RNA_float_set(op->ptr, "proportional_size", t->prop_size);
1318 if (RNA_struct_find_property(op->ptr, "mirror"))
1320 RNA_boolean_set(op->ptr, "mirror", t->flag & T_MIRROR);
1323 if (RNA_struct_find_property(op->ptr, "constraint_axis"))
1325 RNA_enum_set(op->ptr, "constraint_orientation", t->current_orientation);
1327 if (t->con.mode & CON_APPLY)
1329 if (t->con.mode & CON_AXIS0) {
1330 constraint_axis[0] = 1;
1332 if (t->con.mode & CON_AXIS1) {
1333 constraint_axis[1] = 1;
1335 if (t->con.mode & CON_AXIS2) {
1336 constraint_axis[2] = 1;
1340 RNA_boolean_set_array(op->ptr, "constraint_axis", constraint_axis);
1344 int initTransform(bContext *C, TransInfo *t, wmOperator *op, wmEvent *event, int mode)
1348 /* added initialize, for external calls to set stuff in TransInfo, like undo string */
1350 t->state = TRANS_STARTING;
1352 t->options = options;
1356 t->launch_event = event ? event->type : -1;
1358 if (!initTransInfo(C, t, op, event)) // internal data, mouse, vectors
1363 if(t->spacetype == SPACE_VIEW3D)
1365 //calc_manipulator_stats(curarea);
1366 initTransformOrientation(C, t);
1368 t->draw_handle_view = ED_region_draw_cb_activate(t->ar->type, drawTransformView, t, REGION_DRAW_POST_VIEW);
1369 t->draw_handle_pixel = ED_region_draw_cb_activate(t->ar->type, drawTransformPixel, t, REGION_DRAW_POST_PIXEL);
1371 else if(t->spacetype == SPACE_IMAGE) {
1372 unit_m3(t->spacemtx);
1373 t->draw_handle_view = ED_region_draw_cb_activate(t->ar->type, drawTransformView, t, REGION_DRAW_POST_VIEW);
1374 t->draw_handle_pixel = ED_region_draw_cb_activate(t->ar->type, drawTransformPixel, t, REGION_DRAW_POST_PIXEL);
1377 unit_m3(t->spacemtx);
1379 createTransData(C, t); // make TransData structs from selection
1381 if (t->total == 0) {
1386 initSnapping(t, op); // Initialize snapping data AFTER mode flags
1388 /* EVIL! posemode code can switch translation to rotate when 1 bone is selected. will be removed (ton) */
1389 /* EVIL2: we gave as argument also texture space context bit... was cleared */
1390 /* EVIL3: extend mode for animation editors also switches modes... but is best way to avoid duplicate code */
1393 calculatePropRatio(t);
1396 initMouseInput(t, &t->mouse, t->center2d, t->imval);
1399 case TFM_TRANSLATION:
1417 case TFM_SHRINKFATTEN:
1418 initShrinkFatten(t);
1423 case TFM_CURVE_SHRINKFATTEN:
1424 initCurveShrinkFatten(t);
1436 { /* used for both B-Bone width (bonesize) as for deform-dist (envelope) */
1437 bArmature *arm= t->poseobj->data;
1438 if(arm->drawtype==ARM_ENVELOPE)
1439 initBoneEnvelope(t);
1444 case TFM_BONE_ENVELOPE:
1445 initBoneEnvelope(t);
1447 case TFM_EDGE_SLIDE:
1453 case TFM_TIME_TRANSLATE:
1454 initTimeTranslate(t);
1456 case TFM_TIME_SLIDE:
1459 case TFM_TIME_SCALE:
1462 case TFM_TIME_EXTEND:
1463 /* now that transdata has been made, do like for TFM_TIME_TRANSLATE (for most Animation
1464 * Editors because they have only 1D transforms for time values) or TFM_TRANSLATION
1465 * (for Graph/NLA Editors only since they uses 'standard' transforms to get 2D movement)
1466 * depending on which editor this was called from
1468 if ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)
1471 initTimeTranslate(t);
1490 /* overwrite initial values if operator supplied a non-null vector */
1491 if (RNA_property_is_set(op->ptr, "value"))
1494 RNA_float_get_array(op->ptr, "value", values);
1495 QUATCOPY(t->values, values);
1496 QUATCOPY(t->auto_values, values);
1497 t->flag |= T_AUTOVALUES;
1500 /* Constraint init from operator */
1501 if (RNA_struct_find_property(op->ptr, "constraint_axis") && RNA_property_is_set(op->ptr, "constraint_axis"))
1503 int constraint_axis[3];
1505 RNA_boolean_get_array(op->ptr, "constraint_axis", constraint_axis);
1507 if (constraint_axis[0] || constraint_axis[1] || constraint_axis[2])
1509 t->con.mode |= CON_APPLY;
1511 if (constraint_axis[0]) {
1512 t->con.mode |= CON_AXIS0;
1514 if (constraint_axis[1]) {
1515 t->con.mode |= CON_AXIS1;
1517 if (constraint_axis[2]) {
1518 t->con.mode |= CON_AXIS2;
1521 setUserConstraint(t, t->current_orientation, t->con.mode, "%s");
1528 void transformApply(bContext *C, TransInfo *t)
1532 if (t->modifiers & MOD_CONSTRAINT_SELECT)
1533 t->con.mode |= CON_SELECT;
1535 selectConstraint(t);
1537 t->transform(t, t->mval); // calls recalcData()
1538 viewRedrawForce(C, t);
1543 /* If auto confirm is on, break after one pass */
1544 if (t->options & CTX_AUTOCONFIRM)
1546 t->state = TRANS_CONFIRM;
1549 if (BKE_ptcache_get_continue_physics())
1552 //do_screenhandlers(G.curscreen);
1557 int transformEnd(bContext *C, TransInfo *t)
1559 int exit_code = OPERATOR_RUNNING_MODAL;
1561 if (t->state != TRANS_STARTING && t->state != TRANS_RUNNING)
1563 /* handle restoring objects */
1564 if(t->state == TRANS_CANCEL)
1566 exit_code = OPERATOR_CANCELLED;
1567 restoreTransObjects(t); // calls recalcData()
1571 exit_code = OPERATOR_FINISHED;
1574 /* aftertrans does insert keyframes, and clears base flags, doesnt read transdata */
1575 special_aftertrans_update(t);
1580 /* send events out for redraws */
1583 /* Undo as last, certainly after special_trans_update! */
1585 if(t->state == TRANS_CANCEL) {
1586 // if(t->undostr) ED_undo_push(C, t->undostr);
1589 // if(t->undostr) ED_undo_push(C, t->undostr);
1590 // else ED_undo_push(C, transform_to_undostr(t));
1594 viewRedrawForce(C, t);
1600 /* ************************** TRANSFORM LOCKS **************************** */
1602 static void protectedTransBits(short protectflag, float *vec)
1604 if(protectflag & OB_LOCK_LOCX)
1606 if(protectflag & OB_LOCK_LOCY)
1608 if(protectflag & OB_LOCK_LOCZ)
1612 static void protectedSizeBits(short protectflag, float *size)
1614 if(protectflag & OB_LOCK_SCALEX)
1616 if(protectflag & OB_LOCK_SCALEY)
1618 if(protectflag & OB_LOCK_SCALEZ)
1622 static void protectedRotateBits(short protectflag, float *eul, float *oldeul)
1624 if(protectflag & OB_LOCK_ROTX)
1626 if(protectflag & OB_LOCK_ROTY)
1628 if(protectflag & OB_LOCK_ROTZ)
1633 /* this function only does the delta rotation */
1634 /* axis-angle is usually internally stored as quats... */
1635 static void protectedAxisAngleBits(short protectflag, float axis[3], float *angle, float oldAxis[3], float oldAngle)
1637 /* check that protection flags are set */
1638 if ((protectflag & (OB_LOCK_ROTX|OB_LOCK_ROTY|OB_LOCK_ROTZ|OB_LOCK_ROTW)) == 0)
1641 if (protectflag & OB_LOCK_ROT4D) {
1642 /* axis-angle getting limited as 4D entities that they are... */
1643 if (protectflag & OB_LOCK_ROTW)
1645 if (protectflag & OB_LOCK_ROTX)
1646 axis[0]= oldAxis[0];
1647 if (protectflag & OB_LOCK_ROTY)
1648 axis[1]= oldAxis[1];
1649 if (protectflag & OB_LOCK_ROTZ)
1650 axis[2]= oldAxis[2];
1653 /* axis-angle get limited with euler... */
1654 float eul[3], oldeul[3];
1656 axis_angle_to_eulO( eul, EULER_ORDER_DEFAULT,axis, *angle);
1657 axis_angle_to_eulO( oldeul, EULER_ORDER_DEFAULT,oldAxis, oldAngle);
1659 if (protectflag & OB_LOCK_ROTX)
1661 if (protectflag & OB_LOCK_ROTY)
1663 if (protectflag & OB_LOCK_ROTZ)
1666 eulO_to_axis_angle( axis, angle,eul, EULER_ORDER_DEFAULT);
1668 /* when converting to axis-angle, we need a special exception for the case when there is no axis */
1669 if (IS_EQ(axis[0], axis[1]) && IS_EQ(axis[1], axis[2])) {
1670 /* for now, rotate around y-axis then (so that it simply becomes the roll) */
1676 /* this function only does the delta rotation */
1677 static void protectedQuaternionBits(short protectflag, float *quat, float *oldquat)
1679 /* check that protection flags are set */
1680 if ((protectflag & (OB_LOCK_ROTX|OB_LOCK_ROTY|OB_LOCK_ROTZ|OB_LOCK_ROTW)) == 0)
1683 if (protectflag & OB_LOCK_ROT4D) {
1684 /* quaternions getting limited as 4D entities that they are... */
1685 if (protectflag & OB_LOCK_ROTW)
1686 quat[0]= oldquat[0];
1687 if (protectflag & OB_LOCK_ROTX)
1688 quat[1]= oldquat[1];
1689 if (protectflag & OB_LOCK_ROTY)
1690 quat[2]= oldquat[2];
1691 if (protectflag & OB_LOCK_ROTZ)
1692 quat[3]= oldquat[3];
1695 /* quaternions get limited with euler... (compatability mode) */
1696 float eul[3], oldeul[3], quat1[4];
1698 QUATCOPY(quat1, quat);
1699 quat_to_eul( eul,quat);
1700 quat_to_eul( oldeul,oldquat);
1702 if (protectflag & OB_LOCK_ROTX)
1704 if (protectflag & OB_LOCK_ROTY)
1706 if (protectflag & OB_LOCK_ROTZ)
1709 eul_to_quat( quat,eul);
1711 /* quaternions flip w sign to accumulate rotations correctly */
1712 if ( (quat1[0]<0.0f && quat[0]>0.0f) || (quat1[0]>0.0f && quat[0]<0.0f) ) {
1713 mul_qt_fl(quat, -1.0f);
1718 /* ******************* TRANSFORM LIMITS ********************** */
1720 static void constraintTransLim(TransInfo *t, TransData *td)
1723 bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_LOCLIMIT);
1727 /* Make a temporary bConstraintOb for using these limit constraints
1728 * - they only care that cob->matrix is correctly set ;-)
1729 * - current space should be local
1731 memset(&cob, 0, sizeof(bConstraintOb));
1732 unit_m4(cob.matrix);
1733 VECCOPY(cob.matrix[3], td->loc);
1735 /* Evaluate valid constraints */
1736 for (con= td->con; con; con= con->next) {
1739 /* only consider constraint if enabled */
1740 if (con->flag & CONSTRAINT_DISABLE) continue;
1741 if (con->enforce == 0.0f) continue;
1743 /* only use it if it's tagged for this purpose (and the right type) */
1744 if (con->type == CONSTRAINT_TYPE_LOCLIMIT) {
1745 bLocLimitConstraint *data= con->data;
1747 if ((data->flag2 & LIMIT_TRANSFORM)==0)
1750 /* do space conversions */
1751 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1752 /* just multiply by td->mtx (this should be ok) */
1753 copy_m4_m4(tmat, cob.matrix);
1754 mul_m4_m3m4(cob.matrix, td->mtx, tmat);
1756 else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) {
1757 /* skip... incompatable spacetype */
1762 cti->evaluate_constraint(con, &cob, NULL);
1764 /* convert spaces again */
1765 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1766 /* just multiply by td->mtx (this should be ok) */
1767 copy_m4_m4(tmat, cob.matrix);
1768 mul_m4_m3m4(cob.matrix, td->smtx, tmat);
1773 /* copy results from cob->matrix */
1774 VECCOPY(td->loc, cob.matrix[3]);
1778 static void constraintRotLim(TransInfo *t, TransData *td)
1781 bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_ROTLIMIT);
1785 /* Make a temporary bConstraintOb for using these limit constraints
1786 * - they only care that cob->matrix is correctly set ;-)
1787 * - current space should be local
1789 memset(&cob, 0, sizeof(bConstraintOb));
1790 if (td->rotOrder == ROT_MODE_QUAT) {
1793 quat_to_mat4( cob.matrix,td->ext->quat);
1797 else if (td->rotOrder == ROT_MODE_AXISANGLE) {
1800 axis_angle_to_mat4( cob.matrix,&td->ext->quat[1], td->ext->quat[0]);
1807 eulO_to_mat4( cob.matrix,td->ext->rot, td->rotOrder);
1812 /* Evaluate valid constraints */
1813 for (con= td->con; con; con= con->next) {
1814 /* only consider constraint if enabled */
1815 if (con->flag & CONSTRAINT_DISABLE) continue;
1816 if (con->enforce == 0.0f) continue;
1818 /* we're only interested in Limit-Rotation constraints */
1819 if (con->type == CONSTRAINT_TYPE_ROTLIMIT) {
1820 bRotLimitConstraint *data= con->data;
1823 /* only use it if it's tagged for this purpose */
1824 if ((data->flag2 & LIMIT_TRANSFORM)==0)
1827 /* do space conversions */
1828 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1829 /* just multiply by td->mtx (this should be ok) */
1830 copy_m4_m4(tmat, cob.matrix);
1831 mul_m4_m3m4(cob.matrix, td->mtx, tmat);
1833 else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) {
1834 /* skip... incompatable spacetype */
1839 cti->evaluate_constraint(con, &cob, NULL);
1841 /* convert spaces again */
1842 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1843 /* just multiply by td->mtx (this should be ok) */
1844 copy_m4_m4(tmat, cob.matrix);
1845 mul_m4_m3m4(cob.matrix, td->smtx, tmat);
1850 /* copy results from cob->matrix */
1851 if (td->rotOrder == ROT_MODE_QUAT) {
1853 mat4_to_quat( td->ext->quat,cob.matrix);
1855 else if (td->rotOrder == ROT_MODE_AXISANGLE) {
1857 mat4_to_axis_angle( &td->ext->quat[1], &td->ext->quat[0],cob.matrix);
1861 mat4_to_eulO( td->ext->rot, td->rotOrder,cob.matrix);
1866 static void constraintSizeLim(TransInfo *t, TransData *td)
1868 if (td->con && td->ext) {
1869 bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_SIZELIMIT);
1873 /* Make a temporary bConstraintOb for using these limit constraints
1874 * - they only care that cob->matrix is correctly set ;-)
1875 * - current space should be local
1877 memset(&cob, 0, sizeof(bConstraintOb));
1878 if ((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)) {
1879 /* scale val and reset size */
1880 return; // TODO: fix this case
1883 /* Reset val if SINGLESIZE but using a constraint */
1884 if (td->flag & TD_SINGLESIZE)
1887 size_to_mat4( cob.matrix,td->ext->size);
1890 /* Evaluate valid constraints */
1891 for (con= td->con; con; con= con->next) {
1892 /* only consider constraint if enabled */
1893 if (con->flag & CONSTRAINT_DISABLE) continue;
1894 if (con->enforce == 0.0f) continue;
1896 /* we're only interested in Limit-Scale constraints */
1897 if (con->type == CONSTRAINT_TYPE_SIZELIMIT) {
1898 bSizeLimitConstraint *data= con->data;
1901 /* only use it if it's tagged for this purpose */
1902 if ((data->flag2 & LIMIT_TRANSFORM)==0)
1905 /* do space conversions */
1906 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1907 /* just multiply by td->mtx (this should be ok) */
1908 copy_m4_m4(tmat, cob.matrix);
1909 mul_m4_m3m4(cob.matrix, td->mtx, tmat);
1911 else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) {
1912 /* skip... incompatable spacetype */
1917 cti->evaluate_constraint(con, &cob, NULL);
1919 /* convert spaces again */
1920 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1921 /* just multiply by td->mtx (this should be ok) */
1922 copy_m4_m4(tmat, cob.matrix);
1923 mul_m4_m3m4(cob.matrix, td->smtx, tmat);
1928 /* copy results from cob->matrix */
1929 if ((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)) {
1930 /* scale val and reset size */
1931 return; // TODO: fix this case
1934 /* Reset val if SINGLESIZE but using a constraint */
1935 if (td->flag & TD_SINGLESIZE)
1938 mat4_to_size( td->ext->size,cob.matrix);
1943 /* ************************** WARP *************************** */
1945 void initWarp(TransInfo *t)
1947 float max[3], min[3];
1951 t->transform = Warp;
1952 t->handleEvent = handleEventWarp;
1954 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_RATIO);
1962 t->flag |= T_NO_CONSTRAINT;
1964 /* we need min/max in view space */
1965 for(i = 0; i < t->total; i++) {
1967 VECCOPY(center, t->data[i].center);
1968 mul_m3_v3(t->data[i].mtx, center);
1969 mul_m4_v3(t->viewmat, center);
1970 sub_v3_v3v3(center, center, t->viewmat[3]);
1972 minmax_v3_v3v3(min, max, center);
1974 VECCOPY(max, center);
1975 VECCOPY(min, center);
1979 t->center[0]= (min[0]+max[0])/2.0f;
1980 t->center[1]= (min[1]+max[1])/2.0f;
1981 t->center[2]= (min[2]+max[2])/2.0f;
1983 if (max[0] == min[0]) max[0] += 0.1; /* not optimal, but flipping is better than invalid garbage (i.e. division by zero!) */
1984 t->val= (max[0]-min[0])/2.0f; /* t->val is X dimension projected boundbox */
1987 int handleEventWarp(TransInfo *t, wmEvent *event)
1991 if (event->type == MIDDLEMOUSE && event->val==KM_PRESS)
1993 // Use customData pointer to signal warp direction
1994 if (t->customData == 0)
1995 t->customData = (void*)1;
2005 int Warp(TransInfo *t, short mval[2])
2007 TransData *td = t->data;
2008 float vec[3], circumfac, dist, phi0, co, si, *curs, cursor[3], gcursor[3];
2012 curs= give_cursor(t->scene, t->view);
2014 * gcursor is the one used for helpline.
2015 * It has to be in the same space as the drawing loop
2016 * (that means it needs to be in the object's space when in edit mode and
2017 * in global space in object mode)
2019 * cursor is used for calculations.
2020 * It needs to be in view space, but we need to take object's offset
2021 * into account if in Edit mode.
2023 VECCOPY(cursor, curs);
2024 VECCOPY(gcursor, cursor);
2025 if (t->flag & T_EDIT) {
2026 sub_v3_v3v3(cursor, cursor, t->obedit->obmat[3]);
2027 sub_v3_v3v3(gcursor, gcursor, t->obedit->obmat[3]);
2028 mul_m3_v3(t->data->smtx, gcursor);
2030 mul_m4_v3(t->viewmat, cursor);
2031 sub_v3_v3v3(cursor, cursor, t->viewmat[3]);
2033 /* amount of degrees for warp */
2034 circumfac = 360.0f * t->values[0];
2036 if (t->customData) /* non-null value indicates reversed input */
2041 snapGrid(t, &circumfac);
2042 applyNumInput(&t->num, &circumfac);
2044 /* header print for NumInput */
2045 if (hasNumInput(&t->num)) {
2048 outputNumInput(&(t->num), c);
2050 sprintf(str, "Warp: %s", c);
2053 /* default header print */
2054 sprintf(str, "Warp: %.3f", circumfac);
2057 circumfac*= (float)(-M_PI/360.0);
2059 for(i = 0; i < t->total; i++, td++) {
2061 if (td->flag & TD_NOACTION)
2064 if (td->flag & TD_SKIP)
2067 /* translate point to center, rotate in such a way that outline==distance */
2068 VECCOPY(vec, td->iloc);
2069 mul_m3_v3(td->mtx, vec);
2070 mul_m4_v3(t->viewmat, vec);
2071 sub_v3_v3v3(vec, vec, t->viewmat[3]);
2073 dist= vec[0]-cursor[0];
2075 /* t->val is X dimension projected boundbox */
2076 phi0= (circumfac*dist/t->val);
2078 vec[1]= (vec[1]-cursor[1]);
2080 co= (float)cos(phi0);
2081 si= (float)sin(phi0);
2082 loc[0]= -si*vec[1]+cursor[0];
2083 loc[1]= co*vec[1]+cursor[1];
2086 mul_m4_v3(t->viewinv, loc);
2087 sub_v3_v3v3(loc, loc, t->viewinv[3]);
2088 mul_m3_v3(td->smtx, loc);
2090 sub_v3_v3v3(loc, loc, td->iloc);
2091 mul_v3_fl(loc, td->factor);
2092 add_v3_v3v3(td->loc, td->iloc, loc);
2097 ED_area_headerprint(t->sa, str);
2102 /* ************************** SHEAR *************************** */
2104 void initShear(TransInfo *t)
2106 t->mode = TFM_SHEAR;
2107 t->transform = Shear;
2108 t->handleEvent = handleEventShear;
2110 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_ABSOLUTE);
2116 t->snap[2] = t->snap[1] * 0.1f;
2118 t->flag |= T_NO_CONSTRAINT;
2121 int handleEventShear(TransInfo *t, wmEvent *event)
2125 if (event->type == MIDDLEMOUSE && event->val==KM_PRESS)
2127 // Use customData pointer to signal Shear direction
2128 if (t->customData == 0)
2130 initMouseInputMode(t, &t->mouse, INPUT_VERTICAL_ABSOLUTE);
2131 t->customData = (void*)1;
2135 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_ABSOLUTE);
2146 int Shear(TransInfo *t, short mval[2])
2148 TransData *td = t->data;
2150 float smat[3][3], tmat[3][3], totmat[3][3], persmat[3][3], persinv[3][3];
2155 copy_m3_m4(persmat, t->viewmat);
2156 invert_m3_m3(persinv, persmat);
2158 value = 0.05f * t->values[0];
2160 snapGrid(t, &value);
2162 applyNumInput(&t->num, &value);
2164 /* header print for NumInput */
2165 if (hasNumInput(&t->num)) {
2168 outputNumInput(&(t->num), c);
2170 sprintf(str, "Shear: %s %s", c, t->proptext);
2173 /* default header print */
2174 sprintf(str, "Shear: %.3f %s", value, t->proptext);
2179 // Custom data signals shear direction
2180 if (t->customData == 0)
2185 mul_m3_m3m3(tmat, smat, persmat);
2186 mul_m3_m3m3(totmat, persinv, tmat);
2188 for(i = 0 ; i < t->total; i++, td++) {
2189 if (td->flag & TD_NOACTION)
2192 if (td->flag & TD_SKIP)
2197 mul_m3_m3m3(mat3, totmat, td->mtx);
2198 mul_m3_m3m3(tmat, td->smtx, mat3);
2201 copy_m3_m3(tmat, totmat);
2203 sub_v3_v3v3(vec, td->center, t->center);
2205 mul_m3_v3(tmat, vec);
2207 add_v3_v3v3(vec, vec, t->center);
2208 sub_v3_v3v3(vec, vec, td->center);
2210 mul_v3_fl(vec, td->factor);
2212 add_v3_v3v3(td->loc, td->iloc, vec);
2217 ED_area_headerprint(t->sa, str);
2222 /* ************************** RESIZE *************************** */
2224 void initResize(TransInfo *t)
2226 t->mode = TFM_RESIZE;
2227 t->transform = Resize;
2229 initMouseInputMode(t, &t->mouse, INPUT_SPRING_FLIP);
2231 t->flag |= T_NULL_ONE;
2232 t->num.flag |= NUM_NULL_ONE;
2233 t->num.flag |= NUM_AFFECT_ALL;
2235 t->flag |= T_NO_ZERO;
2236 t->num.flag |= NUM_NO_ZERO;
2243 t->snap[2] = t->snap[1] * 0.1f;
2246 static void headerResize(TransInfo *t, float vec[3], char *str) {
2248 if (hasNumInput(&t->num)) {
2249 outputNumInput(&(t->num), tvec);
2252 sprintf(&tvec[0], "%.4f", vec[0]);
2253 sprintf(&tvec[20], "%.4f", vec[1]);
2254 sprintf(&tvec[40], "%.4f", vec[2]);
2257 if (t->con.mode & CON_APPLY) {
2258 switch(t->num.idx_max) {
2260 sprintf(str, "Scale: %s%s %s", &tvec[0], t->con.text, t->proptext);
2263 sprintf(str, "Scale: %s : %s%s %s", &tvec[0], &tvec[20], t->con.text, t->proptext);
2266 sprintf(str, "Scale: %s : %s : %s%s %s", &tvec[0], &tvec[20], &tvec[40], t->con.text, t->proptext);
2270 if (t->flag & T_2D_EDIT)
2271 sprintf(str, "Scale X: %s Y: %s%s %s", &tvec[0], &tvec[20], t->con.text, t->proptext);
2273 sprintf(str, "Scale X: %s Y: %s Z: %s%s %s", &tvec[0], &tvec[20], &tvec[40], t->con.text, t->proptext);
2277 #define SIGN(a) (a<-FLT_EPSILON?1:a>FLT_EPSILON?2:3)
2278 #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)
2280 /* smat is reference matrix, only scaled */
2281 static void TransMat3ToSize( float mat[][3], float smat[][3], float *size)
2285 copy_v3_v3(vec, mat[0]);
2286 size[0]= normalize_v3(vec);
2287 copy_v3_v3(vec, mat[1]);
2288 size[1]= normalize_v3(vec);
2289 copy_v3_v3(vec, mat[2]);
2290 size[2]= normalize_v3(vec);
2292 /* first tried with dotproduct... but the sign flip is crucial */
2293 if( VECSIGNFLIP(mat[0], smat[0]) ) size[0]= -size[0];
2294 if( VECSIGNFLIP(mat[1], smat[1]) ) size[1]= -size[1];
2295 if( VECSIGNFLIP(mat[2], smat[2]) ) size[2]= -size[2];
2299 static void ElementResize(TransInfo *t, TransData *td, float mat[3][3]) {
2300 float tmat[3][3], smat[3][3], center[3];
2303 if (t->flag & T_EDIT) {
2304 mul_m3_m3m3(smat, mat, td->mtx);
2305 mul_m3_m3m3(tmat, td->smtx, smat);
2308 copy_m3_m3(tmat, mat);
2311 if (t->con.applySize) {
2312 t->con.applySize(t, td, tmat);
2315 /* local constraint shouldn't alter center */
2316 if (t->around == V3D_LOCAL) {
2317 if (t->flag & T_OBJECT) {
2318 VECCOPY(center, td->center);
2320 else if (t->flag & T_EDIT) {
2322 if(t->around==V3D_LOCAL && (t->settings->selectmode & SCE_SELECT_FACE)) {
2323 VECCOPY(center, td->center);
2326 VECCOPY(center, t->center);
2330 VECCOPY(center, t->center);
2334 VECCOPY(center, t->center);
2340 if (t->flag & (T_OBJECT|T_TEXTURE|T_POSE)) {
2341 float obsizemat[3][3];
2342 // Reorient the size mat to fit the oriented object.
2343 mul_m3_m3m3(obsizemat, tmat, td->axismtx);
2344 //print_m3("obsizemat", obsizemat);
2345 TransMat3ToSize(obsizemat, td->axismtx, fsize);
2346 //print_v3("fsize", fsize);
2349 mat3_to_size( fsize,tmat);
2352 protectedSizeBits(td->protectflag, fsize);
2354 if ((t->flag & T_V3D_ALIGN)==0) { // align mode doesn't resize objects itself
2355 if((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)){
2356 /* scale val and reset size */
2357 *td->val = td->ival * (1 + (fsize[0] - 1) * td->factor);
2359 td->ext->size[0] = td->ext->isize[0];
2360 td->ext->size[1] = td->ext->isize[1];
2361 td->ext->size[2] = td->ext->isize[2];
2364 /* Reset val if SINGLESIZE but using a constraint */
2365 if (td->flag & TD_SINGLESIZE)
2366 *td->val = td->ival;
2368 td->ext->size[0] = td->ext->isize[0] * (1 + (fsize[0] - 1) * td->factor);
2369 td->ext->size[1] = td->ext->isize[1] * (1 + (fsize[1] - 1) * td->factor);
2370 td->ext->size[2] = td->ext->isize[2] * (1 + (fsize[2] - 1) * td->factor);
2374 constraintSizeLim(t, td);
2377 /* For individual element center, Editmode need to use iloc */
2378 if (t->flag & T_POINTS)
2379 sub_v3_v3v3(vec, td->iloc, center);
2381 sub_v3_v3v3(vec, td->center, center);
2383 mul_m3_v3(tmat, vec);
2385 add_v3_v3v3(vec, vec, center);
2386 if (t->flag & T_POINTS)
2387 sub_v3_v3v3(vec, vec, td->iloc);
2389 sub_v3_v3v3(vec, vec, td->center);
2391 mul_v3_fl(vec, td->factor);
2393 if (t->flag & (T_OBJECT|T_POSE)) {
2394 mul_m3_v3(td->smtx, vec);
2397 protectedTransBits(td->protectflag, vec);
2398 add_v3_v3v3(td->loc, td->iloc, vec);
2400 constraintTransLim(t, td);
2403 int Resize(TransInfo *t, short mval[2])
2406 float size[3], mat[3][3];
2411 /* for manipulator, center handle, the scaling can't be done relative to center */
2412 if( (t->flag & T_USES_MANIPULATOR) && t->con.mode==0)
2414 ratio = 1.0f - ((t->imval[0] - mval[0]) + (t->imval[1] - mval[1]))/100.0f;
2418 ratio = t->values[0];
2421 size[0] = size[1] = size[2] = ratio;
2425 if (hasNumInput(&t->num)) {
2426 applyNumInput(&t->num, size);
2427 constraintNumInput(t, size);
2430 applySnapping(t, size);
2432 if (t->flag & T_AUTOVALUES)
2434 VECCOPY(size, t->auto_values);
2437 VECCOPY(t->values, size);
2439 size_to_mat3( mat,size);
2441 if (t->con.applySize) {
2442 t->con.applySize(t, NULL, mat);
2445 copy_m3_m3(t->mat, mat); // used in manipulator
2447 headerResize(t, size, str);
2449 for(i = 0, td=t->data; i < t->total; i++, td++) {
2450 if (td->flag & TD_NOACTION)
2453 if (td->flag & TD_SKIP)
2456 ElementResize(t, td, mat);
2459 /* evil hack - redo resize if cliping needed */
2460 if (t->flag & T_CLIP_UV && clipUVTransform(t, size, 1)) {
2461 size_to_mat3( mat,size);
2463 if (t->con.applySize)
2464 t->con.applySize(t, NULL, mat);
2466 for(i = 0, td=t->data; i < t->total; i++, td++)
2467 ElementResize(t, td, mat);
2472 ED_area_headerprint(t->sa, str);
2477 /* ************************** TOSPHERE *************************** */
2479 void initToSphere(TransInfo *t)
2481 TransData *td = t->data;
2484 t->mode = TFM_TOSPHERE;
2485 t->transform = ToSphere;
2487 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_RATIO);
2493 t->snap[2] = t->snap[1] * 0.1f;
2495 t->num.flag |= NUM_NULL_ONE | NUM_NO_NEGATIVE;
2496 t->flag |= T_NO_CONSTRAINT;
2498 // Calculate average radius
2499 for(i = 0 ; i < t->total; i++, td++) {
2500 t->val += len_v3v3(t->center, td->iloc);
2503 t->val /= (float)t->total;
2506 int ToSphere(TransInfo *t, short mval[2])
2509 float ratio, radius;
2512 TransData *td = t->data;
2514 ratio = t->values[0];
2516 snapGrid(t, &ratio);
2518 applyNumInput(&t->num, &ratio);
2525 /* header print for NumInput */
2526 if (hasNumInput(&t->num)) {
2529 outputNumInput(&(t->num), c);
2531 sprintf(str, "To Sphere: %s %s", c, t->proptext);
2534 /* default header print */
2535 sprintf(str, "To Sphere: %.4f %s", ratio, t->proptext);
2539 for(i = 0 ; i < t->total; i++, td++) {
2541 if (td->flag & TD_NOACTION)
2544 if (td->flag & TD_SKIP)
2547 sub_v3_v3v3(vec, td->iloc, t->center);
2549 radius = normalize_v3(vec);
2551 tratio = ratio * td->factor;
2553 mul_v3_fl(vec, radius * (1.0f - tratio) + t->val * tratio);
2555 add_v3_v3v3(td->loc, t->center, vec);
2561 ED_area_headerprint(t->sa, str);
2566 /* ************************** ROTATION *************************** */
2569 void initRotation(TransInfo *t)
2571 t->mode = TFM_ROTATION;
2572 t->transform = Rotation;
2574 initMouseInputMode(t, &t->mouse, INPUT_ANGLE);
2577 /* Scale down and flip input for rotation */
2578 t->ndof.factor[0] = -0.2f;
2583 t->snap[1] = (float)((5.0/180)*M_PI);
2584 t->snap[2] = t->snap[1] * 0.2f;
2586 if (t->flag & T_2D_EDIT)
2587 t->flag |= T_NO_CONSTRAINT;
2590 static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short around) {
2591 float vec[3], totmat[3][3], smat[3][3];
2592 float eul[3], fmat[3][3], quat[4];
2593 float *center = t->center;
2595 /* local constraint shouldn't alter center */
2596 if (around == V3D_LOCAL) {
2597 if (t->flag & (T_OBJECT|T_POSE)) {
2598 center = td->center;
2601 if(around==V3D_LOCAL && (t->settings->selectmode & SCE_SELECT_FACE)) {
2602 center = td->center;
2607 if (t->flag & T_POINTS) {
2608 mul_m3_m3m3(totmat, mat, td->mtx);
2609 mul_m3_m3m3(smat, td->smtx, totmat);
2611 sub_v3_v3v3(vec, td->iloc, center);
2612 mul_m3_v3(smat, vec);
2614 add_v3_v3v3(td->loc, vec, center);
2616 sub_v3_v3v3(vec,td->loc,td->iloc);
2617 protectedTransBits(td->protectflag, vec);
2618 add_v3_v3v3(td->loc, td->iloc, vec);
2621 if(td->flag & TD_USEQUAT) {
2622 mul_serie_m3(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0);
2623 mat3_to_quat( quat,fmat); // Actual transform
2626 mul_qt_qtqt(td->ext->quat, quat, td->ext->iquat);
2628 /* is there a reason not to have this here? -jahka */
2629 protectedQuaternionBits(td->protectflag, td->ext->quat, td->ext->iquat);
2636 * This is some VERY ugly special case to deal with pose mode.
2638 * The problem is that mtx and smtx include each bone orientation.
2640 * That is needed to rotate each bone properly, HOWEVER, to calculate
2641 * the translation component, we only need the actual armature object's
2642 * matrix (and inverse). That is not all though. Once the proper translation
2643 * has been computed, it has to be converted back into the bone's space.
2645 else if (t->flag & T_POSE) {
2646 float pmtx[3][3], imtx[3][3];
2648 // Extract and invert armature object matrix
2649 copy_m3_m4(pmtx, t->poseobj->obmat);
2650 invert_m3_m3(imtx, pmtx);
2652 if ((td->flag & TD_NO_LOC) == 0)
2654 sub_v3_v3v3(vec, td->center, center);
2656 mul_m3_v3(pmtx, vec); // To Global space
2657 mul_m3_v3(mat, vec); // Applying rotation
2658 mul_m3_v3(imtx, vec); // To Local space
2660 add_v3_v3v3(vec, vec, center);
2661 /* vec now is the location where the object has to be */
2663 sub_v3_v3v3(vec, vec, td->center); // Translation needed from the initial location
2665 mul_m3_v3(pmtx, vec); // To Global space
2666 mul_m3_v3(td->smtx, vec);// To Pose space
2668 protectedTransBits(td->protectflag, vec);
2670 add_v3_v3v3(td->loc, td->iloc, vec);
2672 constraintTransLim(t, td);
2676 if ((t->flag & T_V3D_ALIGN)==0) { // align mode doesn't rotate objects itself
2677 /* euler or quaternion/axis-angle? */
2678 if (td->rotOrder == ROT_MODE_QUAT) {
2679 mul_serie_m3(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0);
2681 mat3_to_quat( quat,fmat); // Actual transform
2683 mul_qt_qtqt(td->ext->quat, quat, td->ext->iquat);
2684 /* this function works on end result */
2685 protectedQuaternionBits(td->protectflag, td->ext->quat, td->ext->iquat);
2688 else if (td->rotOrder == ROT_MODE_AXISANGLE) {
2689 /* calculate effect based on quats */
2690 float iquat[4], tquat[4];
2692 axis_angle_to_quat(iquat, td->ext->irotAxis, td->ext->irotAngle);
2694 mul_serie_m3(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0);
2695 mat3_to_quat( quat,fmat); // Actual transform
2696 mul_qt_qtqt(tquat, quat, iquat);
2698 quat_to_axis_angle( td->ext->rotAxis, td->ext->rotAngle,tquat);
2700 /* this function works on end result */
2701 protectedAxisAngleBits(td->protectflag, td->ext->rotAxis, td->ext->rotAngle, td->ext->irotAxis, td->ext->irotAngle);
2706 mul_m3_m3m3(totmat, mat, td->mtx);
2707 mul_m3_m3m3(smat, td->smtx, totmat);
2709 /* calculate the total rotatation in eulers */
2710 VECCOPY(eul, td->ext->irot);
2711 eulO_to_mat3( eulmat,eul, td->rotOrder);
2713 /* mat = transform, obmat = bone rotation */
2714 mul_m3_m3m3(fmat, smat, eulmat);
2716 mat3_to_compatible_eulO( eul, td->ext->rot, td->rotOrder,fmat);
2718 /* and apply (to end result only) */
2719 protectedRotateBits(td->protectflag, eul, td->ext->irot);
2720 VECCOPY(td->ext->rot, eul);
2723 constraintRotLim(t, td);
2727 if ((td->flag & TD_NO_LOC) == 0)
2730 sub_v3_v3v3(vec, td->center, center);
2731 mul_m3_v3(mat, vec);
2732 add_v3_v3v3(vec, vec, center);
2733 /* vec now is the location where the object has to be */
2734 sub_v3_v3v3(vec, vec, td->center);
2735 mul_m3_v3(td->smtx, vec);
2737 protectedTransBits(td->protectflag, vec);
2739 add_v3_v3v3(td->loc, td->iloc, vec);
2743 constraintTransLim(t, td);
2746 if ((t->flag & T_V3D_ALIGN)==0) { // align mode doesn't rotate objects itself
2747 /* euler or quaternion? */
2748 if ((td->rotOrder == ROT_MODE_QUAT) || (td->flag & TD_USEQUAT)) {
2749 mul_serie_m3(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0);
2750 mat3_to_quat( quat,fmat); // Actual transform
2752 mul_qt_qtqt(td->ext->quat, quat, td->ext->iquat);
2753 /* this function works on end result */
2754 protectedQuaternionBits(td->protectflag, td->ext->quat, td->ext->iquat);
2756 else if (td->rotOrder == ROT_MODE_AXISANGLE) {
2757 /* calculate effect based on quats */
2758 float iquat[4], tquat[4];
2760 axis_angle_to_quat(iquat, td->ext->irotAxis, td->ext->irotAngle);
2762 mul_serie_m3(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0);
2763 mat3_to_quat( quat,fmat); // Actual transform
2764 mul_qt_qtqt(tquat, quat, iquat);
2766 quat_to_axis_angle( td->ext->rotAxis, td->ext->rotAngle,quat);
2768 /* this function works on end result */
2769 protectedAxisAngleBits(td->protectflag, td->ext->rotAxis, td->ext->rotAngle, td->ext->irotAxis, td->ext->irotAngle);
2774 mul_m3_m3m3(totmat, mat, td->mtx);
2775 mul_m3_m3m3(smat, td->smtx, totmat);
2777 /* calculate the total rotatation in eulers */
2778 add_v3_v3v3(eul, td->ext->irot, td->ext->drot); /* we have to correct for delta rot */
2779 eulO_to_mat3( obmat,eul, td->rotOrder);
2780 /* mat = transform, obmat = object rotation */
2781 mul_m3_m3m3(fmat, smat, obmat);
2783 mat3_to_compatible_eulO( eul, td->ext->rot, td->rotOrder,fmat);
2785 /* correct back for delta rot */
2786 sub_v3_v3v3(eul, eul, td->ext->drot);
2789 protectedRotateBits(td->protectflag, eul, td->ext->irot);
2790 VECCOPY(td->ext->rot, eul);
2793 constraintRotLim(t, td);
2798 static void applyRotation(TransInfo *t, float angle, float axis[3])
2800 TransData *td = t->data;
2804 vec_rot_to_mat3( mat,axis, angle);
2806 for(i = 0 ; i < t->total; i++, td++) {
2808 if (td->flag & TD_NOACTION)
2811 if (td->flag & TD_SKIP)
2814 if (t->con.applyRot) {
2815 t->con.applyRot(t, td, axis, NULL);
2816 vec_rot_to_mat3( mat,axis, angle * td->factor);
2818 else if (t->flag & T_PROP_EDIT) {
2819 vec_rot_to_mat3( mat,axis, angle * td->factor);
2822 ElementRotation(t, td, mat, t->around);
2826 int Rotation(TransInfo *t, short mval[2])
2835 VECCOPY(axis, t->viewinv[2]);
2836 mul_v3_fl(axis, -1.0f);
2839 final = t->values[0];
2841 applyNDofInput(&t->ndof, &final);
2843 snapGrid(t, &final);
2845 if (t->con.applyRot) {
2846 t->con.applyRot(t, NULL, axis, &final);
2849 applySnapping(t, &final);
2851 if (hasNumInput(&t->num)) {
2854 applyNumInput(&t->num, &final);
2856 outputNumInput(&(t->num), c);
2858 sprintf(str, "Rot: %s %s %s", &c[0], t->con.text, t->proptext);
2860 /* Clamp between -180 and 180 */
2861 while (final >= 180.0)
2864 while (final <= -180.0)
2867 final *= (float)(M_PI / 180.0);
2870 sprintf(str, "Rot: %.2f%s %s", 180.0*final/M_PI, t->con.text, t->proptext);
2873 vec_rot_to_mat3( mat,axis, final);
2876 // t->values[0] = final; // used in manipulator
2877 // copy_m3_m3(t->mat, mat); // used in manipulator
2879 applyRotation(t, final, axis);
2883 ED_area_headerprint(t->sa, str);
2889 /* ************************** TRACKBALL *************************** */
2891 void initTrackball(TransInfo *t)
2893 t->mode = TFM_TRACKBALL;
2894 t->transform = Trackball;
2896 initMouseInputMode(t, &t->mouse, INPUT_TRACKBALL);
2899 /* Scale down input for rotation */
2900 t->ndof.factor[0] = 0.2f;
2901 t->ndof.factor[1] = 0.2f;
2906 t->snap[1] = (float)((5.0/180)*M_PI);
2907 t->snap[2] = t->snap[1] * 0.2f;
2909 t->flag |= T_NO_CONSTRAINT;
2912 static void applyTrackball(TransInfo *t, float axis1[3], float axis2[3], float angles[2])
2914 TransData *td = t->data;
2915 float mat[3][3], smat[3][3], totmat[3][3];