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"
93 //#include "BSE_view.h"
96 #include "ED_keyframing.h"
97 #include "ED_screen.h"
98 #include "ED_space_api.h"
99 #include "ED_markers.h"
101 #include "ED_view3d.h"
103 #include "UI_view2d.h"
104 #include "WM_types.h"
107 #include "BLI_arithb.h"
108 #include "BLI_blenlib.h"
109 #include "BLI_editVert.h"
111 #include "PIL_time.h" /* sleep */
113 #include "UI_resources.h"
115 //#include "blendef.h"
117 //#include "mydevice.h"
119 #include "transform.h"
121 /* ************************** SPACE DEPENDANT CODE **************************** */
123 void setTransformViewMatrices(TransInfo *t)
125 if(t->spacetype==SPACE_VIEW3D && t->ar->regiontype == RGN_TYPE_WINDOW) {
126 RegionView3D *rv3d = t->ar->regiondata;
128 Mat4CpyMat4(t->viewmat, rv3d->viewmat);
129 Mat4CpyMat4(t->viewinv, rv3d->viewinv);
130 Mat4CpyMat4(t->persmat, rv3d->persmat);
131 Mat4CpyMat4(t->persinv, rv3d->persinv);
132 t->persp = rv3d->persp;
139 t->persp = V3D_ORTHO;
142 calculateCenter2D(t);
145 void convertViewVec(TransInfo *t, float *vec, short dx, short dy)
147 if (t->spacetype==SPACE_VIEW3D) {
148 if (t->ar->regiontype == RGN_TYPE_WINDOW)
150 window_to_3d_delta(t->ar, vec, dx, dy);
153 else if(t->spacetype==SPACE_IMAGE) {
154 View2D *v2d = t->view;
155 float divx, divy, aspx, aspy;
157 ED_space_image_uv_aspect(t->sa->spacedata.first, &aspx, &aspy);
159 divx= v2d->mask.xmax-v2d->mask.xmin;
160 divy= v2d->mask.ymax-v2d->mask.ymin;
162 vec[0]= aspx*(v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx;
163 vec[1]= aspy*(v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy;
166 else if(ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)) {
167 View2D *v2d = t->view;
170 divx= v2d->mask.xmax-v2d->mask.xmin;
171 divy= v2d->mask.ymax-v2d->mask.ymin;
173 vec[0]= (v2d->cur.xmax-v2d->cur.xmin)*(dx) / (divx);
174 vec[1]= (v2d->cur.ymax-v2d->cur.ymin)*(dy) / (divy);
177 else if(t->spacetype==SPACE_NODE) {
178 View2D *v2d = &t->ar->v2d;
181 divx= v2d->mask.xmax-v2d->mask.xmin;
182 divy= v2d->mask.ymax-v2d->mask.ymin;
184 vec[0]= (v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx;
185 vec[1]= (v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy;
188 else if(t->spacetype==SPACE_SEQ) {
189 View2D *v2d = &t->ar->v2d;
192 divx= v2d->mask.xmax-v2d->mask.xmin;
193 divy= v2d->mask.ymax-v2d->mask.ymin;
195 vec[0]= (v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx;
196 vec[1]= (v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy;
201 void projectIntView(TransInfo *t, float *vec, int *adr)
203 if (t->spacetype==SPACE_VIEW3D) {
204 if(t->ar->regiontype == RGN_TYPE_WINDOW)
205 project_int_noclip(t->ar, vec, adr);
207 else if(t->spacetype==SPACE_IMAGE) {
208 float aspx, aspy, v[2];
210 ED_space_image_uv_aspect(t->sa->spacedata.first, &aspx, &aspy);
214 UI_view2d_to_region_no_clip(t->view, v[0], v[1], adr, adr+1);
216 else if(ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)) {
219 UI_view2d_view_to_region((View2D *)t->view, vec[0], vec[1], out, out+1);
223 else if(t->spacetype==SPACE_SEQ) { /* XXX not tested yet, but should work */
226 UI_view2d_view_to_region((View2D *)t->view, vec[0], vec[1], out, out+1);
232 void projectFloatView(TransInfo *t, float *vec, float *adr)
234 if (t->spacetype==SPACE_VIEW3D) {
235 if(t->ar->regiontype == RGN_TYPE_WINDOW)
236 project_float_noclip(t->ar, vec, adr);
238 else if(t->spacetype==SPACE_IMAGE) {
241 projectIntView(t, vec, a);
245 else if(ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)) {
248 projectIntView(t, vec, a);
254 void applyAspectRatio(TransInfo *t, float *vec)
256 SpaceImage *sima= t->sa->spacedata.first;
258 if ((t->spacetype==SPACE_IMAGE) && (t->mode==TFM_TRANSLATION)) {
261 if((sima->flag & SI_COORDFLOATS)==0) {
263 ED_space_image_size(sima, &width, &height);
269 ED_space_image_uv_aspect(sima, &aspx, &aspy);
275 void removeAspectRatio(TransInfo *t, float *vec)
277 SpaceImage *sima= t->sa->spacedata.first;
279 if ((t->spacetype==SPACE_IMAGE) && (t->mode==TFM_TRANSLATION)) {
282 if((sima->flag & SI_COORDFLOATS)==0) {
284 ED_space_image_size(sima, &width, &height);
290 ED_space_image_uv_aspect(sima, &aspx, &aspy);
296 static void viewRedrawForce(bContext *C, TransInfo *t)
298 if (t->spacetype == SPACE_VIEW3D)
300 /* Do we need more refined tags? */
301 WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
303 /* for realtime animation record - send notifiers recognised by animation editors */
304 if ((t->animtimer) && IS_AUTOKEY_ON(t->scene))
305 WM_event_add_notifier(C, NC_OBJECT|ND_KEYS, NULL);
307 else if (t->spacetype == SPACE_ACTION) {
308 //SpaceAction *saction= (SpaceAction *)t->sa->spacedata.first;
309 WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME_EDIT, NULL);
311 else if (t->spacetype == SPACE_IPO) {
312 //SpaceIpo *sipo= (SpaceIpo *)t->sa->spacedata.first;
313 WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME_EDIT, NULL);
315 else if (t->spacetype == SPACE_NLA) {
316 WM_event_add_notifier(C, NC_ANIMATION|ND_NLA_EDIT, NULL);
318 else if(t->spacetype == SPACE_NODE)
320 //ED_area_tag_redraw(t->sa);
321 WM_event_add_notifier(C, NC_SCENE|ND_NODES, NULL);
323 else if(t->spacetype == SPACE_SEQ)
325 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, NULL);
327 else if (t->spacetype==SPACE_IMAGE) {
328 // XXX how to deal with lock?
330 SpaceImage *sima= (SpaceImage*)t->sa->spacedata.first;
331 if(sima->lock) force_draw_plus(SPACE_VIEW3D, 0);
335 WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_DATA, t->obedit);
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
513 /* called in transform_ops.c, on each regeneration of keymaps */
514 void transform_modal_keymap(wmWindowManager *wm)
516 static EnumPropertyItem modal_items[] = {
517 {TFM_MODAL_CANCEL, "CANCEL", 0, "Cancel", ""},
518 {TFM_MODAL_CONFIRM, "CONFIRM", 0, "Confirm", ""},
519 {TFM_MODAL_TRANSLATE, "TRANSLATE", 0, "Translate", ""},
520 {TFM_MODAL_ROTATE, "ROTATE", 0, "Rotate", ""},
521 {TFM_MODAL_RESIZE, "RESIZE", 0, "Resize", ""},
522 {TFM_MODAL_SNAP_GEARS, "SNAP_GEARS", 0, "Snap On", ""},
523 {TFM_MODAL_SNAP_GEARS_OFF, "SNAP_GEARS_OFF", 0, "Snap Off", ""},
524 {0, NULL, 0, NULL, NULL}};
526 wmKeyMap *keymap= WM_modalkeymap_get(wm, "Transform Modal Map");
528 /* this function is called for each spacetype, only needs to add map once */
531 keymap= WM_modalkeymap_add(wm, "Transform Modal Map", modal_items);
533 /* items for modal map */
534 WM_modalkeymap_add_item(keymap, ESCKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_CANCEL);
535 WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_ANY, KM_ANY, 0, TFM_MODAL_CONFIRM);
536 WM_modalkeymap_add_item(keymap, RETKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_CONFIRM);
537 WM_modalkeymap_add_item(keymap, PADENTER, KM_PRESS, KM_ANY, 0, TFM_MODAL_CONFIRM);
539 WM_modalkeymap_add_item(keymap, GKEY, KM_PRESS, 0, 0, TFM_MODAL_TRANSLATE);
540 WM_modalkeymap_add_item(keymap, RKEY, KM_PRESS, 0, 0, TFM_MODAL_ROTATE);
541 WM_modalkeymap_add_item(keymap, SKEY, KM_PRESS, 0, 0, TFM_MODAL_RESIZE);
543 WM_modalkeymap_add_item(keymap, LEFTCTRLKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_SNAP_GEARS);
544 WM_modalkeymap_add_item(keymap, LEFTCTRLKEY, KM_RELEASE, KM_ANY, 0, TFM_MODAL_SNAP_GEARS_OFF);
546 /* assign map to operators */
547 WM_modalkeymap_assign(keymap, "TFM_OT_transform");
548 WM_modalkeymap_assign(keymap, "TFM_OT_translate");
549 WM_modalkeymap_assign(keymap, "TFM_OT_rotate");
550 WM_modalkeymap_assign(keymap, "TFM_OT_tosphere");
551 WM_modalkeymap_assign(keymap, "TFM_OT_resize");
552 WM_modalkeymap_assign(keymap, "TFM_OT_shear");
553 WM_modalkeymap_assign(keymap, "TFM_OT_warp");
554 WM_modalkeymap_assign(keymap, "TFM_OT_shrink_fatten");
555 WM_modalkeymap_assign(keymap, "TFM_OT_tilt");
556 WM_modalkeymap_assign(keymap, "TFM_OT_trackball");
561 void transformEvent(TransInfo *t, wmEvent *event)
563 float mati[3][3] = {{1.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 1.0f}};
564 char cmode = constraintModeToChar(t);
566 t->redraw |= handleMouseInput(t, &t->mouse, event);
568 if (event->type == MOUSEMOVE)
570 t->mval[0] = event->x - t->ar->winrct.xmin;
571 t->mval[1] = event->y - t->ar->winrct.ymin;
575 applyMouseInput(t, &t->mouse, t->mval, t->values);
578 /* handle modal keymap first */
579 if (event->type == EVT_MODAL_MAP) {
580 switch (event->val) {
581 case TFM_MODAL_CANCEL:
582 t->state = TRANS_CANCEL;
584 case TFM_MODAL_CONFIRM:
585 t->state = TRANS_CONFIRM;
588 case TFM_MODAL_TRANSLATE:
589 /* only switch when... */
590 if( ELEM3(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL) ) {
591 resetTransRestrictions(t);
592 restoreTransObjects(t);
594 initSnapping(t, NULL); // need to reinit after mode change
598 case TFM_MODAL_ROTATE:
599 /* only switch when... */
600 if( ELEM4(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL, TFM_TRANSLATION) ) {
602 resetTransRestrictions(t);
604 if (t->mode == TFM_ROTATION) {
605 restoreTransObjects(t);
609 restoreTransObjects(t);
612 initSnapping(t, NULL); // need to reinit after mode change
616 case TFM_MODAL_RESIZE:
617 /* only switch when... */
618 if( ELEM3(t->mode, TFM_ROTATION, TFM_TRANSLATION, TFM_TRACKBALL) ) {
619 resetTransRestrictions(t);
620 restoreTransObjects(t);
622 initSnapping(t, NULL); // need to reinit after mode change
627 case TFM_MODAL_SNAP_GEARS:
628 t->modifiers |= MOD_SNAP_GEARS;
631 case TFM_MODAL_SNAP_GEARS_OFF:
632 t->modifiers &= ~MOD_SNAP_GEARS;
637 /* else do non-mapped events */
638 else if (event->val==KM_PRESS) {
639 switch (event->type){
641 t->state = TRANS_CANCEL;
643 /* enforce redraw of transform when modifiers are used */
646 t->modifiers |= MOD_SNAP_GEARS;
652 t->modifiers |= MOD_CONSTRAINT_PLANE;
657 if ((t->spacetype==SPACE_VIEW3D) && event->alt) {
658 #if 0 // TRANSFORM_FIX_ME
662 BIF_selectOrientation();
663 calc_manipulator_stats(curarea);
664 Mat3CpyMat4(t->spacemtx, G.vd->twmat);
665 warp_pointer(mval[0], mval[1]);
669 t->state = TRANS_CONFIRM;
674 if ((t->flag & T_NO_CONSTRAINT)==0) {
675 /* exception for switching to dolly, or trackball, in camera view */
676 if (t->flag & T_CAMERA) {
677 if (t->mode==TFM_TRANSLATION)
678 setLocalConstraint(t, (CON_AXIS2), "along local Z");
679 else if (t->mode==TFM_ROTATION) {
680 restoreTransObjects(t);
685 t->modifiers |= MOD_CONSTRAINT_SELECT;
686 if (t->con.mode & CON_APPLY) {
691 initSelectConstraint(t, t->spacemtx);
694 /* bit hackish... but it prevents mmb select to print the orientation from menu */
695 strcpy(t->spacename, "global");
696 initSelectConstraint(t, mati);
698 postSelectConstraint(t);
705 t->state = TRANS_CANCEL;
709 t->state = TRANS_CONFIRM;
712 /* only switch when... */
713 if( ELEM3(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL) ) {
714 resetTransRestrictions(t);
715 restoreTransObjects(t);
717 initSnapping(t, NULL); // need to reinit after mode change
722 /* only switch when... */
723 if( ELEM3(t->mode, TFM_ROTATION, TFM_TRANSLATION, TFM_TRACKBALL) ) {
724 resetTransRestrictions(t);
725 restoreTransObjects(t);
727 initSnapping(t, NULL); // need to reinit after mode change
732 /* only switch when... */
733 if( ELEM4(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL, TFM_TRANSLATION) ) {
735 resetTransRestrictions(t);
737 if (t->mode == TFM_ROTATION) {
738 restoreTransObjects(t);
742 restoreTransObjects(t);
745 initSnapping(t, NULL); // need to reinit after mode change
751 t->flag ^= T_PROP_CONNECTED;
752 sort_trans_data_dist(t);
753 calculatePropRatio(t);
762 if ((t->flag & T_NO_CONSTRAINT)==0) {
764 if (t->flag & T_2D_EDIT) {
768 if (t->con.mode & CON_USER) {
772 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
773 setUserConstraint(t, (CON_AXIS0), "along %s X");
774 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
775 setUserConstraint(t, (CON_AXIS1|CON_AXIS2), "locking %s X");
780 if (t->flag & T_2D_EDIT) {
781 setConstraint(t, mati, (CON_AXIS0), "along X axis");
784 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
785 setConstraint(t, mati, (CON_AXIS0), "along global X");
786 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
787 setConstraint(t, mati, (CON_AXIS1|CON_AXIS2), "locking global X");
794 if ((t->flag & T_NO_CONSTRAINT)==0) {
796 if (t->flag & T_2D_EDIT) {
800 if (t->con.mode & CON_USER) {
804 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
805 setUserConstraint(t, (CON_AXIS1), "along %s Y");
806 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
807 setUserConstraint(t, (CON_AXIS0|CON_AXIS2), "locking %s Y");
812 if (t->flag & T_2D_EDIT) {
813 setConstraint(t, mati, (CON_AXIS1), "along Y axis");
816 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
817 setConstraint(t, mati, (CON_AXIS1), "along global Y");
818 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
819 setConstraint(t, mati, (CON_AXIS0|CON_AXIS2), "locking global Y");
826 if ((t->flag & T_NO_CONSTRAINT)==0) {
828 if (t->con.mode & CON_USER) {
832 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
833 setUserConstraint(t, (CON_AXIS2), "along %s Z");
834 else if ((t->modifiers & MOD_CONSTRAINT_PLANE) && ((t->flag & T_2D_EDIT)==0))
835 setUserConstraint(t, (CON_AXIS0|CON_AXIS1), "locking %s Z");
838 else if ((t->flag & T_2D_EDIT)==0) {
839 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
840 setConstraint(t, mati, (CON_AXIS2), "along global Z");
841 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
842 setConstraint(t, mati, (CON_AXIS0|CON_AXIS1), "locking global Z");
848 if (t->flag & T_PROP_EDIT && event->shift) {
849 t->prop_mode = (t->prop_mode + 1) % 6;
850 calculatePropRatio(t);
855 if(event->alt && t->flag & T_PROP_EDIT) {
856 t->prop_size *= 1.1f;
857 calculatePropRatio(t);
863 if (t->flag & T_AUTOIK) {
864 transform_autoik_update(t, 1);
866 else if(t->flag & T_PROP_EDIT) {
868 calculatePropRatio(t);
870 else view_editmove(event->type);
874 if(event->alt && t->flag & T_PROP_EDIT) {
875 t->prop_size*= 0.90909090f;
876 calculatePropRatio(t);
882 if (t->flag & T_AUTOIK) {
883 transform_autoik_update(t, -1);
885 else if (t->flag & T_PROP_EDIT) {
886 t->prop_size*= 0.90909090f;
887 calculatePropRatio(t);
889 else view_editmove(event->type);
897 // Numerical input events
898 t->redraw |= handleNumInput(&(t->num), event);
901 switch(handleNDofInput(&(t->ndof), event))
904 if ((t->options & CTX_NDOF) == 0)
906 /* Confirm on normal transform only */
907 t->state = TRANS_CONFIRM;
911 if (t->options & CTX_NDOF)
913 /* Cancel on pure NDOF transform */
914 t->state = TRANS_CANCEL;
918 /* Otherwise, just redraw, NDof input was cancelled */
923 if (t->options & CTX_NDOF)
925 /* Confirm on pure NDOF transform */
926 t->state = TRANS_CONFIRM;
936 t->redraw |= handleSnapping(t, event);
938 //arrows_move_cursor(event->type);
941 switch (event->type){
943 t->state = TRANS_CONFIRM;
947 t->modifiers &= ~MOD_CONSTRAINT_PLANE;
953 t->modifiers &= ~MOD_SNAP_GEARS;
954 /* no redraw on release modifier keys! this makes sure you can assign the 'grid' still
955 after releasing modifer key */
959 if ((t->flag & T_NO_CONSTRAINT)==0) {
960 t->modifiers &= ~MOD_CONSTRAINT_SELECT;
961 postSelectConstraint(t);
967 // if(WM_modal_tweak_exit(event, t->event_type))
968 //// if (t->options & CTX_TWEAK)
969 // t->state = TRANS_CONFIRM;
974 // Per transform event, if present
976 t->redraw |= t->handleEvent(t, event);
979 int calculateTransformCenter(bContext *C, wmEvent *event, int centerMode, float *vec)
981 TransInfo *t = MEM_callocN(sizeof(TransInfo), "TransInfo data");
984 t->state = TRANS_RUNNING;
986 t->options = CTX_NONE;
990 initTransInfo(C, t, NULL, event); // internal data, mouse, vectors
992 createTransData(C, t); // make TransData structs from selection
994 t->around = centerMode; // override userdefined mode
1004 // Copy center from constraint center. Transform center can be local
1005 VECCOPY(vec, t->con.center);
1010 /* aftertrans does insert ipos and action channels, and clears base flags, doesnt read transdata */
1011 special_aftertrans_update(t);
1024 static void drawArrow(ArrowDirection d, short offset, short length, short size)
1034 glVertex2s( offset, 0);
1035 glVertex2s( offset + length, 0);
1036 glVertex2s( offset + length, 0);
1037 glVertex2s( offset + length - size, -size);
1038 glVertex2s( offset + length, 0);
1039 glVertex2s( offset + length - size, size);
1048 glVertex2s( 0, offset);
1049 glVertex2s( 0, offset + length);
1050 glVertex2s( 0, offset + length);
1051 glVertex2s(-size, offset + length - size);
1052 glVertex2s( 0, offset + length);
1053 glVertex2s( size, offset + length - size);
1059 static void drawArrowHead(ArrowDirection d, short size)
1068 glVertex2s( -size, -size);
1070 glVertex2s( -size, size);
1078 glVertex2s(-size, -size);
1080 glVertex2s( size, -size);
1086 static void drawArc(float size, float angle_start, float angle_end, int segments)
1088 float delta = (angle_end - angle_start) / segments;
1091 glBegin(GL_LINE_STRIP);
1093 for( angle = angle_start; angle < angle_end; angle += delta)
1095 glVertex2f( cosf(angle) * size, sinf(angle) * size);
1097 glVertex2f( cosf(angle_end) * size, sinf(angle_end) * size);
1102 void drawHelpline(const struct bContext *C, TransInfo *t)
1104 if (t->helpline != HLP_NONE && !(t->flag & T_USES_MANIPULATOR))
1106 float vecrot[3], cent[2];
1108 VECCOPY(vecrot, t->center);
1109 if(t->flag & T_EDIT) {
1110 Object *ob= t->obedit;
1111 if(ob) Mat4MulVecfl(ob->obmat, vecrot);
1113 else if(t->flag & T_POSE) {
1114 Object *ob=t->poseobj;
1115 if(ob) Mat4MulVecfl(ob->obmat, vecrot);
1118 projectFloatView(t, vecrot, cent); // no overflow in extreme cases
1120 glDisable(GL_DEPTH_TEST);
1122 glMatrixMode(GL_PROJECTION);
1124 glMatrixMode(GL_MODELVIEW);
1127 ED_region_pixelspace(t->ar);
1132 UI_ThemeColor(TH_WIRE);
1135 glBegin(GL_LINE_STRIP);
1136 glVertex2sv(t->mval);
1140 glTranslatef(t->mval[0], t->mval[1], 0);
1141 glRotatef(-180 / M_PI * atan2f(cent[0] - t->mval[0], cent[1] - t->mval[1]), 0, 0, 1);
1145 drawArrow(UP, 5, 10, 5);
1146 drawArrow(DOWN, 5, 10, 5);
1150 UI_ThemeColor(TH_WIRE);
1152 glTranslatef(t->mval[0], t->mval[1], 0);
1155 drawArrow(RIGHT, 5, 10, 5);
1156 drawArrow(LEFT, 5, 10, 5);
1160 UI_ThemeColor(TH_WIRE);
1162 glTranslatef(t->mval[0], t->mval[1], 0);
1166 drawArrow(UP, 5, 10, 5);
1167 drawArrow(DOWN, 5, 10, 5);
1172 float dx = t->mval[0] - cent[0], dy = t->mval[1] - cent[1];
1173 float angle = atan2f(dy, dx);
1174 float dist = sqrtf(dx*dx + dy*dy);
1175 float delta_angle = MIN2(15 / dist, M_PI/4);
1176 float spacing_angle = MIN2(5 / dist, M_PI/12);
1177 UI_ThemeColor(TH_WIRE);
1180 glBegin(GL_LINE_STRIP);
1181 glVertex2sv(t->mval);
1185 glTranslatef(cent[0], cent[1], 0);
1189 drawArc(dist, angle - delta_angle, angle - spacing_angle, 10);
1190 drawArc(dist, angle + spacing_angle, angle + delta_angle, 10);
1194 glTranslatef(cosf(angle - delta_angle) * dist, sinf(angle - delta_angle) * dist, 0);
1195 glRotatef(180 / M_PI * (angle - delta_angle), 0, 0, 1);
1197 drawArrowHead(DOWN, 5);
1201 glTranslatef(cosf(angle + delta_angle) * dist, sinf(angle + delta_angle) * dist, 0);
1202 glRotatef(180 / M_PI * (angle + delta_angle), 0, 0, 1);
1204 drawArrowHead(UP, 5);
1211 char col[3], col2[3];
1212 UI_GetThemeColor3ubv(TH_GRID, col);
1214 glTranslatef(t->mval[0], t->mval[1], 0);
1218 UI_make_axis_color(col, col2, 'x');
1219 glColor3ubv((GLubyte *)col2);
1221 drawArrow(RIGHT, 5, 10, 5);
1222 drawArrow(LEFT, 5, 10, 5);
1224 UI_make_axis_color(col, col2, 'y');
1225 glColor3ubv((GLubyte *)col2);
1227 drawArrow(UP, 5, 10, 5);
1228 drawArrow(DOWN, 5, 10, 5);
1234 glMatrixMode(GL_PROJECTION);
1236 glMatrixMode(GL_MODELVIEW);
1239 glEnable(GL_DEPTH_TEST);
1243 void drawTransform(const struct bContext *C, struct ARegion *ar, void *arg)
1247 drawConstraint(C, t);
1248 drawPropCircle(C, t);
1253 void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
1255 ToolSettings *ts = CTX_data_tool_settings(C);
1256 int constraint_axis[3] = {0, 0, 0};
1257 int proportional = 0;
1259 if (t->flag & T_AUTOVALUES)
1261 RNA_float_set_array(op->ptr, "value", t->auto_values);
1265 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 (RNA_struct_find_property(op->ptr, "proportional"))
1283 RNA_enum_set(op->ptr, "proportional", proportional);
1284 RNA_enum_set(op->ptr, "proportional_editing_falloff", t->prop_mode);
1285 RNA_float_set(op->ptr, "proportional_size", t->prop_size);
1288 if (RNA_struct_find_property(op->ptr, "mirror"))
1290 RNA_boolean_set(op->ptr, "mirror", t->flag & T_MIRROR);
1293 if (RNA_struct_find_property(op->ptr, "constraint_axis"))
1295 RNA_enum_set(op->ptr, "constraint_orientation", t->current_orientation);
1297 if (t->con.mode & CON_APPLY)
1299 if (t->con.mode & CON_AXIS0) {
1300 constraint_axis[0] = 1;
1302 if (t->con.mode & CON_AXIS1) {
1303 constraint_axis[1] = 1;
1305 if (t->con.mode & CON_AXIS2) {
1306 constraint_axis[2] = 1;
1310 RNA_boolean_set_array(op->ptr, "constraint_axis", constraint_axis);
1313 // XXX If modal, save settings back in scene
1314 if (t->flag & T_MODAL)
1316 ts->prop_mode = t->prop_mode;
1317 ts->proportional = proportional;
1319 if(t->spacetype == SPACE_VIEW3D)
1321 View3D *v3d = t->view;
1323 v3d->twmode = t->current_orientation;
1328 int initTransform(bContext *C, TransInfo *t, wmOperator *op, wmEvent *event, int mode)
1332 /* added initialize, for external calls to set stuff in TransInfo, like undo string */
1334 t->state = TRANS_RUNNING;
1336 t->options = options;
1340 if (!initTransInfo(C, t, op, event)) // internal data, mouse, vectors
1345 if(t->spacetype == SPACE_VIEW3D)
1347 //calc_manipulator_stats(curarea);
1348 initTransformOrientation(C, t);
1350 t->draw_handle = ED_region_draw_cb_activate(t->ar->type, drawTransform, t, REGION_DRAW_POST);
1352 else if(t->spacetype == SPACE_IMAGE) {
1353 Mat3One(t->spacemtx);
1354 t->draw_handle = ED_region_draw_cb_activate(t->ar->type, drawTransform, t, REGION_DRAW_POST);
1357 Mat3One(t->spacemtx);
1359 createTransData(C, t); // make TransData structs from selection
1361 if (t->total == 0) {
1366 initSnapping(t, op); // Initialize snapping data AFTER mode flags
1368 /* EVIL! posemode code can switch translation to rotate when 1 bone is selected. will be removed (ton) */
1369 /* EVIL2: we gave as argument also texture space context bit... was cleared */
1370 /* EVIL3: extend mode for animation editors also switches modes... but is best way to avoid duplicate code */
1373 calculatePropRatio(t);
1376 initMouseInput(t, &t->mouse, t->center2d, t->imval);
1379 case TFM_TRANSLATION:
1397 case TFM_SHRINKFATTEN:
1398 initShrinkFatten(t);
1403 case TFM_CURVE_SHRINKFATTEN:
1404 initCurveShrinkFatten(t);
1416 { /* used for both B-Bone width (bonesize) as for deform-dist (envelope) */
1417 bArmature *arm= t->poseobj->data;
1418 if(arm->drawtype==ARM_ENVELOPE)
1419 initBoneEnvelope(t);
1424 case TFM_BONE_ENVELOPE:
1425 initBoneEnvelope(t);
1430 case TFM_TIME_TRANSLATE:
1431 initTimeTranslate(t);
1433 case TFM_TIME_SLIDE:
1436 case TFM_TIME_SCALE:
1439 case TFM_TIME_EXTEND:
1440 /* now that transdata has been made, do like for TFM_TIME_TRANSLATE (for most Animation
1441 * Editors because they have only 1D transforms for time values) or TFM_TRANSLATION
1442 * (for Graph/NLA Editors only since they uses 'standard' transforms to get 2D movement)
1443 * depending on which editor this was called from
1445 if ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)
1448 initTimeTranslate(t);
1467 /* overwrite initial values if operator supplied a non-null vector */
1468 if (RNA_property_is_set(op->ptr, "value"))
1471 RNA_float_get_array(op->ptr, "value", values);
1472 QUATCOPY(t->values, values);
1473 QUATCOPY(t->auto_values, values);
1474 t->flag |= T_AUTOVALUES;
1477 /* Constraint init from operator */
1478 if (RNA_struct_find_property(op->ptr, "constraint_axis") && RNA_property_is_set(op->ptr, "constraint_axis"))
1480 int constraint_axis[3];
1482 RNA_boolean_get_array(op->ptr, "constraint_axis", constraint_axis);
1484 if (constraint_axis[0] || constraint_axis[1] || constraint_axis[2])
1486 t->con.mode |= CON_APPLY;
1488 if (constraint_axis[0]) {
1489 t->con.mode |= CON_AXIS0;
1491 if (constraint_axis[1]) {
1492 t->con.mode |= CON_AXIS1;
1494 if (constraint_axis[2]) {
1495 t->con.mode |= CON_AXIS2;
1498 setUserConstraint(t, t->con.mode, "%s");
1505 void transformApply(bContext *C, TransInfo *t)
1509 if (t->modifiers & MOD_CONSTRAINT_SELECT)
1510 t->con.mode |= CON_SELECT;
1512 selectConstraint(t);
1514 t->transform(t, t->mval); // calls recalcData()
1515 viewRedrawForce(C, t);
1520 /* If auto confirm is on, break after one pass */
1521 if (t->options & CTX_AUTOCONFIRM)
1523 t->state = TRANS_CONFIRM;
1526 if (BKE_ptcache_get_continue_physics())
1529 //do_screenhandlers(G.curscreen);
1534 int transformEnd(bContext *C, TransInfo *t)
1536 int exit_code = OPERATOR_RUNNING_MODAL;
1538 if (t->state != TRANS_RUNNING)
1540 /* handle restoring objects */
1541 if(t->state == TRANS_CANCEL)
1543 exit_code = OPERATOR_CANCELLED;
1544 restoreTransObjects(t); // calls recalcData()
1548 exit_code = OPERATOR_FINISHED;
1554 /* aftertrans does insert keyframes, and clears base flags, doesnt read transdata */
1555 special_aftertrans_update(t);
1557 /* send events out for redraws */
1560 /* Undo as last, certainly after special_trans_update! */
1562 if(t->state == TRANS_CANCEL) {
1563 // if(t->undostr) ED_undo_push(C, t->undostr);
1566 // if(t->undostr) ED_undo_push(C, t->undostr);
1567 // else ED_undo_push(C, transform_to_undostr(t));
1571 viewRedrawForce(C, t);
1577 /* ************************** TRANSFORM LOCKS **************************** */
1579 static void protectedTransBits(short protectflag, float *vec)
1581 if(protectflag & OB_LOCK_LOCX)
1583 if(protectflag & OB_LOCK_LOCY)
1585 if(protectflag & OB_LOCK_LOCZ)
1589 static void protectedSizeBits(short protectflag, float *size)
1591 if(protectflag & OB_LOCK_SCALEX)
1593 if(protectflag & OB_LOCK_SCALEY)
1595 if(protectflag & OB_LOCK_SCALEZ)
1599 static void protectedRotateBits(short protectflag, float *eul, float *oldeul)
1601 if(protectflag & OB_LOCK_ROTX)
1603 if(protectflag & OB_LOCK_ROTY)
1605 if(protectflag & OB_LOCK_ROTZ)
1609 static void protectedQuaternionBits(short protectflag, float *quat, float *oldquat)
1611 /* quaternions get limited with euler... */
1612 /* this function only does the delta rotation */
1615 float eul[3], oldeul[3], quat1[4];
1617 QUATCOPY(quat1, quat);
1618 QuatToEul(quat, eul);
1619 QuatToEul(oldquat, oldeul);
1621 if(protectflag & OB_LOCK_ROTX)
1623 if(protectflag & OB_LOCK_ROTY)
1625 if(protectflag & OB_LOCK_ROTZ)
1628 EulToQuat(eul, quat);
1629 /* quaternions flip w sign to accumulate rotations correctly */
1630 if( (quat1[0]<0.0f && quat[0]>0.0f) || (quat1[0]>0.0f && quat[0]<0.0f) ) {
1631 QuatMulf(quat, -1.0f);
1636 /* ******************* TRANSFORM LIMITS ********************** */
1638 static void constraintTransLim(TransInfo *t, TransData *td)
1641 bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_LOCLIMIT);
1645 /* Make a temporary bConstraintOb for using these limit constraints
1646 * - they only care that cob->matrix is correctly set ;-)
1647 * - current space should be local
1649 memset(&cob, 0, sizeof(bConstraintOb));
1650 Mat4One(cob.matrix);
1652 TransDataIpokey *tdi= td->tdi;
1653 cob.matrix[3][0]= tdi->locx[0];
1654 cob.matrix[3][1]= tdi->locy[0];
1655 cob.matrix[3][2]= tdi->locz[0];
1658 VECCOPY(cob.matrix[3], td->loc);
1661 /* Evaluate valid constraints */
1662 for (con= td->con; con; con= con->next) {
1665 /* only consider constraint if enabled */
1666 if (con->flag & CONSTRAINT_DISABLE) continue;
1667 if (con->enforce == 0.0f) continue;
1669 /* only use it if it's tagged for this purpose (and the right type) */
1670 if (con->type == CONSTRAINT_TYPE_LOCLIMIT) {
1671 bLocLimitConstraint *data= con->data;
1673 if ((data->flag2 & LIMIT_TRANSFORM)==0)
1676 /* do space conversions */
1677 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1678 /* just multiply by td->mtx (this should be ok) */
1679 Mat4CpyMat4(tmat, cob.matrix);
1680 Mat4MulMat34(cob.matrix, td->mtx, tmat);
1682 else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) {
1683 /* skip... incompatable spacetype */
1688 cti->evaluate_constraint(con, &cob, NULL);
1690 /* convert spaces again */
1691 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1692 /* just multiply by td->mtx (this should be ok) */
1693 Mat4CpyMat4(tmat, cob.matrix);
1694 Mat4MulMat34(cob.matrix, td->smtx, tmat);
1699 /* copy results from cob->matrix */
1701 TransDataIpokey *tdi= td->tdi;
1702 tdi->locx[0]= cob.matrix[3][0];
1703 tdi->locy[0]= cob.matrix[3][1];
1704 tdi->locz[0]= cob.matrix[3][2];
1707 VECCOPY(td->loc, cob.matrix[3]);
1712 static void constraintRotLim(TransInfo *t, TransData *td)
1715 bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_ROTLIMIT);
1719 /* Make a temporary bConstraintOb for using these limit constraints
1720 * - they only care that cob->matrix is correctly set ;-)
1721 * - current space should be local
1723 memset(&cob, 0, sizeof(bConstraintOb));
1724 if (td->flag & TD_USEQUAT) {
1727 QuatToMat4(td->ext->quat, cob.matrix);
1732 /* ipo-keys eulers */
1733 TransDataIpokey *tdi= td->tdi;
1736 eul[0]= tdi->rotx[0];
1737 eul[1]= tdi->roty[0];
1738 eul[2]= tdi->rotz[0];
1740 EulToMat4(eul, cob.matrix);
1745 EulToMat4(td->ext->rot, cob.matrix);
1750 /* Evaluate valid constraints */
1751 for (con= td->con; con; con= con->next) {
1752 /* only consider constraint if enabled */
1753 if (con->flag & CONSTRAINT_DISABLE) continue;
1754 if (con->enforce == 0.0f) continue;
1756 /* we're only interested in Limit-Rotation constraints */
1757 if (con->type == CONSTRAINT_TYPE_ROTLIMIT) {
1758 bRotLimitConstraint *data= con->data;
1761 /* only use it if it's tagged for this purpose */
1762 if ((data->flag2 & LIMIT_TRANSFORM)==0)
1765 /* do space conversions */
1766 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1767 /* just multiply by td->mtx (this should be ok) */
1768 Mat4CpyMat4(tmat, cob.matrix);
1769 Mat4MulMat34(cob.matrix, td->mtx, tmat);
1771 else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) {
1772 /* skip... incompatable spacetype */
1777 cti->evaluate_constraint(con, &cob, NULL);
1779 /* convert spaces again */
1780 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1781 /* just multiply by td->mtx (this should be ok) */
1782 Mat4CpyMat4(tmat, cob.matrix);
1783 Mat4MulMat34(cob.matrix, td->smtx, tmat);
1788 /* copy results from cob->matrix */
1789 if (td->flag & TD_USEQUAT) {
1791 Mat4ToQuat(cob.matrix, td->ext->quat);
1794 /* ipo-keys eulers */
1795 TransDataIpokey *tdi= td->tdi;
1798 Mat4ToEul(cob.matrix, eul);
1800 tdi->rotx[0]= eul[0];
1801 tdi->roty[0]= eul[1];
1802 tdi->rotz[0]= eul[2];
1806 Mat4ToEul(cob.matrix, td->ext->rot);
1811 static void constraintSizeLim(TransInfo *t, TransData *td)
1813 if (td->con && td->ext) {
1814 bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_SIZELIMIT);
1818 /* Make a temporary bConstraintOb for using these limit constraints
1819 * - they only care that cob->matrix is correctly set ;-)
1820 * - current space should be local
1822 memset(&cob, 0, sizeof(bConstraintOb));
1824 TransDataIpokey *tdi= td->tdi;
1827 size[0]= tdi->sizex[0];
1828 size[1]= tdi->sizey[0];
1829 size[2]= tdi->sizez[0];
1830 SizeToMat4(size, cob.matrix);
1832 else if ((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)) {
1833 /* scale val and reset size */
1834 return; // TODO: fix this case
1837 /* Reset val if SINGLESIZE but using a constraint */
1838 if (td->flag & TD_SINGLESIZE)
1841 SizeToMat4(td->ext->size, cob.matrix);
1844 /* Evaluate valid constraints */
1845 for (con= td->con; con; con= con->next) {
1846 /* only consider constraint if enabled */
1847 if (con->flag & CONSTRAINT_DISABLE) continue;
1848 if (con->enforce == 0.0f) continue;
1850 /* we're only interested in Limit-Scale constraints */
1851 if (con->type == CONSTRAINT_TYPE_SIZELIMIT) {
1852 bSizeLimitConstraint *data= con->data;
1855 /* only use it if it's tagged for this purpose */
1856 if ((data->flag2 & LIMIT_TRANSFORM)==0)
1859 /* do space conversions */
1860 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1861 /* just multiply by td->mtx (this should be ok) */
1862 Mat4CpyMat4(tmat, cob.matrix);
1863 Mat4MulMat34(cob.matrix, td->mtx, tmat);
1865 else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) {
1866 /* skip... incompatable spacetype */
1871 cti->evaluate_constraint(con, &cob, NULL);
1873 /* convert spaces again */
1874 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1875 /* just multiply by td->mtx (this should be ok) */
1876 Mat4CpyMat4(tmat, cob.matrix);
1877 Mat4MulMat34(cob.matrix, td->smtx, tmat);
1882 /* copy results from cob->matrix */
1884 TransDataIpokey *tdi= td->tdi;
1887 Mat4ToSize(cob.matrix, size);
1889 tdi->sizex[0]= size[0];
1890 tdi->sizey[0]= size[1];
1891 tdi->sizez[0]= size[2];
1893 else if ((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)) {
1894 /* scale val and reset size */
1895 return; // TODO: fix this case
1898 /* Reset val if SINGLESIZE but using a constraint */
1899 if (td->flag & TD_SINGLESIZE)
1902 Mat4ToSize(cob.matrix, td->ext->size);
1907 /* ************************** WARP *************************** */
1909 void initWarp(TransInfo *t)
1911 float max[3], min[3];
1915 t->transform = Warp;
1916 t->handleEvent = handleEventWarp;
1918 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_RATIO);
1926 t->flag |= T_NO_CONSTRAINT;
1928 /* we need min/max in view space */
1929 for(i = 0; i < t->total; i++) {
1931 VECCOPY(center, t->data[i].center);
1932 Mat3MulVecfl(t->data[i].mtx, center);
1933 Mat4MulVecfl(t->viewmat, center);
1934 VecSubf(center, center, t->viewmat[3]);
1936 MinMax3(min, max, center);
1938 VECCOPY(max, center);
1939 VECCOPY(min, center);
1943 t->center[0]= (min[0]+max[0])/2.0f;
1944 t->center[1]= (min[1]+max[1])/2.0f;
1945 t->center[2]= (min[2]+max[2])/2.0f;
1947 if (max[0] == min[0]) max[0] += 0.1; /* not optimal, but flipping is better than invalid garbage (i.e. division by zero!) */
1948 t->val= (max[0]-min[0])/2.0f; /* t->val is X dimension projected boundbox */
1951 int handleEventWarp(TransInfo *t, wmEvent *event)
1955 if (event->type == MIDDLEMOUSE && event->val==KM_PRESS)
1957 // Use customData pointer to signal warp direction
1958 if (t->customData == 0)
1959 t->customData = (void*)1;
1969 int Warp(TransInfo *t, short mval[2])
1971 TransData *td = t->data;
1972 float vec[3], circumfac, dist, phi0, co, si, *curs, cursor[3], gcursor[3];
1976 curs= give_cursor(t->scene, t->view);
1978 * gcursor is the one used for helpline.
1979 * It has to be in the same space as the drawing loop
1980 * (that means it needs to be in the object's space when in edit mode and
1981 * in global space in object mode)
1983 * cursor is used for calculations.
1984 * It needs to be in view space, but we need to take object's offset
1985 * into account if in Edit mode.
1987 VECCOPY(cursor, curs);
1988 VECCOPY(gcursor, cursor);
1989 if (t->flag & T_EDIT) {
1990 VecSubf(cursor, cursor, t->obedit->obmat[3]);
1991 VecSubf(gcursor, gcursor, t->obedit->obmat[3]);
1992 Mat3MulVecfl(t->data->smtx, gcursor);
1994 Mat4MulVecfl(t->viewmat, cursor);
1995 VecSubf(cursor, cursor, t->viewmat[3]);
1997 /* amount of degrees for warp */
1998 circumfac = 360.0f * t->values[0];
2000 if (t->customData) /* non-null value indicates reversed input */
2005 snapGrid(t, &circumfac);
2006 applyNumInput(&t->num, &circumfac);
2008 /* header print for NumInput */
2009 if (hasNumInput(&t->num)) {
2012 outputNumInput(&(t->num), c);
2014 sprintf(str, "Warp: %s", c);
2017 /* default header print */
2018 sprintf(str, "Warp: %.3f", circumfac);
2021 circumfac*= (float)(-M_PI/360.0);
2023 for(i = 0; i < t->total; i++, td++) {
2025 if (td->flag & TD_NOACTION)
2028 if (td->flag & TD_SKIP)
2031 /* translate point to center, rotate in such a way that outline==distance */
2032 VECCOPY(vec, td->iloc);
2033 Mat3MulVecfl(td->mtx, vec);
2034 Mat4MulVecfl(t->viewmat, vec);
2035 VecSubf(vec, vec, t->viewmat[3]);
2037 dist= vec[0]-cursor[0];
2039 /* t->val is X dimension projected boundbox */
2040 phi0= (circumfac*dist/t->val);
2042 vec[1]= (vec[1]-cursor[1]);
2044 co= (float)cos(phi0);
2045 si= (float)sin(phi0);
2046 loc[0]= -si*vec[1]+cursor[0];
2047 loc[1]= co*vec[1]+cursor[1];
2050 Mat4MulVecfl(t->viewinv, loc);
2051 VecSubf(loc, loc, t->viewinv[3]);
2052 Mat3MulVecfl(td->smtx, loc);
2054 VecSubf(loc, loc, td->iloc);
2055 VecMulf(loc, td->factor);
2056 VecAddf(td->loc, td->iloc, loc);
2061 ED_area_headerprint(t->sa, str);
2066 /* ************************** SHEAR *************************** */
2068 void initShear(TransInfo *t)
2070 t->mode = TFM_SHEAR;
2071 t->transform = Shear;
2072 t->handleEvent = handleEventShear;
2074 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_ABSOLUTE);
2080 t->snap[2] = t->snap[1] * 0.1f;
2082 t->flag |= T_NO_CONSTRAINT;
2085 int handleEventShear(TransInfo *t, wmEvent *event)
2089 if (event->type == MIDDLEMOUSE && event->val==KM_PRESS)
2091 // Use customData pointer to signal Shear direction
2092 if (t->customData == 0)
2094 initMouseInputMode(t, &t->mouse, INPUT_VERTICAL_ABSOLUTE);
2095 t->customData = (void*)1;
2099 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_ABSOLUTE);
2110 int Shear(TransInfo *t, short mval[2])
2112 TransData *td = t->data;
2114 float smat[3][3], tmat[3][3], totmat[3][3], persmat[3][3], persinv[3][3];
2119 Mat3CpyMat4(persmat, t->viewmat);
2120 Mat3Inv(persinv, persmat);
2122 value = 0.05f * t->values[0];
2124 snapGrid(t, &value);
2126 applyNumInput(&t->num, &value);
2128 /* header print for NumInput */
2129 if (hasNumInput(&t->num)) {
2132 outputNumInput(&(t->num), c);
2134 sprintf(str, "Shear: %s %s", c, t->proptext);
2137 /* default header print */
2138 sprintf(str, "Shear: %.3f %s", value, t->proptext);
2143 // Custom data signals shear direction
2144 if (t->customData == 0)
2149 Mat3MulMat3(tmat, smat, persmat);
2150 Mat3MulMat3(totmat, persinv, tmat);
2152 for(i = 0 ; i < t->total; i++, td++) {
2153 if (td->flag & TD_NOACTION)
2156 if (td->flag & TD_SKIP)
2161 Mat3MulMat3(mat3, totmat, td->mtx);
2162 Mat3MulMat3(tmat, td->smtx, mat3);
2165 Mat3CpyMat3(tmat, totmat);
2167 VecSubf(vec, td->center, t->center);
2169 Mat3MulVecfl(tmat, vec);
2171 VecAddf(vec, vec, t->center);
2172 VecSubf(vec, vec, td->center);
2174 VecMulf(vec, td->factor);
2176 VecAddf(td->loc, td->iloc, vec);
2181 ED_area_headerprint(t->sa, str);
2186 /* ************************** RESIZE *************************** */
2188 void initResize(TransInfo *t)
2190 t->mode = TFM_RESIZE;
2191 t->transform = Resize;
2193 initMouseInputMode(t, &t->mouse, INPUT_SPRING_FLIP);
2195 t->flag |= T_NULL_ONE;
2196 t->num.flag |= NUM_NULL_ONE;
2197 t->num.flag |= NUM_AFFECT_ALL;
2199 t->flag |= T_NO_ZERO;
2200 t->num.flag |= NUM_NO_ZERO;
2207 t->snap[2] = t->snap[1] * 0.1f;
2210 static void headerResize(TransInfo *t, float vec[3], char *str) {
2212 if (hasNumInput(&t->num)) {
2213 outputNumInput(&(t->num), tvec);
2216 sprintf(&tvec[0], "%.4f", vec[0]);
2217 sprintf(&tvec[20], "%.4f", vec[1]);
2218 sprintf(&tvec[40], "%.4f", vec[2]);
2221 if (t->con.mode & CON_APPLY) {
2222 switch(t->num.idx_max) {
2224 sprintf(str, "Scale: %s%s %s", &tvec[0], t->con.text, t->proptext);
2227 sprintf(str, "Scale: %s : %s%s %s", &tvec[0], &tvec[20], t->con.text, t->proptext);
2230 sprintf(str, "Scale: %s : %s : %s%s %s", &tvec[0], &tvec[20], &tvec[40], t->con.text, t->proptext);
2234 if (t->flag & T_2D_EDIT)
2235 sprintf(str, "Scale X: %s Y: %s%s %s", &tvec[0], &tvec[20], t->con.text, t->proptext);
2237 sprintf(str, "Scale X: %s Y: %s Z: %s%s %s", &tvec[0], &tvec[20], &tvec[40], t->con.text, t->proptext);
2241 #define SIGN(a) (a<-FLT_EPSILON?1:a>FLT_EPSILON?2:3)
2242 #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)
2244 /* smat is reference matrix, only scaled */
2245 static void TransMat3ToSize( float mat[][3], float smat[][3], float *size)
2249 VecCopyf(vec, mat[0]);
2250 size[0]= Normalize(vec);
2251 VecCopyf(vec, mat[1]);
2252 size[1]= Normalize(vec);
2253 VecCopyf(vec, mat[2]);
2254 size[2]= Normalize(vec);
2256 /* first tried with dotproduct... but the sign flip is crucial */
2257 if( VECSIGNFLIP(mat[0], smat[0]) ) size[0]= -size[0];
2258 if( VECSIGNFLIP(mat[1], smat[1]) ) size[1]= -size[1];
2259 if( VECSIGNFLIP(mat[2], smat[2]) ) size[2]= -size[2];
2263 static void ElementResize(TransInfo *t, TransData *td, float mat[3][3]) {
2264 float tmat[3][3], smat[3][3], center[3];
2267 if (t->flag & T_EDIT) {
2268 Mat3MulMat3(smat, mat, td->mtx);
2269 Mat3MulMat3(tmat, td->smtx, smat);
2272 Mat3CpyMat3(tmat, mat);
2275 if (t->con.applySize) {
2276 t->con.applySize(t, td, tmat);
2279 /* local constraint shouldn't alter center */
2280 if (t->around == V3D_LOCAL) {
2281 if (t->flag & T_OBJECT) {
2282 VECCOPY(center, td->center);
2284 else if (t->flag & T_EDIT) {
2286 if(t->around==V3D_LOCAL && (t->settings->selectmode & SCE_SELECT_FACE)) {
2287 VECCOPY(center, td->center);
2290 VECCOPY(center, t->center);
2294 VECCOPY(center, t->center);
2298 VECCOPY(center, t->center);
2304 if (t->flag & (T_OBJECT|T_TEXTURE|T_POSE)) {
2305 float obsizemat[3][3];
2306 // Reorient the size mat to fit the oriented object.
2307 Mat3MulMat3(obsizemat, tmat, td->axismtx);
2308 //printmatrix3("obsizemat", obsizemat);
2309 TransMat3ToSize(obsizemat, td->axismtx, fsize);
2310 //printvecf("fsize", fsize);
2313 Mat3ToSize(tmat, fsize);
2316 protectedSizeBits(td->protectflag, fsize);
2318 if ((t->flag & T_V3D_ALIGN)==0) { // align mode doesn't resize objects itself
2319 /* handle ipokeys? */
2321 TransDataIpokey *tdi= td->tdi;
2322 /* calculate delta size (equal for size and dsize) */
2324 vec[0]= (tdi->oldsize[0])*(fsize[0] -1.0f) * td->factor;
2325 vec[1]= (tdi->oldsize[1])*(fsize[1] -1.0f) * td->factor;
2326 vec[2]= (tdi->oldsize[2])*(fsize[2] -1.0f) * td->factor;
2328 add_tdi_poin(tdi->sizex, tdi->oldsize, vec[0]);
2329 add_tdi_poin(tdi->sizey, tdi->oldsize+1, vec[1]);
2330 add_tdi_poin(tdi->sizez, tdi->oldsize+2, vec[2]);
2333 else if((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)){
2334 /* scale val and reset size */
2335 *td->val = td->ival * fsize[0] * td->factor;
2337 td->ext->size[0] = td->ext->isize[0];
2338 td->ext->size[1] = td->ext->isize[1];
2339 td->ext->size[2] = td->ext->isize[2];
2342 /* Reset val if SINGLESIZE but using a constraint */
2343 if (td->flag & TD_SINGLESIZE)
2344 *td->val = td->ival;
2346 td->ext->size[0] = td->ext->isize[0] * (fsize[0]) * td->factor;
2347 td->ext->size[1] = td->ext->isize[1] * (fsize[1]) * td->factor;
2348 td->ext->size[2] = td->ext->isize[2] * (fsize[2]) * td->factor;
2352 constraintSizeLim(t, td);
2355 /* For individual element center, Editmode need to use iloc */
2356 if (t->flag & T_POINTS)
2357 VecSubf(vec, td->iloc, center);
2359 VecSubf(vec, td->center, center);
2361 Mat3MulVecfl(tmat, vec);
2363 VecAddf(vec, vec, center);
2364 if (t->flag & T_POINTS)
2365 VecSubf(vec, vec, td->iloc);
2367 VecSubf(vec, vec, td->center);
2369 VecMulf(vec, td->factor);
2371 if (t->flag & (T_OBJECT|T_POSE)) {
2372 Mat3MulVecfl(td->smtx, vec);
2375 protectedTransBits(td->protectflag, vec);
2378 TransDataIpokey *tdi= td->tdi;
2379 add_tdi_poin(tdi->locx, tdi->oldloc, vec[0]);
2380 add_tdi_poin(tdi->locy, tdi->oldloc+1, vec[1]);
2381 add_tdi_poin(tdi->locz, tdi->oldloc+2, vec[2]);
2383 else VecAddf(td->loc, td->iloc, vec);
2385 constraintTransLim(t, td);
2388 int Resize(TransInfo *t, short mval[2])
2391 float size[3], mat[3][3];
2396 /* for manipulator, center handle, the scaling can't be done relative to center */
2397 if( (t->flag & T_USES_MANIPULATOR) && t->con.mode==0)
2399 ratio = 1.0f - ((t->imval[0] - mval[0]) + (t->imval[1] - mval[1]))/100.0f;
2403 ratio = t->values[0];
2406 size[0] = size[1] = size[2] = ratio;
2410 if (hasNumInput(&t->num)) {
2411 applyNumInput(&t->num, size);
2412 constraintNumInput(t, size);
2415 applySnapping(t, size);
2417 if (t->flag & T_AUTOVALUES)
2419 VECCOPY(size, t->auto_values);
2422 VECCOPY(t->values, size);
2424 SizeToMat3(size, mat);
2426 if (t->con.applySize) {
2427 t->con.applySize(t, NULL, mat);
2430 Mat3CpyMat3(t->mat, mat); // used in manipulator
2432 headerResize(t, size, str);
2434 for(i = 0, td=t->data; i < t->total; i++, td++) {
2435 if (td->flag & TD_NOACTION)
2438 if (td->flag & TD_SKIP)
2441 ElementResize(t, td, mat);
2444 /* evil hack - redo resize if cliping needed */
2445 if (t->flag & T_CLIP_UV && clipUVTransform(t, size, 1)) {
2446 SizeToMat3(size, mat);
2448 if (t->con.applySize)
2449 t->con.applySize(t, NULL, mat);
2451 for(i = 0, td=t->data; i < t->total; i++, td++)
2452 ElementResize(t, td, mat);
2457 ED_area_headerprint(t->sa, str);
2462 /* ************************** TOSPHERE *************************** */
2464 void initToSphere(TransInfo *t)
2466 TransData *td = t->data;
2469 t->mode = TFM_TOSPHERE;
2470 t->transform = ToSphere;
2472 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_RATIO);
2478 t->snap[2] = t->snap[1] * 0.1f;
2480 t->num.flag |= NUM_NULL_ONE | NUM_NO_NEGATIVE;
2481 t->flag |= T_NO_CONSTRAINT;
2483 // Calculate average radius
2484 for(i = 0 ; i < t->total; i++, td++) {
2485 t->val += VecLenf(t->center, td->iloc);
2488 t->val /= (float)t->total;
2491 int ToSphere(TransInfo *t, short mval[2])
2494 float ratio, radius;
2497 TransData *td = t->data;
2499 ratio = t->values[0];
2501 snapGrid(t, &ratio);
2503 applyNumInput(&t->num, &ratio);
2510 /* header print for NumInput */
2511 if (hasNumInput(&t->num)) {
2514 outputNumInput(&(t->num), c);
2516 sprintf(str, "To Sphere: %s %s", c, t->proptext);
2519 /* default header print */
2520 sprintf(str, "To Sphere: %.4f %s", ratio, t->proptext);
2524 for(i = 0 ; i < t->total; i++, td++) {
2526 if (td->flag & TD_NOACTION)
2529 if (td->flag & TD_SKIP)
2532 VecSubf(vec, td->iloc, t->center);
2534 radius = Normalize(vec);
2536 tratio = ratio * td->factor;
2538 VecMulf(vec, radius * (1.0f - tratio) + t->val * tratio);
2540 VecAddf(td->loc, t->center, vec);
2546 ED_area_headerprint(t->sa, str);
2551 /* ************************** ROTATION *************************** */
2554 void initRotation(TransInfo *t)
2556 t->mode = TFM_ROTATION;
2557 t->transform = Rotation;
2559 initMouseInputMode(t, &t->mouse, INPUT_ANGLE);
2562 /* Scale down and flip input for rotation */
2563 t->ndof.factor[0] = -0.2f;
2568 t->snap[1] = (float)((5.0/180)*M_PI);
2569 t->snap[2] = t->snap[1] * 0.2f;
2571 if (t->flag & T_2D_EDIT)
2572 t->flag |= T_NO_CONSTRAINT;
2575 static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short around) {
2576 float vec[3], totmat[3][3], smat[3][3];
2577 float eul[3], fmat[3][3], quat[4];
2578 float *center = t->center;
2580 /* local constraint shouldn't alter center */
2581 if (around == V3D_LOCAL) {
2582 if (t->flag & (T_OBJECT|T_POSE)) {
2583 center = td->center;
2586 /* !TODO! Make this if not rely on G */
2587 if(around==V3D_LOCAL && (t->settings->selectmode & SCE_SELECT_FACE)) {
2588 center = td->center;
2593 if (t->flag & T_POINTS) {
2594 Mat3MulMat3(totmat, mat, td->mtx);
2595 Mat3MulMat3(smat, td->smtx, totmat);
2597 VecSubf(vec, td->iloc, center);
2598 Mat3MulVecfl(smat, vec);
2600 VecAddf(td->loc, vec, center);
2602 VecSubf(vec,td->loc,td->iloc);
2603 protectedTransBits(td->protectflag, vec);
2604 VecAddf(td->loc, td->iloc, vec);
2606 if(td->flag & TD_USEQUAT) {
2607 Mat3MulSerie(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0);
2608 Mat3ToQuat(fmat, quat); // Actual transform
2611 QuatMul(td->ext->quat, quat, td->ext->iquat);
2613 /* is there a reason not to have this here? -jahka */
2614 protectedQuaternionBits(td->protectflag, td->ext->quat, td->ext->iquat);
2621 * This is some VERY ugly special case to deal with pose mode.
2623 * The problem is that mtx and smtx include each bone orientation.
2625 * That is needed to rotate each bone properly, HOWEVER, to calculate
2626 * the translation component, we only need the actual armature object's
2627 * matrix (and inverse). That is not all though. Once the proper translation
2628 * has been computed, it has to be converted back into the bone's space.
2630 else if (t->flag & T_POSE) {
2631 float pmtx[3][3], imtx[3][3];
2633 // Extract and invert armature object matrix
2634 Mat3CpyMat4(pmtx, t->poseobj->obmat);
2635 Mat3Inv(imtx, pmtx);
2637 if ((td->flag & TD_NO_LOC) == 0)
2639 VecSubf(vec, td->center, center);
2641 Mat3MulVecfl(pmtx, vec); // To Global space
2642 Mat3MulVecfl(mat, vec); // Applying rotation
2643 Mat3MulVecfl(imtx, vec); // To Local space
2645 VecAddf(vec, vec, center);
2646 /* vec now is the location where the object has to be */
2648 VecSubf(vec, vec, td->center); // Translation needed from the initial location
2650 Mat3MulVecfl(pmtx, vec); // To Global space
2651 Mat3MulVecfl(td->smtx, vec);// To Pose space
2653 protectedTransBits(td->protectflag, vec);
2655 VecAddf(td->loc, td->iloc, vec);
2657 constraintTransLim(t, td);
2661 if ((t->flag & T_V3D_ALIGN)==0) { // align mode doesn't rotate objects itself
2662 /* euler or quaternion? */
2663 if (td->flag & TD_USEQUAT) {
2664 Mat3MulSerie(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0);
2666 Mat3ToQuat(fmat, quat); // Actual transform
2668 QuatMul(td->ext->quat, quat, td->ext->iquat);
2669 /* this function works on end result */
2670 protectedQuaternionBits(td->protectflag, td->ext->quat, td->ext->iquat);
2675 Mat3MulMat3(totmat, mat, td->mtx);
2676 Mat3MulMat3(smat, td->smtx, totmat);
2678 /* calculate the total rotatation in eulers */
2679 VECCOPY(eul, td->ext->irot);
2680 EulToMat3(eul, eulmat);
2682 /* mat = transform, obmat = bone rotation */
2683 Mat3MulMat3(fmat, smat, eulmat);
2685 Mat3ToCompatibleEul(fmat, eul, td->ext->rot);
2687 /* and apply (to end result only) */
2688 protectedRotateBits(td->protectflag, eul, td->ext->irot);
2689 VECCOPY(td->ext->rot, eul);
2692 constraintRotLim(t, td);
2696 if ((td->flag & TD_NO_LOC) == 0)
2699 VecSubf(vec, td->center, center);
2700 Mat3MulVecfl(mat, vec);
2701 VecAddf(vec, vec, center);
2702 /* vec now is the location where the object has to be */
2703 VecSubf(vec, vec, td->center);
2704 Mat3MulVecfl(td->smtx, vec);
2706 protectedTransBits(td->protectflag, vec);
2709 TransDataIpokey *tdi= td->tdi;
2710 add_tdi_poin(tdi->locx, tdi->oldloc, vec[0]);
2711 add_tdi_poin(tdi->locy, tdi->oldloc+1, vec[1]);
2712 add_tdi_poin(tdi->locz, tdi->oldloc+2, vec[2]);
2714 else VecAddf(td->loc, td->iloc, vec);
2718 constraintTransLim(t, td);
2721 if ((t->flag & T_V3D_ALIGN)==0) { // align mode doesn't rotate objects itself
2722 /* euler or quaternion? */
2723 if (td->flag & TD_USEQUAT) {
2724 Mat3MulSerie(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0);
2725 Mat3ToQuat(fmat, quat); // Actual transform
2727 QuatMul(td->ext->quat, quat, td->ext->iquat);
2728 /* this function works on end result */
2729 protectedQuaternionBits(td->protectflag, td->ext->quat, td->ext->iquat);
2734 /* are there ipo keys? */
2736 TransDataIpokey *tdi= td->tdi;
2737 float current_rot[3];
2740 /* current IPO value for compatible euler */
2741 current_rot[0] = (tdi->rotx) ? tdi->rotx[0] : 0.0f;
2742 current_rot[1] = (tdi->roty) ? tdi->roty[0] : 0.0f;
2743 current_rot[2] = (tdi->rotz) ? tdi->rotz[0] : 0.0f;
2744 VecMulf(current_rot, (float)(M_PI_2 / 9.0));
2746 /* calculate the total rotatation in eulers */
2747 VecAddf(eul, td->ext->irot, td->ext->drot);
2748 EulToMat3(eul, obmat);
2749 /* mat = transform, obmat = object rotation */
2750 Mat3MulMat3(fmat, mat, obmat);
2752 Mat3ToCompatibleEul(fmat, eul, current_rot);
2754 /* correct back for delta rot */
2755 if(tdi->flag & TOB_IPODROT) {
2756 VecSubf(rot, eul, td->ext->irot);
2759 VecSubf(rot, eul, td->ext->drot);
2762 VecMulf(rot, (float)(9.0/M_PI_2));
2763 VecSubf(rot, rot, tdi->oldrot);
2765 protectedRotateBits(td->protectflag, rot, tdi->oldrot);
2767 add_tdi_poin(tdi->rotx, tdi->oldrot, rot[0]);
2768 add_tdi_poin(tdi->roty, tdi->oldrot+1, rot[1]);
2769 add_tdi_poin(tdi->rotz, tdi->oldrot+2, rot[2]);
2772 Mat3MulMat3(totmat, mat, td->mtx);
2773 Mat3MulMat3(smat, td->smtx, totmat);
2775 /* calculate the total rotatation in eulers */
2776 VecAddf(eul, td->ext->irot, td->ext->drot); /* we have to correct for delta rot */
2777 EulToMat3(eul, obmat);
2778 /* mat = transform, obmat = object rotation */
2779 Mat3MulMat3(fmat, smat, obmat);
2781 Mat3ToCompatibleEul(fmat, eul, td->ext->rot);
2783 /* correct back for delta rot */
2784 VecSubf(eul, eul, td->ext->drot);
2787 protectedRotateBits(td->protectflag, eul, td->ext->irot);
2788 VECCOPY(td->ext->rot, eul);
2792 constraintRotLim(t, td);
2797 static void applyRotation(TransInfo *t, float angle, float axis[3])
2799 TransData *td = t->data;
2803 VecRotToMat3(axis, angle, mat);
2805 for(i = 0 ; i < t->total; i++, td++) {
2807 if (td->flag & TD_NOACTION)
2810 if (td->flag & TD_SKIP)
2813 if (t->con.applyRot) {
2814 t->con.applyRot(t, td, axis, NULL);
2815 VecRotToMat3(axis, angle * td->factor, mat);
2817 else if (t->flag & T_PROP_EDIT) {
2818 VecRotToMat3(axis, angle * td->factor, mat);
2821 ElementRotation(t, td, mat, t->around);
2825 int Rotation(TransInfo *t, short mval[2])
2834 VECCOPY(axis, t->viewinv[2]);
2835 VecMulf(axis, -1.0f);
2838 final = t->values[0];
2840 applyNDofInput(&t->ndof, &final);
2842 snapGrid(t, &final);
2844 if (t->con.applyRot) {
2845 t->con.applyRot(t, NULL, axis, &final);
2848 applySnapping(t, &final);
2850 if (hasNumInput(&t->num)) {
2853 applyNumInput(&t->num, &final);
2855 outputNumInput(&(t->num), c);
2857 sprintf(str, "Rot: %s %s %s", &c[0], t->con.text, t->proptext);
2859 /* Clamp between -180 and 180 */
2860 while (final >= 180.0)
2863 while (final <= -180.0)
2866 final *= (float)(M_PI / 180.0);
2869 sprintf(str, "Rot: %.2f%s %s", 180.0*final/M_PI, t->con.text, t->proptext);
2872 VecRotToMat3(axis, final, mat);
2875 // t->values[0] = final; // used in manipulator
2876 // Mat3CpyMat3(t->mat, mat); // used in manipulator
2878 applyRotation(t, final, axis);
2882 ED_area_headerprint(t->sa, str);
2888 /* ************************** TRACKBALL *************************** */
2890 void initTrackball(TransInfo *t)
2892 t->mode = TFM_TRACKBALL;
2893 t->transform = Trackball;
2895 initMouseInputMode(t, &t->mouse, INPUT_TRACKBALL);
2898 /* Scale down input for rotation */
2899 t->ndof.factor[0] = 0.2f;
2900 t->ndof.factor[1] = 0.2f;
2905 t->snap[1] = (float)((5.0/180)*M_PI);
2906 t->snap[2] = t->snap[1] * 0.2f;
2908 t->flag |= T_NO_CONSTRAINT;
2911 static void applyTrackball(TransInfo *t, float axis1[3], float axis2[3], float angles[2])
2913 TransData *td = t->data;
2914 float mat[3][3], smat[3][3], totmat[3][3];
2917 VecRotToMat3(axis1, angles[0], smat);
2918 VecRotToMat3(axis2, angles[1], totmat);
2920 Mat3MulMat3(mat, smat, totmat);
2922 for(i = 0 ; i < t->total; i++, td++) {
2923 if (td->flag & TD_NOACTION)
2926 if (td->flag & TD_SKIP)
2929 if (t->flag & T_PROP_EDIT) {
2930 VecRotToMat3(axis1, td->factor * angles[0], smat);
2931 VecRotToMat3(axis2, td->factor * angles[1], totmat);
2933 Mat3MulMat3(mat, smat, totmat);
2936 ElementRotation(t, td, mat, t->around);
2940 int Trackball(TransInfo *t, short mval[2])
2943 float axis1[3], axis2[3];
2944 float mat[3][3], totmat[3][3], smat[3][3];
2947 VECCOPY(axis1, t->persinv[0]);
2948 VECCOPY(axis2, t->persinv[1]);
2952 phi[0] = t->values[0];
2953 phi[1] = t->values[1];
2955 applyNDofInput(&t->ndof, phi);
2959 if (hasNumInput(&t->num)) {
2962 applyNumInput(&t->num, phi);
2964 outputNumInput(&(t->num), c);
2966 sprintf(str, "Trackball: %s %s %s", &c[0], &c[20], t->proptext);
2968 phi[0] *= (float)(M_PI / 180.0);
2969 phi[1] *= (float)(M_PI / 180.0);
2972 sprintf(str, "Trackball: %.2f %.2f %s", 180.0*phi[0]/M_PI, 180.0*phi[1]/M_PI, t->proptext);
2975 VecRotToMat3(axis1, phi[0], smat);
2976 VecRotToMat3(axis2, phi[1], totmat);
2978 Mat3MulMat3(mat, smat, totmat);
2981 //Mat3CpyMat3(t->mat, mat); // used in manipulator