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"
104 #include "UI_view2d.h"
105 #include "WM_types.h"
108 #include "BLI_arithb.h"
109 #include "BLI_blenlib.h"
110 #include "BLI_editVert.h"
112 #include "PIL_time.h" /* sleep */
114 #include "UI_resources.h"
116 //#include "blendef.h"
118 //#include "mydevice.h"
120 #include "transform.h"
122 /* ************************** SPACE DEPENDANT CODE **************************** */
124 void setTransformViewMatrices(TransInfo *t)
126 if(t->spacetype==SPACE_VIEW3D && t->ar->regiontype == RGN_TYPE_WINDOW) {
127 RegionView3D *rv3d = t->ar->regiondata;
129 Mat4CpyMat4(t->viewmat, rv3d->viewmat);
130 Mat4CpyMat4(t->viewinv, rv3d->viewinv);
131 Mat4CpyMat4(t->persmat, rv3d->persmat);
132 Mat4CpyMat4(t->persinv, rv3d->persinv);
133 t->persp = rv3d->persp;
140 t->persp = V3D_ORTHO;
143 calculateCenter2D(t);
146 void convertViewVec(TransInfo *t, float *vec, short dx, short dy)
148 if (t->spacetype==SPACE_VIEW3D) {
149 if (t->ar->regiontype == RGN_TYPE_WINDOW)
151 window_to_3d_delta(t->ar, vec, dx, dy);
154 else if(t->spacetype==SPACE_IMAGE) {
155 View2D *v2d = t->view;
156 float divx, divy, aspx, aspy;
158 ED_space_image_uv_aspect(t->sa->spacedata.first, &aspx, &aspy);
160 divx= v2d->mask.xmax-v2d->mask.xmin;
161 divy= v2d->mask.ymax-v2d->mask.ymin;
163 vec[0]= aspx*(v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx;
164 vec[1]= aspy*(v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy;
167 else if(ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)) {
168 View2D *v2d = t->view;
171 divx= v2d->mask.xmax-v2d->mask.xmin;
172 divy= v2d->mask.ymax-v2d->mask.ymin;
174 vec[0]= (v2d->cur.xmax-v2d->cur.xmin)*(dx) / (divx);
175 vec[1]= (v2d->cur.ymax-v2d->cur.ymin)*(dy) / (divy);
178 else if(t->spacetype==SPACE_NODE) {
179 View2D *v2d = &t->ar->v2d;
182 divx= v2d->mask.xmax-v2d->mask.xmin;
183 divy= v2d->mask.ymax-v2d->mask.ymin;
185 vec[0]= (v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx;
186 vec[1]= (v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy;
189 else if(t->spacetype==SPACE_SEQ) {
190 View2D *v2d = &t->ar->v2d;
193 divx= v2d->mask.xmax-v2d->mask.xmin;
194 divy= v2d->mask.ymax-v2d->mask.ymin;
196 vec[0]= (v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx;
197 vec[1]= (v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy;
202 void projectIntView(TransInfo *t, float *vec, int *adr)
204 if (t->spacetype==SPACE_VIEW3D) {
205 if(t->ar->regiontype == RGN_TYPE_WINDOW)
206 project_int_noclip(t->ar, vec, adr);
208 else if(t->spacetype==SPACE_IMAGE) {
209 float aspx, aspy, v[2];
211 ED_space_image_uv_aspect(t->sa->spacedata.first, &aspx, &aspy);
215 UI_view2d_to_region_no_clip(t->view, v[0], v[1], adr, adr+1);
217 else if(ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)) {
220 UI_view2d_view_to_region((View2D *)t->view, vec[0], vec[1], out, out+1);
224 else if(t->spacetype==SPACE_SEQ) { /* XXX not tested yet, but should work */
227 UI_view2d_view_to_region((View2D *)t->view, vec[0], vec[1], out, out+1);
233 void projectFloatView(TransInfo *t, float *vec, float *adr)
235 if (t->spacetype==SPACE_VIEW3D) {
236 if(t->ar->regiontype == RGN_TYPE_WINDOW)
237 project_float_noclip(t->ar, vec, adr);
239 else if(t->spacetype==SPACE_IMAGE) {
242 projectIntView(t, vec, a);
246 else if(ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)) {
249 projectIntView(t, vec, a);
255 void applyAspectRatio(TransInfo *t, float *vec)
257 SpaceImage *sima= t->sa->spacedata.first;
259 if ((t->spacetype==SPACE_IMAGE) && (t->mode==TFM_TRANSLATION)) {
262 if((sima->flag & SI_COORDFLOATS)==0) {
264 ED_space_image_size(sima, &width, &height);
270 ED_space_image_uv_aspect(sima, &aspx, &aspy);
276 void removeAspectRatio(TransInfo *t, float *vec)
278 SpaceImage *sima= t->sa->spacedata.first;
280 if ((t->spacetype==SPACE_IMAGE) && (t->mode==TFM_TRANSLATION)) {
283 if((sima->flag & SI_COORDFLOATS)==0) {
285 ED_space_image_size(sima, &width, &height);
291 ED_space_image_uv_aspect(sima, &aspx, &aspy);
297 static void viewRedrawForce(bContext *C, TransInfo *t)
299 if (t->spacetype == SPACE_VIEW3D)
301 /* Do we need more refined tags? */
302 WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
304 /* for realtime animation record - send notifiers recognised by animation editors */
305 if ((t->animtimer) && IS_AUTOKEY_ON(t->scene))
306 WM_event_add_notifier(C, NC_OBJECT|ND_KEYS, NULL);
308 else if (t->spacetype == SPACE_ACTION) {
309 //SpaceAction *saction= (SpaceAction *)t->sa->spacedata.first;
310 WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME_EDIT, NULL);
312 else if (t->spacetype == SPACE_IPO) {
313 //SpaceIpo *sipo= (SpaceIpo *)t->sa->spacedata.first;
314 WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME_EDIT, NULL);
316 else if (t->spacetype == SPACE_NLA) {
317 WM_event_add_notifier(C, NC_ANIMATION|ND_NLA_EDIT, NULL);
319 else if(t->spacetype == SPACE_NODE)
321 //ED_area_tag_redraw(t->sa);
322 WM_event_add_notifier(C, NC_SCENE|ND_NODES, NULL);
324 else if(t->spacetype == SPACE_SEQ)
326 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, NULL);
328 else if (t->spacetype==SPACE_IMAGE) {
329 // XXX how to deal with lock?
331 SpaceImage *sima= (SpaceImage*)t->sa->spacedata.first;
332 if(sima->lock) force_draw_plus(SPACE_VIEW3D, 0);
336 WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_DATA, t->obedit);
340 static void viewRedrawPost(TransInfo *t)
342 ED_area_headerprint(t->sa, NULL);
344 #if 0 // TRANSFORM_FIX_ME
345 if(t->spacetype==SPACE_VIEW3D) {
346 allqueue(REDRAWBUTSOBJECT, 0);
347 allqueue(REDRAWVIEW3D, 0);
349 else if(t->spacetype==SPACE_IMAGE) {
350 allqueue(REDRAWIMAGE, 0);
351 allqueue(REDRAWVIEW3D, 0);
353 else if(ELEM3(t->spacetype, SPACE_ACTION, SPACE_NLA, SPACE_IPO)) {
354 allqueue(REDRAWVIEW3D, 0);
355 allqueue(REDRAWACTION, 0);
356 allqueue(REDRAWNLA, 0);
357 allqueue(REDRAWIPO, 0);
358 allqueue(REDRAWTIME, 0);
359 allqueue(REDRAWBUTSOBJECT, 0);
362 scrarea_queue_headredraw(curarea);
366 /* ************************** TRANSFORMATIONS **************************** */
368 void BIF_selectOrientation() {
369 #if 0 // TRANSFORM_FIX_ME
371 char *str_menu = BIF_menustringTransformOrientation("Orientation");
372 val= pupmenu(str_menu);
381 static void view_editmove(unsigned short event)
383 #if 0 // TRANSFORM_FIX_ME
385 /* Regular: Zoom in */
386 /* Shift: Scroll up */
387 /* Ctrl: Scroll right */
388 /* Alt-Shift: Rotate up */
389 /* Alt-Ctrl: Rotate right */
391 /* only work in 3D window for now
392 * In the end, will have to send to event to a 2D window handler instead
394 if (Trans.flag & T_2D_EDIT)
400 if( G.qual & LR_SHIFTKEY ) {
401 if( G.qual & LR_ALTKEY ) {
402 G.qual &= ~LR_SHIFTKEY;
404 G.qual |= LR_SHIFTKEY;
408 } else if( G.qual & LR_CTRLKEY ) {
409 if( G.qual & LR_ALTKEY ) {
410 G.qual &= ~LR_CTRLKEY;
412 G.qual |= LR_CTRLKEY;
416 } else if(U.uiflag & USER_WHEELZOOMDIR)
417 persptoetsen(PADMINUS);
419 persptoetsen(PADPLUSKEY);
424 if( G.qual & LR_SHIFTKEY ) {
425 if( G.qual & LR_ALTKEY ) {
426 G.qual &= ~LR_SHIFTKEY;
428 G.qual |= LR_SHIFTKEY;
432 } else if( G.qual & LR_CTRLKEY ) {
433 if( G.qual & LR_ALTKEY ) {
434 G.qual &= ~LR_CTRLKEY;
436 G.qual |= LR_CTRLKEY;
440 } else if(U.uiflag & USER_WHEELZOOMDIR)
441 persptoetsen(PADPLUSKEY);
443 persptoetsen(PADMINUS);
450 setTransformViewMatrices(&Trans);
455 static char *transform_to_undostr(TransInfo *t)
458 case TFM_TRANSLATION:
470 case TFM_SHRINKFATTEN:
471 return "Shrink/Fatten";
481 return "Bevel Weight";
486 case TFM_BONE_ENVELOPE:
487 return "Bone Envelope";
488 case TFM_TIME_TRANSLATE:
489 return "Translate Anim. Data";
491 return "Scale Anim. Data";
503 /* ************************************************* */
505 /* NOTE: these defines are saved in keymap files, do not change values but just add new ones */
506 #define TFM_MODAL_CANCEL 1
507 #define TFM_MODAL_CONFIRM 2
508 #define TFM_MODAL_TRANSLATE 3
509 #define TFM_MODAL_ROTATE 4
510 #define TFM_MODAL_RESIZE 5
511 #define TFM_MODAL_SNAP_GEARS 6
512 #define TFM_MODAL_SNAP_GEARS_OFF 7
514 /* called in transform_ops.c, on each regeneration of keymaps */
515 void transform_modal_keymap(wmWindowManager *wm)
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 {0, NULL, 0, NULL, NULL}};
527 wmKeyMap *keymap= WM_modalkeymap_get(wm, "Transform Modal Map");
529 /* this function is called for each spacetype, only needs to add map once */
532 keymap= WM_modalkeymap_add(wm, "Transform Modal Map", modal_items);
534 /* items for modal map */
535 WM_modalkeymap_add_item(keymap, ESCKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_CANCEL);
536 WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_ANY, KM_ANY, 0, TFM_MODAL_CONFIRM);
537 WM_modalkeymap_add_item(keymap, RETKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_CONFIRM);
538 WM_modalkeymap_add_item(keymap, PADENTER, KM_PRESS, KM_ANY, 0, TFM_MODAL_CONFIRM);
540 WM_modalkeymap_add_item(keymap, GKEY, KM_PRESS, 0, 0, TFM_MODAL_TRANSLATE);
541 WM_modalkeymap_add_item(keymap, RKEY, KM_PRESS, 0, 0, TFM_MODAL_ROTATE);
542 WM_modalkeymap_add_item(keymap, SKEY, KM_PRESS, 0, 0, TFM_MODAL_RESIZE);
544 WM_modalkeymap_add_item(keymap, LEFTCTRLKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_SNAP_GEARS);
545 WM_modalkeymap_add_item(keymap, LEFTCTRLKEY, KM_RELEASE, KM_ANY, 0, TFM_MODAL_SNAP_GEARS_OFF);
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 applyMouseInput(t, &t->mouse, t->mval, t->values);
579 /* handle modal keymap first */
580 if (event->type == EVT_MODAL_MAP) {
581 switch (event->val) {
582 case TFM_MODAL_CANCEL:
583 t->state = TRANS_CANCEL;
585 case TFM_MODAL_CONFIRM:
586 t->state = TRANS_CONFIRM;
589 case TFM_MODAL_TRANSLATE:
590 /* only switch when... */
591 if( ELEM3(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL) ) {
592 resetTransRestrictions(t);
593 restoreTransObjects(t);
595 initSnapping(t, NULL); // need to reinit after mode change
599 case TFM_MODAL_ROTATE:
600 /* only switch when... */
601 if( ELEM4(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL, TFM_TRANSLATION) ) {
603 resetTransRestrictions(t);
605 if (t->mode == TFM_ROTATION) {
606 restoreTransObjects(t);
610 restoreTransObjects(t);
613 initSnapping(t, NULL); // need to reinit after mode change
617 case TFM_MODAL_RESIZE:
618 /* only switch when... */
619 if( ELEM3(t->mode, TFM_ROTATION, TFM_TRANSLATION, TFM_TRACKBALL) ) {
620 resetTransRestrictions(t);
621 restoreTransObjects(t);
623 initSnapping(t, NULL); // need to reinit after mode change
628 case TFM_MODAL_SNAP_GEARS:
629 t->modifiers |= MOD_SNAP_GEARS;
632 case TFM_MODAL_SNAP_GEARS_OFF:
633 t->modifiers &= ~MOD_SNAP_GEARS;
638 /* else do non-mapped events */
639 else if (event->val==KM_PRESS) {
640 switch (event->type){
642 t->state = TRANS_CANCEL;
644 /* enforce redraw of transform when modifiers are used */
647 t->modifiers |= MOD_SNAP_GEARS;
653 t->modifiers |= MOD_CONSTRAINT_PLANE;
658 if ((t->spacetype==SPACE_VIEW3D) && event->alt) {
659 #if 0 // TRANSFORM_FIX_ME
663 BIF_selectOrientation();
664 calc_manipulator_stats(curarea);
665 Mat3CpyMat4(t->spacemtx, G.vd->twmat);
666 warp_pointer(mval[0], mval[1]);
670 t->state = TRANS_CONFIRM;
675 if ((t->flag & T_NO_CONSTRAINT)==0) {
676 /* exception for switching to dolly, or trackball, in camera view */
677 if (t->flag & T_CAMERA) {
678 if (t->mode==TFM_TRANSLATION)
679 setLocalConstraint(t, (CON_AXIS2), "along local Z");
680 else if (t->mode==TFM_ROTATION) {
681 restoreTransObjects(t);
686 t->modifiers |= MOD_CONSTRAINT_SELECT;
687 if (t->con.mode & CON_APPLY) {
692 initSelectConstraint(t, t->spacemtx);
695 /* bit hackish... but it prevents mmb select to print the orientation from menu */
696 strcpy(t->spacename, "global");
697 initSelectConstraint(t, mati);
699 postSelectConstraint(t);
706 t->state = TRANS_CANCEL;
710 t->state = TRANS_CONFIRM;
713 /* only switch when... */
714 if( ELEM3(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL) ) {
715 resetTransRestrictions(t);
716 restoreTransObjects(t);
718 initSnapping(t, NULL); // need to reinit after mode change
723 /* only switch when... */
724 if( ELEM3(t->mode, TFM_ROTATION, TFM_TRANSLATION, TFM_TRACKBALL) ) {
725 resetTransRestrictions(t);
726 restoreTransObjects(t);
728 initSnapping(t, NULL); // need to reinit after mode change
733 /* only switch when... */
734 if( ELEM4(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL, TFM_TRANSLATION) ) {
736 resetTransRestrictions(t);
738 if (t->mode == TFM_ROTATION) {
739 restoreTransObjects(t);
743 restoreTransObjects(t);
746 initSnapping(t, NULL); // need to reinit after mode change
752 t->flag ^= T_PROP_CONNECTED;
753 sort_trans_data_dist(t);
754 calculatePropRatio(t);
763 if ((t->flag & T_NO_CONSTRAINT)==0) {
765 if (t->flag & T_2D_EDIT) {
769 if (t->con.mode & CON_USER) {
773 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
774 setUserConstraint(t, (CON_AXIS0), "along %s X");
775 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
776 setUserConstraint(t, (CON_AXIS1|CON_AXIS2), "locking %s X");
781 if (t->flag & T_2D_EDIT) {
782 setConstraint(t, mati, (CON_AXIS0), "along X axis");
785 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
786 setConstraint(t, mati, (CON_AXIS0), "along global X");
787 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
788 setConstraint(t, mati, (CON_AXIS1|CON_AXIS2), "locking global X");
795 if ((t->flag & T_NO_CONSTRAINT)==0) {
797 if (t->flag & T_2D_EDIT) {
801 if (t->con.mode & CON_USER) {
805 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
806 setUserConstraint(t, (CON_AXIS1), "along %s Y");
807 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
808 setUserConstraint(t, (CON_AXIS0|CON_AXIS2), "locking %s Y");
813 if (t->flag & T_2D_EDIT) {
814 setConstraint(t, mati, (CON_AXIS1), "along Y axis");
817 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
818 setConstraint(t, mati, (CON_AXIS1), "along global Y");
819 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
820 setConstraint(t, mati, (CON_AXIS0|CON_AXIS2), "locking global Y");
827 if ((t->flag & T_NO_CONSTRAINT)==0) {
829 if (t->con.mode & CON_USER) {
833 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
834 setUserConstraint(t, (CON_AXIS2), "along %s Z");
835 else if ((t->modifiers & MOD_CONSTRAINT_PLANE) && ((t->flag & T_2D_EDIT)==0))
836 setUserConstraint(t, (CON_AXIS0|CON_AXIS1), "locking %s Z");
839 else if ((t->flag & T_2D_EDIT)==0) {
840 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
841 setConstraint(t, mati, (CON_AXIS2), "along global Z");
842 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
843 setConstraint(t, mati, (CON_AXIS0|CON_AXIS1), "locking global Z");
849 if (t->flag & T_PROP_EDIT && event->shift) {
850 t->prop_mode = (t->prop_mode + 1) % 6;
851 calculatePropRatio(t);
856 if(event->alt && t->flag & T_PROP_EDIT) {
857 t->prop_size *= 1.1f;
858 calculatePropRatio(t);
864 if (t->flag & T_AUTOIK) {
865 transform_autoik_update(t, 1);
867 else if(t->flag & T_PROP_EDIT) {
869 calculatePropRatio(t);
871 else view_editmove(event->type);
875 if(event->alt && t->flag & T_PROP_EDIT) {
876 t->prop_size*= 0.90909090f;
877 calculatePropRatio(t);
883 if (t->flag & T_AUTOIK) {
884 transform_autoik_update(t, -1);
886 else if (t->flag & T_PROP_EDIT) {
887 t->prop_size*= 0.90909090f;
888 calculatePropRatio(t);
890 else view_editmove(event->type);
898 // Numerical input events
899 t->redraw |= handleNumInput(&(t->num), event);
902 switch(handleNDofInput(&(t->ndof), event))
905 if ((t->options & CTX_NDOF) == 0)
907 /* Confirm on normal transform only */
908 t->state = TRANS_CONFIRM;
912 if (t->options & CTX_NDOF)
914 /* Cancel on pure NDOF transform */
915 t->state = TRANS_CANCEL;
919 /* Otherwise, just redraw, NDof input was cancelled */
924 if (t->options & CTX_NDOF)
926 /* Confirm on pure NDOF transform */
927 t->state = TRANS_CONFIRM;
937 t->redraw |= handleSnapping(t, event);
939 //arrows_move_cursor(event->type);
942 switch (event->type){
944 t->state = TRANS_CONFIRM;
948 t->modifiers &= ~MOD_CONSTRAINT_PLANE;
954 t->modifiers &= ~MOD_SNAP_GEARS;
955 /* no redraw on release modifier keys! this makes sure you can assign the 'grid' still
956 after releasing modifer key */
960 if ((t->flag & T_NO_CONSTRAINT)==0) {
961 t->modifiers &= ~MOD_CONSTRAINT_SELECT;
962 postSelectConstraint(t);
968 // if(WM_modal_tweak_exit(event, t->event_type))
969 //// if (t->options & CTX_TWEAK)
970 // t->state = TRANS_CONFIRM;
975 // Per transform event, if present
977 t->redraw |= t->handleEvent(t, event);
980 int calculateTransformCenter(bContext *C, wmEvent *event, int centerMode, float *vec)
982 TransInfo *t = MEM_callocN(sizeof(TransInfo), "TransInfo data");
985 t->state = TRANS_RUNNING;
987 t->options = CTX_NONE;
991 initTransInfo(C, t, NULL, event); // internal data, mouse, vectors
993 createTransData(C, t); // make TransData structs from selection
995 t->around = centerMode; // override userdefined mode
1005 // Copy center from constraint center. Transform center can be local
1006 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);
1025 static void drawArrow(ArrowDirection d, short offset, short length, short size)
1035 glVertex2s( offset, 0);
1036 glVertex2s( offset + length, 0);
1037 glVertex2s( offset + length, 0);
1038 glVertex2s( offset + length - size, -size);
1039 glVertex2s( offset + length, 0);
1040 glVertex2s( offset + length - size, size);
1049 glVertex2s( 0, offset);
1050 glVertex2s( 0, offset + length);
1051 glVertex2s( 0, offset + length);
1052 glVertex2s(-size, offset + length - size);
1053 glVertex2s( 0, offset + length);
1054 glVertex2s( size, offset + length - size);
1060 static void drawArrowHead(ArrowDirection d, short size)
1069 glVertex2s( -size, -size);
1071 glVertex2s( -size, size);
1079 glVertex2s(-size, -size);
1081 glVertex2s( size, -size);
1087 static void drawArc(float size, float angle_start, float angle_end, int segments)
1089 float delta = (angle_end - angle_start) / segments;
1092 glBegin(GL_LINE_STRIP);
1094 for( angle = angle_start; angle < angle_end; angle += delta)
1096 glVertex2f( cosf(angle) * size, sinf(angle) * size);
1098 glVertex2f( cosf(angle_end) * size, sinf(angle_end) * size);
1103 void drawHelpline(const struct bContext *C, TransInfo *t)
1105 if (t->helpline != HLP_NONE && !(t->flag & T_USES_MANIPULATOR))
1107 float vecrot[3], cent[2];
1109 VECCOPY(vecrot, t->center);
1110 if(t->flag & T_EDIT) {
1111 Object *ob= t->obedit;
1112 if(ob) Mat4MulVecfl(ob->obmat, vecrot);
1114 else if(t->flag & T_POSE) {
1115 Object *ob=t->poseobj;
1116 if(ob) Mat4MulVecfl(ob->obmat, vecrot);
1119 projectFloatView(t, vecrot, cent); // no overflow in extreme cases
1121 glDisable(GL_DEPTH_TEST);
1123 glMatrixMode(GL_PROJECTION);
1125 glMatrixMode(GL_MODELVIEW);
1128 ED_region_pixelspace(t->ar);
1133 UI_ThemeColor(TH_WIRE);
1136 glBegin(GL_LINE_STRIP);
1137 glVertex2sv(t->mval);
1141 glTranslatef(t->mval[0], t->mval[1], 0);
1142 glRotatef(-180 / M_PI * atan2f(cent[0] - t->mval[0], cent[1] - t->mval[1]), 0, 0, 1);
1146 drawArrow(UP, 5, 10, 5);
1147 drawArrow(DOWN, 5, 10, 5);
1151 UI_ThemeColor(TH_WIRE);
1153 glTranslatef(t->mval[0], t->mval[1], 0);
1156 drawArrow(RIGHT, 5, 10, 5);
1157 drawArrow(LEFT, 5, 10, 5);
1161 UI_ThemeColor(TH_WIRE);
1163 glTranslatef(t->mval[0], t->mval[1], 0);
1167 drawArrow(UP, 5, 10, 5);
1168 drawArrow(DOWN, 5, 10, 5);
1173 float dx = t->mval[0] - cent[0], dy = t->mval[1] - cent[1];
1174 float angle = atan2f(dy, dx);
1175 float dist = sqrtf(dx*dx + dy*dy);
1176 float delta_angle = MIN2(15 / dist, M_PI/4);
1177 float spacing_angle = MIN2(5 / dist, M_PI/12);
1178 UI_ThemeColor(TH_WIRE);
1181 glBegin(GL_LINE_STRIP);
1182 glVertex2sv(t->mval);
1186 glTranslatef(cent[0], cent[1], 0);
1190 drawArc(dist, angle - delta_angle, angle - spacing_angle, 10);
1191 drawArc(dist, angle + spacing_angle, angle + delta_angle, 10);
1195 glTranslatef(cosf(angle - delta_angle) * dist, sinf(angle - delta_angle) * dist, 0);
1196 glRotatef(180 / M_PI * (angle - delta_angle), 0, 0, 1);
1198 drawArrowHead(DOWN, 5);
1202 glTranslatef(cosf(angle + delta_angle) * dist, sinf(angle + delta_angle) * dist, 0);
1203 glRotatef(180 / M_PI * (angle + delta_angle), 0, 0, 1);
1205 drawArrowHead(UP, 5);
1212 char col[3], col2[3];
1213 UI_GetThemeColor3ubv(TH_GRID, col);
1215 glTranslatef(t->mval[0], t->mval[1], 0);
1219 UI_make_axis_color(col, col2, 'x');
1220 glColor3ubv((GLubyte *)col2);
1222 drawArrow(RIGHT, 5, 10, 5);
1223 drawArrow(LEFT, 5, 10, 5);
1225 UI_make_axis_color(col, col2, 'y');
1226 glColor3ubv((GLubyte *)col2);
1228 drawArrow(UP, 5, 10, 5);
1229 drawArrow(DOWN, 5, 10, 5);
1235 glMatrixMode(GL_PROJECTION);
1237 glMatrixMode(GL_MODELVIEW);
1240 glEnable(GL_DEPTH_TEST);
1244 void drawTransform(const struct bContext *C, struct ARegion *ar, void *arg)
1248 drawConstraint(C, t);
1249 drawPropCircle(C, t);
1254 void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
1256 ToolSettings *ts = CTX_data_tool_settings(C);
1257 int constraint_axis[3] = {0, 0, 0};
1258 int proportional = 0;
1260 if (t->flag & T_AUTOVALUES)
1262 RNA_float_set_array(op->ptr, "value", t->auto_values);
1266 RNA_float_set_array(op->ptr, "value", t->values);
1269 /* XXX convert stupid flag to enum */
1270 switch(t->flag & (T_PROP_EDIT|T_PROP_CONNECTED))
1272 case (T_PROP_EDIT|T_PROP_CONNECTED):
1282 if (RNA_struct_find_property(op->ptr, "proportional"))
1284 RNA_enum_set(op->ptr, "proportional", proportional);
1285 RNA_enum_set(op->ptr, "proportional_editing_falloff", t->prop_mode);
1286 RNA_float_set(op->ptr, "proportional_size", t->prop_size);
1289 if (RNA_struct_find_property(op->ptr, "mirror"))
1291 RNA_boolean_set(op->ptr, "mirror", t->flag & T_MIRROR);
1294 if (RNA_struct_find_property(op->ptr, "constraint_axis"))
1296 RNA_enum_set(op->ptr, "constraint_orientation", t->current_orientation);
1298 if (t->con.mode & CON_APPLY)
1300 if (t->con.mode & CON_AXIS0) {
1301 constraint_axis[0] = 1;
1303 if (t->con.mode & CON_AXIS1) {
1304 constraint_axis[1] = 1;
1306 if (t->con.mode & CON_AXIS2) {
1307 constraint_axis[2] = 1;
1311 RNA_boolean_set_array(op->ptr, "constraint_axis", constraint_axis);
1314 // XXX If modal, save settings back in scene
1315 if (t->flag & T_MODAL)
1317 ts->prop_mode = t->prop_mode;
1318 ts->proportional = proportional;
1320 if(t->spacetype == SPACE_VIEW3D)
1322 View3D *v3d = t->view;
1324 v3d->twmode = t->current_orientation;
1329 int initTransform(bContext *C, TransInfo *t, wmOperator *op, wmEvent *event, int mode)
1333 /* added initialize, for external calls to set stuff in TransInfo, like undo string */
1335 t->state = TRANS_RUNNING;
1337 t->options = options;
1341 if (!initTransInfo(C, t, op, event)) // internal data, mouse, vectors
1346 if(t->spacetype == SPACE_VIEW3D)
1348 //calc_manipulator_stats(curarea);
1349 initTransformOrientation(C, t);
1351 t->draw_handle = ED_region_draw_cb_activate(t->ar->type, drawTransform, t, REGION_DRAW_POST);
1353 else if(t->spacetype == SPACE_IMAGE) {
1354 Mat3One(t->spacemtx);
1355 t->draw_handle = ED_region_draw_cb_activate(t->ar->type, drawTransform, t, REGION_DRAW_POST);
1358 Mat3One(t->spacemtx);
1360 createTransData(C, t); // make TransData structs from selection
1362 if (t->total == 0) {
1367 initSnapping(t, op); // Initialize snapping data AFTER mode flags
1369 /* EVIL! posemode code can switch translation to rotate when 1 bone is selected. will be removed (ton) */
1370 /* EVIL2: we gave as argument also texture space context bit... was cleared */
1371 /* EVIL3: extend mode for animation editors also switches modes... but is best way to avoid duplicate code */
1374 calculatePropRatio(t);
1377 initMouseInput(t, &t->mouse, t->center2d, t->imval);
1380 case TFM_TRANSLATION:
1398 case TFM_SHRINKFATTEN:
1399 initShrinkFatten(t);
1404 case TFM_CURVE_SHRINKFATTEN:
1405 initCurveShrinkFatten(t);
1417 { /* used for both B-Bone width (bonesize) as for deform-dist (envelope) */
1418 bArmature *arm= t->poseobj->data;
1419 if(arm->drawtype==ARM_ENVELOPE)
1420 initBoneEnvelope(t);
1425 case TFM_BONE_ENVELOPE:
1426 initBoneEnvelope(t);
1431 case TFM_TIME_TRANSLATE:
1432 initTimeTranslate(t);
1434 case TFM_TIME_SLIDE:
1437 case TFM_TIME_SCALE:
1440 case TFM_TIME_EXTEND:
1441 /* now that transdata has been made, do like for TFM_TIME_TRANSLATE (for most Animation
1442 * Editors because they have only 1D transforms for time values) or TFM_TRANSLATION
1443 * (for Graph/NLA Editors only since they uses 'standard' transforms to get 2D movement)
1444 * depending on which editor this was called from
1446 if ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)
1449 initTimeTranslate(t);
1468 /* overwrite initial values if operator supplied a non-null vector */
1469 if (RNA_property_is_set(op->ptr, "value"))
1472 RNA_float_get_array(op->ptr, "value", values);
1473 QUATCOPY(t->values, values);
1474 QUATCOPY(t->auto_values, values);
1475 t->flag |= T_AUTOVALUES;
1478 /* Constraint init from operator */
1479 if (RNA_struct_find_property(op->ptr, "constraint_axis") && RNA_property_is_set(op->ptr, "constraint_axis"))
1481 int constraint_axis[3];
1483 RNA_boolean_get_array(op->ptr, "constraint_axis", constraint_axis);
1485 if (constraint_axis[0] || constraint_axis[1] || constraint_axis[2])
1487 t->con.mode |= CON_APPLY;
1489 if (constraint_axis[0]) {
1490 t->con.mode |= CON_AXIS0;
1492 if (constraint_axis[1]) {
1493 t->con.mode |= CON_AXIS1;
1495 if (constraint_axis[2]) {
1496 t->con.mode |= CON_AXIS2;
1499 setUserConstraint(t, t->con.mode, "%s");
1506 void transformApply(bContext *C, TransInfo *t)
1510 if (t->modifiers & MOD_CONSTRAINT_SELECT)
1511 t->con.mode |= CON_SELECT;
1513 selectConstraint(t);
1515 t->transform(t, t->mval); // calls recalcData()
1516 viewRedrawForce(C, t);
1521 /* If auto confirm is on, break after one pass */
1522 if (t->options & CTX_AUTOCONFIRM)
1524 t->state = TRANS_CONFIRM;
1527 if (BKE_ptcache_get_continue_physics())
1530 //do_screenhandlers(G.curscreen);
1535 int transformEnd(bContext *C, TransInfo *t)
1537 int exit_code = OPERATOR_RUNNING_MODAL;
1539 if (t->state != TRANS_RUNNING)
1541 /* handle restoring objects */
1542 if(t->state == TRANS_CANCEL)
1544 exit_code = OPERATOR_CANCELLED;
1545 restoreTransObjects(t); // calls recalcData()
1549 exit_code = OPERATOR_FINISHED;
1555 /* aftertrans does insert keyframes, and clears base flags, doesnt read transdata */
1556 special_aftertrans_update(t);
1558 /* send events out for redraws */
1561 /* Undo as last, certainly after special_trans_update! */
1563 if(t->state == TRANS_CANCEL) {
1564 // if(t->undostr) ED_undo_push(C, t->undostr);
1567 // if(t->undostr) ED_undo_push(C, t->undostr);
1568 // else ED_undo_push(C, transform_to_undostr(t));
1572 viewRedrawForce(C, t);
1578 /* ************************** TRANSFORM LOCKS **************************** */
1580 static void protectedTransBits(short protectflag, float *vec)
1582 if(protectflag & OB_LOCK_LOCX)
1584 if(protectflag & OB_LOCK_LOCY)
1586 if(protectflag & OB_LOCK_LOCZ)
1590 static void protectedSizeBits(short protectflag, float *size)
1592 if(protectflag & OB_LOCK_SCALEX)
1594 if(protectflag & OB_LOCK_SCALEY)
1596 if(protectflag & OB_LOCK_SCALEZ)
1600 static void protectedRotateBits(short protectflag, float *eul, float *oldeul)
1602 if(protectflag & OB_LOCK_ROTX)
1604 if(protectflag & OB_LOCK_ROTY)
1606 if(protectflag & OB_LOCK_ROTZ)
1610 static void protectedQuaternionBits(short protectflag, float *quat, float *oldquat)
1612 /* quaternions get limited with euler... */
1613 /* this function only does the delta rotation */
1616 float eul[3], oldeul[3], quat1[4];
1618 QUATCOPY(quat1, quat);
1619 QuatToEul(quat, eul);
1620 QuatToEul(oldquat, oldeul);
1622 if(protectflag & OB_LOCK_ROTX)
1624 if(protectflag & OB_LOCK_ROTY)
1626 if(protectflag & OB_LOCK_ROTZ)
1629 EulToQuat(eul, quat);
1630 /* quaternions flip w sign to accumulate rotations correctly */
1631 if( (quat1[0]<0.0f && quat[0]>0.0f) || (quat1[0]>0.0f && quat[0]<0.0f) ) {
1632 QuatMulf(quat, -1.0f);
1637 /* ******************* TRANSFORM LIMITS ********************** */
1639 static void constraintTransLim(TransInfo *t, TransData *td)
1642 bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_LOCLIMIT);
1646 /* Make a temporary bConstraintOb for using these limit constraints
1647 * - they only care that cob->matrix is correctly set ;-)
1648 * - current space should be local
1650 memset(&cob, 0, sizeof(bConstraintOb));
1651 Mat4One(cob.matrix);
1653 TransDataIpokey *tdi= td->tdi;
1654 cob.matrix[3][0]= tdi->locx[0];
1655 cob.matrix[3][1]= tdi->locy[0];
1656 cob.matrix[3][2]= tdi->locz[0];
1659 VECCOPY(cob.matrix[3], td->loc);
1662 /* Evaluate valid constraints */
1663 for (con= td->con; con; con= con->next) {
1666 /* only consider constraint if enabled */
1667 if (con->flag & CONSTRAINT_DISABLE) continue;
1668 if (con->enforce == 0.0f) continue;
1670 /* only use it if it's tagged for this purpose (and the right type) */
1671 if (con->type == CONSTRAINT_TYPE_LOCLIMIT) {
1672 bLocLimitConstraint *data= con->data;
1674 if ((data->flag2 & LIMIT_TRANSFORM)==0)
1677 /* do space conversions */
1678 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1679 /* just multiply by td->mtx (this should be ok) */
1680 Mat4CpyMat4(tmat, cob.matrix);
1681 Mat4MulMat34(cob.matrix, td->mtx, tmat);
1683 else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) {
1684 /* skip... incompatable spacetype */
1689 cti->evaluate_constraint(con, &cob, NULL);
1691 /* convert spaces again */
1692 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1693 /* just multiply by td->mtx (this should be ok) */
1694 Mat4CpyMat4(tmat, cob.matrix);
1695 Mat4MulMat34(cob.matrix, td->smtx, tmat);
1700 /* copy results from cob->matrix */
1702 TransDataIpokey *tdi= td->tdi;
1703 tdi->locx[0]= cob.matrix[3][0];
1704 tdi->locy[0]= cob.matrix[3][1];
1705 tdi->locz[0]= cob.matrix[3][2];
1708 VECCOPY(td->loc, cob.matrix[3]);
1713 static void constraintRotLim(TransInfo *t, TransData *td)
1716 bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_ROTLIMIT);
1720 /* Make a temporary bConstraintOb for using these limit constraints
1721 * - they only care that cob->matrix is correctly set ;-)
1722 * - current space should be local
1724 memset(&cob, 0, sizeof(bConstraintOb));
1725 if (td->flag & TD_USEQUAT) {
1728 QuatToMat4(td->ext->quat, cob.matrix);
1733 /* ipo-keys eulers */
1734 TransDataIpokey *tdi= td->tdi;
1737 eul[0]= tdi->rotx[0];
1738 eul[1]= tdi->roty[0];
1739 eul[2]= tdi->rotz[0];
1741 EulToMat4(eul, cob.matrix);
1746 EulToMat4(td->ext->rot, cob.matrix);
1751 /* Evaluate valid constraints */
1752 for (con= td->con; con; con= con->next) {
1753 /* only consider constraint if enabled */
1754 if (con->flag & CONSTRAINT_DISABLE) continue;
1755 if (con->enforce == 0.0f) continue;
1757 /* we're only interested in Limit-Rotation constraints */
1758 if (con->type == CONSTRAINT_TYPE_ROTLIMIT) {
1759 bRotLimitConstraint *data= con->data;
1762 /* only use it if it's tagged for this purpose */
1763 if ((data->flag2 & LIMIT_TRANSFORM)==0)
1766 /* do space conversions */
1767 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1768 /* just multiply by td->mtx (this should be ok) */
1769 Mat4CpyMat4(tmat, cob.matrix);
1770 Mat4MulMat34(cob.matrix, td->mtx, tmat);
1772 else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) {
1773 /* skip... incompatable spacetype */
1778 cti->evaluate_constraint(con, &cob, NULL);
1780 /* convert spaces again */
1781 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1782 /* just multiply by td->mtx (this should be ok) */
1783 Mat4CpyMat4(tmat, cob.matrix);
1784 Mat4MulMat34(cob.matrix, td->smtx, tmat);
1789 /* copy results from cob->matrix */
1790 if (td->flag & TD_USEQUAT) {
1792 Mat4ToQuat(cob.matrix, td->ext->quat);
1795 /* ipo-keys eulers */
1796 TransDataIpokey *tdi= td->tdi;
1799 Mat4ToEul(cob.matrix, eul);
1801 tdi->rotx[0]= eul[0];
1802 tdi->roty[0]= eul[1];
1803 tdi->rotz[0]= eul[2];
1807 Mat4ToEul(cob.matrix, td->ext->rot);
1812 static void constraintSizeLim(TransInfo *t, TransData *td)
1814 if (td->con && td->ext) {
1815 bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_SIZELIMIT);
1819 /* Make a temporary bConstraintOb for using these limit constraints
1820 * - they only care that cob->matrix is correctly set ;-)
1821 * - current space should be local
1823 memset(&cob, 0, sizeof(bConstraintOb));
1825 TransDataIpokey *tdi= td->tdi;
1828 size[0]= tdi->sizex[0];
1829 size[1]= tdi->sizey[0];
1830 size[2]= tdi->sizez[0];
1831 SizeToMat4(size, cob.matrix);
1833 else if ((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)) {
1834 /* scale val and reset size */
1835 return; // TODO: fix this case
1838 /* Reset val if SINGLESIZE but using a constraint */
1839 if (td->flag & TD_SINGLESIZE)
1842 SizeToMat4(td->ext->size, cob.matrix);
1845 /* Evaluate valid constraints */
1846 for (con= td->con; con; con= con->next) {
1847 /* only consider constraint if enabled */
1848 if (con->flag & CONSTRAINT_DISABLE) continue;
1849 if (con->enforce == 0.0f) continue;
1851 /* we're only interested in Limit-Scale constraints */
1852 if (con->type == CONSTRAINT_TYPE_SIZELIMIT) {
1853 bSizeLimitConstraint *data= con->data;
1856 /* only use it if it's tagged for this purpose */
1857 if ((data->flag2 & LIMIT_TRANSFORM)==0)
1860 /* do space conversions */
1861 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1862 /* just multiply by td->mtx (this should be ok) */
1863 Mat4CpyMat4(tmat, cob.matrix);
1864 Mat4MulMat34(cob.matrix, td->mtx, tmat);
1866 else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) {
1867 /* skip... incompatable spacetype */
1872 cti->evaluate_constraint(con, &cob, NULL);
1874 /* convert spaces again */
1875 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1876 /* just multiply by td->mtx (this should be ok) */
1877 Mat4CpyMat4(tmat, cob.matrix);
1878 Mat4MulMat34(cob.matrix, td->smtx, tmat);
1883 /* copy results from cob->matrix */
1885 TransDataIpokey *tdi= td->tdi;
1888 Mat4ToSize(cob.matrix, size);
1890 tdi->sizex[0]= size[0];
1891 tdi->sizey[0]= size[1];
1892 tdi->sizez[0]= size[2];
1894 else if ((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)) {
1895 /* scale val and reset size */
1896 return; // TODO: fix this case
1899 /* Reset val if SINGLESIZE but using a constraint */
1900 if (td->flag & TD_SINGLESIZE)
1903 Mat4ToSize(cob.matrix, td->ext->size);
1908 /* ************************** WARP *************************** */
1910 void initWarp(TransInfo *t)
1912 float max[3], min[3];
1916 t->transform = Warp;
1917 t->handleEvent = handleEventWarp;
1919 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_RATIO);
1927 t->flag |= T_NO_CONSTRAINT;
1929 /* we need min/max in view space */
1930 for(i = 0; i < t->total; i++) {
1932 VECCOPY(center, t->data[i].center);
1933 Mat3MulVecfl(t->data[i].mtx, center);
1934 Mat4MulVecfl(t->viewmat, center);
1935 VecSubf(center, center, t->viewmat[3]);
1937 MinMax3(min, max, center);
1939 VECCOPY(max, center);
1940 VECCOPY(min, center);
1944 t->center[0]= (min[0]+max[0])/2.0f;
1945 t->center[1]= (min[1]+max[1])/2.0f;
1946 t->center[2]= (min[2]+max[2])/2.0f;
1948 if (max[0] == min[0]) max[0] += 0.1; /* not optimal, but flipping is better than invalid garbage (i.e. division by zero!) */
1949 t->val= (max[0]-min[0])/2.0f; /* t->val is X dimension projected boundbox */
1952 int handleEventWarp(TransInfo *t, wmEvent *event)
1956 if (event->type == MIDDLEMOUSE && event->val==KM_PRESS)
1958 // Use customData pointer to signal warp direction
1959 if (t->customData == 0)
1960 t->customData = (void*)1;
1970 int Warp(TransInfo *t, short mval[2])
1972 TransData *td = t->data;
1973 float vec[3], circumfac, dist, phi0, co, si, *curs, cursor[3], gcursor[3];
1977 curs= give_cursor(t->scene, t->view);
1979 * gcursor is the one used for helpline.
1980 * It has to be in the same space as the drawing loop
1981 * (that means it needs to be in the object's space when in edit mode and
1982 * in global space in object mode)
1984 * cursor is used for calculations.
1985 * It needs to be in view space, but we need to take object's offset
1986 * into account if in Edit mode.
1988 VECCOPY(cursor, curs);
1989 VECCOPY(gcursor, cursor);
1990 if (t->flag & T_EDIT) {
1991 VecSubf(cursor, cursor, t->obedit->obmat[3]);
1992 VecSubf(gcursor, gcursor, t->obedit->obmat[3]);
1993 Mat3MulVecfl(t->data->smtx, gcursor);
1995 Mat4MulVecfl(t->viewmat, cursor);
1996 VecSubf(cursor, cursor, t->viewmat[3]);
1998 /* amount of degrees for warp */
1999 circumfac = 360.0f * t->values[0];
2001 if (t->customData) /* non-null value indicates reversed input */
2006 snapGrid(t, &circumfac);
2007 applyNumInput(&t->num, &circumfac);
2009 /* header print for NumInput */
2010 if (hasNumInput(&t->num)) {
2013 outputNumInput(&(t->num), c);
2015 sprintf(str, "Warp: %s", c);
2018 /* default header print */
2019 sprintf(str, "Warp: %.3f", circumfac);
2022 circumfac*= (float)(-M_PI/360.0);
2024 for(i = 0; i < t->total; i++, td++) {
2026 if (td->flag & TD_NOACTION)
2029 if (td->flag & TD_SKIP)
2032 /* translate point to center, rotate in such a way that outline==distance */
2033 VECCOPY(vec, td->iloc);
2034 Mat3MulVecfl(td->mtx, vec);
2035 Mat4MulVecfl(t->viewmat, vec);
2036 VecSubf(vec, vec, t->viewmat[3]);
2038 dist= vec[0]-cursor[0];
2040 /* t->val is X dimension projected boundbox */
2041 phi0= (circumfac*dist/t->val);
2043 vec[1]= (vec[1]-cursor[1]);
2045 co= (float)cos(phi0);
2046 si= (float)sin(phi0);
2047 loc[0]= -si*vec[1]+cursor[0];
2048 loc[1]= co*vec[1]+cursor[1];
2051 Mat4MulVecfl(t->viewinv, loc);
2052 VecSubf(loc, loc, t->viewinv[3]);
2053 Mat3MulVecfl(td->smtx, loc);
2055 VecSubf(loc, loc, td->iloc);
2056 VecMulf(loc, td->factor);
2057 VecAddf(td->loc, td->iloc, loc);
2062 ED_area_headerprint(t->sa, str);
2067 /* ************************** SHEAR *************************** */
2069 void initShear(TransInfo *t)
2071 t->mode = TFM_SHEAR;
2072 t->transform = Shear;
2073 t->handleEvent = handleEventShear;
2075 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_ABSOLUTE);
2081 t->snap[2] = t->snap[1] * 0.1f;
2083 t->flag |= T_NO_CONSTRAINT;
2086 int handleEventShear(TransInfo *t, wmEvent *event)
2090 if (event->type == MIDDLEMOUSE && event->val==KM_PRESS)
2092 // Use customData pointer to signal Shear direction
2093 if (t->customData == 0)
2095 initMouseInputMode(t, &t->mouse, INPUT_VERTICAL_ABSOLUTE);
2096 t->customData = (void*)1;
2100 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_ABSOLUTE);
2111 int Shear(TransInfo *t, short mval[2])
2113 TransData *td = t->data;
2115 float smat[3][3], tmat[3][3], totmat[3][3], persmat[3][3], persinv[3][3];
2120 Mat3CpyMat4(persmat, t->viewmat);
2121 Mat3Inv(persinv, persmat);
2123 value = 0.05f * t->values[0];
2125 snapGrid(t, &value);
2127 applyNumInput(&t->num, &value);
2129 /* header print for NumInput */
2130 if (hasNumInput(&t->num)) {
2133 outputNumInput(&(t->num), c);
2135 sprintf(str, "Shear: %s %s", c, t->proptext);
2138 /* default header print */
2139 sprintf(str, "Shear: %.3f %s", value, t->proptext);
2144 // Custom data signals shear direction
2145 if (t->customData == 0)
2150 Mat3MulMat3(tmat, smat, persmat);
2151 Mat3MulMat3(totmat, persinv, tmat);
2153 for(i = 0 ; i < t->total; i++, td++) {
2154 if (td->flag & TD_NOACTION)
2157 if (td->flag & TD_SKIP)
2162 Mat3MulMat3(mat3, totmat, td->mtx);
2163 Mat3MulMat3(tmat, td->smtx, mat3);
2166 Mat3CpyMat3(tmat, totmat);
2168 VecSubf(vec, td->center, t->center);
2170 Mat3MulVecfl(tmat, vec);
2172 VecAddf(vec, vec, t->center);
2173 VecSubf(vec, vec, td->center);
2175 VecMulf(vec, td->factor);
2177 VecAddf(td->loc, td->iloc, vec);
2182 ED_area_headerprint(t->sa, str);
2187 /* ************************** RESIZE *************************** */
2189 void initResize(TransInfo *t)
2191 t->mode = TFM_RESIZE;
2192 t->transform = Resize;
2194 initMouseInputMode(t, &t->mouse, INPUT_SPRING_FLIP);
2196 t->flag |= T_NULL_ONE;
2197 t->num.flag |= NUM_NULL_ONE;
2198 t->num.flag |= NUM_AFFECT_ALL;
2200 t->flag |= T_NO_ZERO;
2201 t->num.flag |= NUM_NO_ZERO;
2208 t->snap[2] = t->snap[1] * 0.1f;
2211 static void headerResize(TransInfo *t, float vec[3], char *str) {
2213 if (hasNumInput(&t->num)) {
2214 outputNumInput(&(t->num), tvec);
2217 sprintf(&tvec[0], "%.4f", vec[0]);
2218 sprintf(&tvec[20], "%.4f", vec[1]);
2219 sprintf(&tvec[40], "%.4f", vec[2]);
2222 if (t->con.mode & CON_APPLY) {
2223 switch(t->num.idx_max) {
2225 sprintf(str, "Scale: %s%s %s", &tvec[0], t->con.text, t->proptext);
2228 sprintf(str, "Scale: %s : %s%s %s", &tvec[0], &tvec[20], t->con.text, t->proptext);
2231 sprintf(str, "Scale: %s : %s : %s%s %s", &tvec[0], &tvec[20], &tvec[40], t->con.text, t->proptext);
2235 if (t->flag & T_2D_EDIT)
2236 sprintf(str, "Scale X: %s Y: %s%s %s", &tvec[0], &tvec[20], t->con.text, t->proptext);
2238 sprintf(str, "Scale X: %s Y: %s Z: %s%s %s", &tvec[0], &tvec[20], &tvec[40], t->con.text, t->proptext);
2242 #define SIGN(a) (a<-FLT_EPSILON?1:a>FLT_EPSILON?2:3)
2243 #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)
2245 /* smat is reference matrix, only scaled */
2246 static void TransMat3ToSize( float mat[][3], float smat[][3], float *size)
2250 VecCopyf(vec, mat[0]);
2251 size[0]= Normalize(vec);
2252 VecCopyf(vec, mat[1]);
2253 size[1]= Normalize(vec);
2254 VecCopyf(vec, mat[2]);
2255 size[2]= Normalize(vec);
2257 /* first tried with dotproduct... but the sign flip is crucial */
2258 if( VECSIGNFLIP(mat[0], smat[0]) ) size[0]= -size[0];
2259 if( VECSIGNFLIP(mat[1], smat[1]) ) size[1]= -size[1];
2260 if( VECSIGNFLIP(mat[2], smat[2]) ) size[2]= -size[2];
2264 static void ElementResize(TransInfo *t, TransData *td, float mat[3][3]) {
2265 float tmat[3][3], smat[3][3], center[3];
2268 if (t->flag & T_EDIT) {
2269 Mat3MulMat3(smat, mat, td->mtx);
2270 Mat3MulMat3(tmat, td->smtx, smat);
2273 Mat3CpyMat3(tmat, mat);
2276 if (t->con.applySize) {
2277 t->con.applySize(t, td, tmat);
2280 /* local constraint shouldn't alter center */
2281 if (t->around == V3D_LOCAL) {
2282 if (t->flag & T_OBJECT) {
2283 VECCOPY(center, td->center);
2285 else if (t->flag & T_EDIT) {
2287 if(t->around==V3D_LOCAL && (t->settings->selectmode & SCE_SELECT_FACE)) {
2288 VECCOPY(center, td->center);
2291 VECCOPY(center, t->center);
2295 VECCOPY(center, t->center);
2299 VECCOPY(center, t->center);
2305 if (t->flag & (T_OBJECT|T_TEXTURE|T_POSE)) {
2306 float obsizemat[3][3];
2307 // Reorient the size mat to fit the oriented object.
2308 Mat3MulMat3(obsizemat, tmat, td->axismtx);
2309 //printmatrix3("obsizemat", obsizemat);
2310 TransMat3ToSize(obsizemat, td->axismtx, fsize);
2311 //printvecf("fsize", fsize);
2314 Mat3ToSize(tmat, fsize);
2317 protectedSizeBits(td->protectflag, fsize);
2319 if ((t->flag & T_V3D_ALIGN)==0) { // align mode doesn't resize objects itself
2320 /* handle ipokeys? */
2322 TransDataIpokey *tdi= td->tdi;
2323 /* calculate delta size (equal for size and dsize) */
2325 vec[0]= (tdi->oldsize[0])*(fsize[0] -1.0f) * td->factor;
2326 vec[1]= (tdi->oldsize[1])*(fsize[1] -1.0f) * td->factor;
2327 vec[2]= (tdi->oldsize[2])*(fsize[2] -1.0f) * td->factor;
2329 add_tdi_poin(tdi->sizex, tdi->oldsize, vec[0]);
2330 add_tdi_poin(tdi->sizey, tdi->oldsize+1, vec[1]);
2331 add_tdi_poin(tdi->sizez, tdi->oldsize+2, vec[2]);
2334 else if((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)){
2335 /* scale val and reset size */
2336 *td->val = td->ival * fsize[0] * td->factor;
2338 td->ext->size[0] = td->ext->isize[0];
2339 td->ext->size[1] = td->ext->isize[1];
2340 td->ext->size[2] = td->ext->isize[2];
2343 /* Reset val if SINGLESIZE but using a constraint */
2344 if (td->flag & TD_SINGLESIZE)
2345 *td->val = td->ival;
2347 td->ext->size[0] = td->ext->isize[0] * (fsize[0]) * td->factor;
2348 td->ext->size[1] = td->ext->isize[1] * (fsize[1]) * td->factor;
2349 td->ext->size[2] = td->ext->isize[2] * (fsize[2]) * td->factor;
2353 constraintSizeLim(t, td);
2356 /* For individual element center, Editmode need to use iloc */
2357 if (t->flag & T_POINTS)
2358 VecSubf(vec, td->iloc, center);
2360 VecSubf(vec, td->center, center);
2362 Mat3MulVecfl(tmat, vec);
2364 VecAddf(vec, vec, center);
2365 if (t->flag & T_POINTS)
2366 VecSubf(vec, vec, td->iloc);
2368 VecSubf(vec, vec, td->center);
2370 VecMulf(vec, td->factor);
2372 if (t->flag & (T_OBJECT|T_POSE)) {
2373 Mat3MulVecfl(td->smtx, vec);
2376 protectedTransBits(td->protectflag, vec);
2379 TransDataIpokey *tdi= td->tdi;
2380 add_tdi_poin(tdi->locx, tdi->oldloc, vec[0]);
2381 add_tdi_poin(tdi->locy, tdi->oldloc+1, vec[1]);
2382 add_tdi_poin(tdi->locz, tdi->oldloc+2, vec[2]);
2384 else VecAddf(td->loc, td->iloc, vec);
2386 constraintTransLim(t, td);
2389 int Resize(TransInfo *t, short mval[2])
2392 float size[3], mat[3][3];
2397 /* for manipulator, center handle, the scaling can't be done relative to center */
2398 if( (t->flag & T_USES_MANIPULATOR) && t->con.mode==0)
2400 ratio = 1.0f - ((t->imval[0] - mval[0]) + (t->imval[1] - mval[1]))/100.0f;
2404 ratio = t->values[0];
2407 size[0] = size[1] = size[2] = ratio;
2411 if (hasNumInput(&t->num)) {
2412 applyNumInput(&t->num, size);
2413 constraintNumInput(t, size);
2416 applySnapping(t, size);
2418 if (t->flag & T_AUTOVALUES)
2420 VECCOPY(size, t->auto_values);
2423 VECCOPY(t->values, size);
2425 SizeToMat3(size, mat);
2427 if (t->con.applySize) {
2428 t->con.applySize(t, NULL, mat);
2431 Mat3CpyMat3(t->mat, mat); // used in manipulator
2433 headerResize(t, size, str);
2435 for(i = 0, td=t->data; i < t->total; i++, td++) {
2436 if (td->flag & TD_NOACTION)
2439 if (td->flag & TD_SKIP)
2442 ElementResize(t, td, mat);
2445 /* evil hack - redo resize if cliping needed */
2446 if (t->flag & T_CLIP_UV && clipUVTransform(t, size, 1)) {
2447 SizeToMat3(size, mat);
2449 if (t->con.applySize)
2450 t->con.applySize(t, NULL, mat);
2452 for(i = 0, td=t->data; i < t->total; i++, td++)
2453 ElementResize(t, td, mat);
2458 ED_area_headerprint(t->sa, str);
2463 /* ************************** TOSPHERE *************************** */
2465 void initToSphere(TransInfo *t)
2467 TransData *td = t->data;
2470 t->mode = TFM_TOSPHERE;
2471 t->transform = ToSphere;
2473 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_RATIO);
2479 t->snap[2] = t->snap[1] * 0.1f;
2481 t->num.flag |= NUM_NULL_ONE | NUM_NO_NEGATIVE;
2482 t->flag |= T_NO_CONSTRAINT;
2484 // Calculate average radius
2485 for(i = 0 ; i < t->total; i++, td++) {
2486 t->val += VecLenf(t->center, td->iloc);
2489 t->val /= (float)t->total;
2492 int ToSphere(TransInfo *t, short mval[2])
2495 float ratio, radius;
2498 TransData *td = t->data;
2500 ratio = t->values[0];
2502 snapGrid(t, &ratio);
2504 applyNumInput(&t->num, &ratio);
2511 /* header print for NumInput */
2512 if (hasNumInput(&t->num)) {
2515 outputNumInput(&(t->num), c);
2517 sprintf(str, "To Sphere: %s %s", c, t->proptext);
2520 /* default header print */
2521 sprintf(str, "To Sphere: %.4f %s", ratio, t->proptext);
2525 for(i = 0 ; i < t->total; i++, td++) {
2527 if (td->flag & TD_NOACTION)
2530 if (td->flag & TD_SKIP)
2533 VecSubf(vec, td->iloc, t->center);
2535 radius = Normalize(vec);
2537 tratio = ratio * td->factor;
2539 VecMulf(vec, radius * (1.0f - tratio) + t->val * tratio);
2541 VecAddf(td->loc, t->center, vec);
2547 ED_area_headerprint(t->sa, str);
2552 /* ************************** ROTATION *************************** */
2555 void initRotation(TransInfo *t)
2557 t->mode = TFM_ROTATION;
2558 t->transform = Rotation;
2560 initMouseInputMode(t, &t->mouse, INPUT_ANGLE);
2563 /* Scale down and flip input for rotation */
2564 t->ndof.factor[0] = -0.2f;
2569 t->snap[1] = (float)((5.0/180)*M_PI);
2570 t->snap[2] = t->snap[1] * 0.2f;
2572 if (t->flag & T_2D_EDIT)
2573 t->flag |= T_NO_CONSTRAINT;
2576 static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short around) {
2577 float vec[3], totmat[3][3], smat[3][3];
2578 float eul[3], fmat[3][3], quat[4];
2579 float *center = t->center;
2581 /* local constraint shouldn't alter center */
2582 if (around == V3D_LOCAL) {
2583 if (t->flag & (T_OBJECT|T_POSE)) {
2584 center = td->center;
2587 /* !TODO! Make this if not rely on G */
2588 if(around==V3D_LOCAL && (t->settings->selectmode & SCE_SELECT_FACE)) {
2589 center = td->center;
2594 if (t->flag & T_POINTS) {
2595 Mat3MulMat3(totmat, mat, td->mtx);
2596 Mat3MulMat3(smat, td->smtx, totmat);
2598 VecSubf(vec, td->iloc, center);
2599 Mat3MulVecfl(smat, vec);
2601 VecAddf(td->loc, vec, center);
2603 VecSubf(vec,td->loc,td->iloc);
2604 protectedTransBits(td->protectflag, vec);
2605 VecAddf(td->loc, td->iloc, vec);
2607 if(td->flag & TD_USEQUAT) {
2608 Mat3MulSerie(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0);
2609 Mat3ToQuat(fmat, quat); // Actual transform
2612 QuatMul(td->ext->quat, quat, td->ext->iquat);
2614 /* is there a reason not to have this here? -jahka */
2615 protectedQuaternionBits(td->protectflag, td->ext->quat, td->ext->iquat);
2622 * This is some VERY ugly special case to deal with pose mode.
2624 * The problem is that mtx and smtx include each bone orientation.
2626 * That is needed to rotate each bone properly, HOWEVER, to calculate
2627 * the translation component, we only need the actual armature object's
2628 * matrix (and inverse). That is not all though. Once the proper translation
2629 * has been computed, it has to be converted back into the bone's space.
2631 else if (t->flag & T_POSE) {
2632 float pmtx[3][3], imtx[3][3];
2634 // Extract and invert armature object matrix
2635 Mat3CpyMat4(pmtx, t->poseobj->obmat);
2636 Mat3Inv(imtx, pmtx);
2638 if ((td->flag & TD_NO_LOC) == 0)
2640 VecSubf(vec, td->center, center);
2642 Mat3MulVecfl(pmtx, vec); // To Global space
2643 Mat3MulVecfl(mat, vec); // Applying rotation
2644 Mat3MulVecfl(imtx, vec); // To Local space
2646 VecAddf(vec, vec, center);
2647 /* vec now is the location where the object has to be */
2649 VecSubf(vec, vec, td->center); // Translation needed from the initial location
2651 Mat3MulVecfl(pmtx, vec); // To Global space
2652 Mat3MulVecfl(td->smtx, vec);// To Pose space
2654 protectedTransBits(td->protectflag, vec);
2656 VecAddf(td->loc, td->iloc, vec);
2658 constraintTransLim(t, td);
2662 if ((t->flag & T_V3D_ALIGN)==0) { // align mode doesn't rotate objects itself
2663 /* euler or quaternion? */
2664 if (td->flag & TD_USEQUAT) {
2665 Mat3MulSerie(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0);
2667 Mat3ToQuat(fmat, quat); // Actual transform
2669 QuatMul(td->ext->quat, quat, td->ext->iquat);
2670 /* this function works on end result */
2671 protectedQuaternionBits(td->protectflag, td->ext->quat, td->ext->iquat);
2676 Mat3MulMat3(totmat, mat, td->mtx);
2677 Mat3MulMat3(smat, td->smtx, totmat);
2679 /* calculate the total rotatation in eulers */
2680 VECCOPY(eul, td->ext->irot);
2681 EulOToMat3(eul, td->rotOrder, eulmat);
2683 /* mat = transform, obmat = bone rotation */
2684 Mat3MulMat3(fmat, smat, eulmat);
2686 Mat3ToCompatibleEulO(fmat, eul, td->ext->rot, td->rotOrder);
2688 /* and apply (to end result only) */
2689 protectedRotateBits(td->protectflag, eul, td->ext->irot);
2690 VECCOPY(td->ext->rot, eul);
2693 constraintRotLim(t, td);
2697 if ((td->flag & TD_NO_LOC) == 0)
2700 VecSubf(vec, td->center, center);
2701 Mat3MulVecfl(mat, vec);
2702 VecAddf(vec, vec, center);
2703 /* vec now is the location where the object has to be */
2704 VecSubf(vec, vec, td->center);
2705 Mat3MulVecfl(td->smtx, vec);
2707 protectedTransBits(td->protectflag, vec);
2710 TransDataIpokey *tdi= td->tdi;
2711 add_tdi_poin(tdi->locx, tdi->oldloc, vec[0]);
2712 add_tdi_poin(tdi->locy, tdi->oldloc+1, vec[1]);
2713 add_tdi_poin(tdi->locz, tdi->oldloc+2, vec[2]);
2715 else VecAddf(td->loc, td->iloc, vec);
2719 constraintTransLim(t, td);
2722 if ((t->flag & T_V3D_ALIGN)==0) { // align mode doesn't rotate objects itself
2723 /* euler or quaternion? */
2724 if (td->flag & TD_USEQUAT) {
2725 Mat3MulSerie(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0);
2726 Mat3ToQuat(fmat, quat); // Actual transform
2728 QuatMul(td->ext->quat, quat, td->ext->iquat);
2729 /* this function works on end result */
2730 protectedQuaternionBits(td->protectflag, td->ext->quat, td->ext->iquat);
2735 /* are there ipo keys? */
2737 TransDataIpokey *tdi= td->tdi;
2738 float current_rot[3];
2741 /* current IPO value for compatible euler */
2742 current_rot[0] = (tdi->rotx) ? tdi->rotx[0] : 0.0f;
2743 current_rot[1] = (tdi->roty) ? tdi->roty[0] : 0.0f;
2744 current_rot[2] = (tdi->rotz) ? tdi->rotz[0] : 0.0f;
2745 VecMulf(current_rot, (float)(M_PI_2 / 9.0));
2747 /* calculate the total rotatation in eulers */
2748 VecAddf(eul, td->ext->irot, td->ext->drot);
2749 EulToMat3(eul, obmat);
2750 /* mat = transform, obmat = object rotation */
2751 Mat3MulMat3(fmat, mat, obmat);
2753 Mat3ToCompatibleEul(fmat, eul, current_rot);
2755 /* correct back for delta rot */
2756 if(tdi->flag & TOB_IPODROT) {
2757 VecSubf(rot, eul, td->ext->irot);
2760 VecSubf(rot, eul, td->ext->drot);
2763 VecMulf(rot, (float)(9.0/M_PI_2));
2764 VecSubf(rot, rot, tdi->oldrot);
2766 protectedRotateBits(td->protectflag, rot, tdi->oldrot);
2768 add_tdi_poin(tdi->rotx, tdi->oldrot, rot[0]);
2769 add_tdi_poin(tdi->roty, tdi->oldrot+1, rot[1]);
2770 add_tdi_poin(tdi->rotz, tdi->oldrot+2, rot[2]);
2773 Mat3MulMat3(totmat, mat, td->mtx);
2774 Mat3MulMat3(smat, td->smtx, totmat);
2776 /* calculate the total rotatation in eulers */
2777 VecAddf(eul, td->ext->irot, td->ext->drot); /* we have to correct for delta rot */
2778 EulToMat3(eul, obmat);
2779 /* mat = transform, obmat = object rotation */
2780 Mat3MulMat3(fmat, smat, obmat);
2782 Mat3ToCompatibleEul(fmat, eul, td->ext->rot);
2784 /* correct back for delta rot */
2785 VecSubf(eul, eul, td->ext->drot);
2788 protectedRotateBits(td->protectflag, eul, td->ext->irot);
2789 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 VecRotToMat3(axis, angle, mat);
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 VecRotToMat3(axis, angle * td->factor, mat);
2818 else if (t->flag & T_PROP_EDIT) {
2819 VecRotToMat3(axis, angle * td->factor, mat);
2822 ElementRotation(t, td, mat, t->around);
2826 int Rotation(TransInfo *t, short mval[2])
2835 VECCOPY(axis, t->viewinv[2]);
2836 VecMulf(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 VecRotToMat3(axis, final, mat);
2876 // t->values[0] = final; // used in manipulator
2877 // Mat3CpyMat3(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];
2918 VecRotToMat3(axis1, angles[0], smat);
2919 VecRotToMat3(axis2, angles[1], totmat);
2921 Mat3MulMat3(mat, smat, totmat);
2923 for(i = 0 ; i < t->total; i++, td++) {
2924 if (td->flag & TD_NOACTION)
2927 if (td->flag & TD_SKIP)
2930 if (t->flag & T_PROP_EDIT) {
2931 VecRotToMat3(axis1, td->factor * angles[0], smat);
2932 VecRotToMat3(axis2, td->factor * angles[1], totmat);
2934 Mat3MulMat3(mat, smat, totmat);
2937 ElementRotation(t, td, mat, t->around);
2941 int Trackball(TransInfo *t, short mval[2])
2944 float axis1[3], axis2[3];
2945 float mat[3][3], totmat[3][3], smat[3][3];
2948 VECCOPY(axis1, t->persinv[0]);
2949 VECCOPY(axis2, t->persinv[1]);
2953 phi[0] = t->values[0];
2954 phi[1] = t->values[1];
2956 applyNDofInput(&t->ndof, phi);
2960 if (hasNumInput(&t->num)) {
2963 applyNumInput(&t->num, phi);
2965 outputNumInput(&(t->num), c);
2967 sprintf(str, "Trackball: %s %s %s", &c[0], &c[20], t->proptext);
2969 phi[0] *= (float)(M_PI / 180.0);
2970 phi[1] *= (float)(M_PI / 180.0);
2973 sprintf(str, "Trackball: %.2f %.2f %s", 180.0*phi[0]/M_PI, 180.0*phi[1]/M_PI, t->proptext);
2976 VecRotToMat3(axis1, phi[0], smat);
2977 VecRotToMat3(axis2, phi[1], totmat);
2979 Mat3MulMat3(mat, smat, totmat);