4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21 * All rights reserved.
23 * The Original Code is: all of this file.
25 * Contributor(s): none yet.
27 * ***** END GPL LICENSE BLOCK *****
46 #include "MEM_guardedalloc.h"
48 #include "DNA_anim_types.h"
49 #include "DNA_armature_types.h"
50 #include "DNA_action_types.h" /* for some special action-editor settings */
51 #include "DNA_constraint_types.h"
52 #include "DNA_ipo_types.h" /* some silly ipo flag */
53 #include "DNA_listBase.h"
54 #include "DNA_meshdata_types.h"
55 #include "DNA_mesh_types.h"
56 #include "DNA_object_types.h"
57 #include "DNA_scene_types.h" /* PET modes */
58 #include "DNA_screen_types.h" /* area dimensions */
59 #include "DNA_texture_types.h"
60 #include "DNA_userdef_types.h"
61 #include "DNA_view3d_types.h"
62 #include "DNA_space_types.h"
63 #include "DNA_windowmanager_types.h"
65 #include "RNA_access.h"
67 //#include "BIF_editview.h" /* arrows_move_cursor */
69 #include "BIF_glutil.h"
70 //#include "BIF_mywindow.h"
71 //#include "BIF_resources.h"
72 //#include "BIF_screen.h"
73 //#include "BIF_space.h" /* undo */
74 //#include "BIF_toets.h" /* persptoetsen */
75 //#include "BIF_mywindow.h" /* warp_pointer */
76 //#include "BIF_toolbox.h" /* notice */
77 //#include "BIF_editmesh.h"
78 //#include "BIF_editsima.h"
79 //#include "BIF_editparticle.h"
81 #include "BKE_action.h"
83 //#include "BKE_bad_level_calls.h"/* popmenu and error */
84 #include "BKE_bmesh.h"
85 #include "BKE_context.h"
86 #include "BKE_constraint.h"
87 #include "BKE_global.h"
88 #include "BKE_particle.h"
89 #include "BKE_pointcache.h"
90 #include "BKE_utildefines.h"
91 #include "BKE_context.h"
94 //#include "BSE_view.h"
97 #include "ED_keyframing.h"
98 #include "ED_screen.h"
99 #include "ED_space_api.h"
100 #include "ED_markers.h"
102 #include "ED_view3d.h"
105 #include "UI_view2d.h"
106 #include "WM_types.h"
109 #include "BLI_arithb.h"
110 #include "BLI_blenlib.h"
111 #include "BLI_editVert.h"
112 #include "BLI_ghash.h"
113 #include "BLI_linklist.h"
115 #include "PIL_time.h" /* sleep */
117 #include "UI_resources.h"
119 //#include "blendef.h"
121 //#include "mydevice.h"
123 #include "transform.h"
125 /* ************************** SPACE DEPENDANT CODE **************************** */
127 void setTransformViewMatrices(TransInfo *t)
129 if(t->spacetype==SPACE_VIEW3D && t->ar->regiontype == RGN_TYPE_WINDOW) {
130 RegionView3D *rv3d = t->ar->regiondata;
132 Mat4CpyMat4(t->viewmat, rv3d->viewmat);
133 Mat4CpyMat4(t->viewinv, rv3d->viewinv);
134 Mat4CpyMat4(t->persmat, rv3d->persmat);
135 Mat4CpyMat4(t->persinv, rv3d->persinv);
136 t->persp = rv3d->persp;
143 t->persp = V3D_ORTHO;
146 calculateCenter2D(t);
149 void convertViewVec(TransInfo *t, float *vec, short dx, short dy)
151 if (t->spacetype==SPACE_VIEW3D) {
152 if (t->ar->regiontype == RGN_TYPE_WINDOW)
154 window_to_3d_delta(t->ar, vec, dx, dy);
157 else if(t->spacetype==SPACE_IMAGE) {
158 View2D *v2d = t->view;
159 float divx, divy, aspx, aspy;
161 ED_space_image_uv_aspect(t->sa->spacedata.first, &aspx, &aspy);
163 divx= v2d->mask.xmax-v2d->mask.xmin;
164 divy= v2d->mask.ymax-v2d->mask.ymin;
166 vec[0]= aspx*(v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx;
167 vec[1]= aspy*(v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy;
170 else if(ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)) {
171 View2D *v2d = t->view;
174 divx= v2d->mask.xmax-v2d->mask.xmin;
175 divy= v2d->mask.ymax-v2d->mask.ymin;
177 vec[0]= (v2d->cur.xmax-v2d->cur.xmin)*(dx) / (divx);
178 vec[1]= (v2d->cur.ymax-v2d->cur.ymin)*(dy) / (divy);
181 else if(t->spacetype==SPACE_NODE) {
182 View2D *v2d = &t->ar->v2d;
185 divx= v2d->mask.xmax-v2d->mask.xmin;
186 divy= v2d->mask.ymax-v2d->mask.ymin;
188 vec[0]= (v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx;
189 vec[1]= (v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy;
192 else if(t->spacetype==SPACE_SEQ) {
193 View2D *v2d = &t->ar->v2d;
196 divx= v2d->mask.xmax-v2d->mask.xmin;
197 divy= v2d->mask.ymax-v2d->mask.ymin;
199 vec[0]= (v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx;
200 vec[1]= (v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy;
205 void projectIntView(TransInfo *t, float *vec, int *adr)
207 if (t->spacetype==SPACE_VIEW3D) {
208 if(t->ar->regiontype == RGN_TYPE_WINDOW)
209 project_int_noclip(t->ar, vec, adr);
211 else if(t->spacetype==SPACE_IMAGE) {
212 float aspx, aspy, v[2];
214 ED_space_image_uv_aspect(t->sa->spacedata.first, &aspx, &aspy);
218 UI_view2d_to_region_no_clip(t->view, v[0], v[1], adr, adr+1);
220 else if(ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)) {
223 UI_view2d_view_to_region((View2D *)t->view, vec[0], vec[1], out, out+1);
227 else if(t->spacetype==SPACE_SEQ) { /* XXX not tested yet, but should work */
230 UI_view2d_view_to_region((View2D *)t->view, vec[0], vec[1], out, out+1);
236 void projectFloatView(TransInfo *t, float *vec, float *adr)
238 if (t->spacetype==SPACE_VIEW3D) {
239 if(t->ar->regiontype == RGN_TYPE_WINDOW)
240 project_float_noclip(t->ar, vec, adr);
242 else if(t->spacetype==SPACE_IMAGE) {
245 projectIntView(t, vec, a);
249 else if(ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)) {
252 projectIntView(t, vec, a);
258 void applyAspectRatio(TransInfo *t, float *vec)
260 SpaceImage *sima= t->sa->spacedata.first;
262 if ((t->spacetype==SPACE_IMAGE) && (t->mode==TFM_TRANSLATION)) {
265 if((sima->flag & SI_COORDFLOATS)==0) {
267 ED_space_image_size(sima, &width, &height);
273 ED_space_image_uv_aspect(sima, &aspx, &aspy);
279 void removeAspectRatio(TransInfo *t, float *vec)
281 SpaceImage *sima= t->sa->spacedata.first;
283 if ((t->spacetype==SPACE_IMAGE) && (t->mode==TFM_TRANSLATION)) {
286 if((sima->flag & SI_COORDFLOATS)==0) {
288 ED_space_image_size(sima, &width, &height);
294 ED_space_image_uv_aspect(sima, &aspx, &aspy);
300 static void viewRedrawForce(bContext *C, TransInfo *t)
302 if (t->spacetype == SPACE_VIEW3D)
304 /* Do we need more refined tags? */
305 WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
307 /* for realtime animation record - send notifiers recognised by animation editors */
308 if ((t->animtimer) && IS_AUTOKEY_ON(t->scene))
309 WM_event_add_notifier(C, NC_OBJECT|ND_KEYS, NULL);
311 else if (t->spacetype == SPACE_ACTION) {
312 //SpaceAction *saction= (SpaceAction *)t->sa->spacedata.first;
313 WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME_EDIT, NULL);
315 else if (t->spacetype == SPACE_IPO) {
316 //SpaceIpo *sipo= (SpaceIpo *)t->sa->spacedata.first;
317 WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME_EDIT, NULL);
319 else if (t->spacetype == SPACE_NLA) {
320 WM_event_add_notifier(C, NC_ANIMATION|ND_NLA_EDIT, NULL);
322 else if(t->spacetype == SPACE_NODE)
324 //ED_area_tag_redraw(t->sa);
325 WM_event_add_notifier(C, NC_SCENE|ND_NODES, NULL);
327 else if(t->spacetype == SPACE_SEQ)
329 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, NULL);
331 else if (t->spacetype==SPACE_IMAGE) {
332 // XXX how to deal with lock?
334 SpaceImage *sima= (SpaceImage*)t->sa->spacedata.first;
335 if(sima->lock) force_draw_plus(SPACE_VIEW3D, 0);
339 WM_event_add_notifier(C, NC_GEOM|ND_DATA, t->obedit->data);
343 static void viewRedrawPost(TransInfo *t)
345 ED_area_headerprint(t->sa, NULL);
347 #if 0 // TRANSFORM_FIX_ME
348 if(t->spacetype==SPACE_VIEW3D) {
349 allqueue(REDRAWBUTSOBJECT, 0);
350 allqueue(REDRAWVIEW3D, 0);
352 else if(t->spacetype==SPACE_IMAGE) {
353 allqueue(REDRAWIMAGE, 0);
354 allqueue(REDRAWVIEW3D, 0);
356 else if(ELEM3(t->spacetype, SPACE_ACTION, SPACE_NLA, SPACE_IPO)) {
357 allqueue(REDRAWVIEW3D, 0);
358 allqueue(REDRAWACTION, 0);
359 allqueue(REDRAWNLA, 0);
360 allqueue(REDRAWIPO, 0);
361 allqueue(REDRAWTIME, 0);
362 allqueue(REDRAWBUTSOBJECT, 0);
365 scrarea_queue_headredraw(curarea);
369 /* ************************** TRANSFORMATIONS **************************** */
371 void BIF_selectOrientation() {
372 #if 0 // TRANSFORM_FIX_ME
374 char *str_menu = BIF_menustringTransformOrientation("Orientation");
375 val= pupmenu(str_menu);
384 static void view_editmove(unsigned short event)
386 #if 0 // TRANSFORM_FIX_ME
388 /* Regular: Zoom in */
389 /* Shift: Scroll up */
390 /* Ctrl: Scroll right */
391 /* Alt-Shift: Rotate up */
392 /* Alt-Ctrl: Rotate right */
394 /* only work in 3D window for now
395 * In the end, will have to send to event to a 2D window handler instead
397 if (Trans.flag & T_2D_EDIT)
403 if( G.qual & LR_SHIFTKEY ) {
404 if( G.qual & LR_ALTKEY ) {
405 G.qual &= ~LR_SHIFTKEY;
407 G.qual |= LR_SHIFTKEY;
411 } else if( G.qual & LR_CTRLKEY ) {
412 if( G.qual & LR_ALTKEY ) {
413 G.qual &= ~LR_CTRLKEY;
415 G.qual |= LR_CTRLKEY;
419 } else if(U.uiflag & USER_WHEELZOOMDIR)
420 persptoetsen(PADMINUS);
422 persptoetsen(PADPLUSKEY);
427 if( G.qual & LR_SHIFTKEY ) {
428 if( G.qual & LR_ALTKEY ) {
429 G.qual &= ~LR_SHIFTKEY;
431 G.qual |= LR_SHIFTKEY;
435 } else if( G.qual & LR_CTRLKEY ) {
436 if( G.qual & LR_ALTKEY ) {
437 G.qual &= ~LR_CTRLKEY;
439 G.qual |= LR_CTRLKEY;
443 } else if(U.uiflag & USER_WHEELZOOMDIR)
444 persptoetsen(PADPLUSKEY);
446 persptoetsen(PADMINUS);
453 setTransformViewMatrices(&Trans);
458 static char *transform_to_undostr(TransInfo *t)
461 case TFM_TRANSLATION:
473 case TFM_SHRINKFATTEN:
474 return "Shrink/Fatten";
484 return "Bevel Weight";
489 case TFM_BONE_ENVELOPE:
490 return "Bone Envelope";
491 case TFM_TIME_TRANSLATE:
492 return "Translate Anim. Data";
494 return "Scale Anim. Data";
506 /* ************************************************* */
508 /* NOTE: these defines are saved in keymap files, do not change values but just add new ones */
509 #define TFM_MODAL_CANCEL 1
510 #define TFM_MODAL_CONFIRM 2
511 #define TFM_MODAL_TRANSLATE 3
512 #define TFM_MODAL_ROTATE 4
513 #define TFM_MODAL_RESIZE 5
514 #define TFM_MODAL_SNAP_GEARS 6
515 #define TFM_MODAL_SNAP_GEARS_OFF 7
517 /* called in transform_ops.c, on each regeneration of keymaps */
518 void transform_modal_keymap(wmWindowManager *wm)
520 static EnumPropertyItem modal_items[] = {
521 {TFM_MODAL_CANCEL, "CANCEL", 0, "Cancel", ""},
522 {TFM_MODAL_CONFIRM, "CONFIRM", 0, "Confirm", ""},
523 {TFM_MODAL_TRANSLATE, "TRANSLATE", 0, "Translate", ""},
524 {TFM_MODAL_ROTATE, "ROTATE", 0, "Rotate", ""},
525 {TFM_MODAL_RESIZE, "RESIZE", 0, "Resize", ""},
526 {TFM_MODAL_SNAP_GEARS, "SNAP_GEARS", 0, "Snap On", ""},
527 {TFM_MODAL_SNAP_GEARS_OFF, "SNAP_GEARS_OFF", 0, "Snap Off", ""},
528 {0, NULL, 0, NULL, NULL}};
530 wmKeyMap *keymap= WM_modalkeymap_get(wm, "Transform Modal Map");
532 /* this function is called for each spacetype, only needs to add map once */
535 keymap= WM_modalkeymap_add(wm, "Transform Modal Map", modal_items);
537 /* items for modal map */
538 WM_modalkeymap_add_item(keymap, ESCKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_CANCEL);
539 WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_ANY, KM_ANY, 0, TFM_MODAL_CONFIRM);
540 WM_modalkeymap_add_item(keymap, RETKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_CONFIRM);
541 WM_modalkeymap_add_item(keymap, PADENTER, KM_PRESS, KM_ANY, 0, TFM_MODAL_CONFIRM);
543 WM_modalkeymap_add_item(keymap, GKEY, KM_PRESS, 0, 0, TFM_MODAL_TRANSLATE);
544 WM_modalkeymap_add_item(keymap, RKEY, KM_PRESS, 0, 0, TFM_MODAL_ROTATE);
545 WM_modalkeymap_add_item(keymap, SKEY, KM_PRESS, 0, 0, TFM_MODAL_RESIZE);
547 WM_modalkeymap_add_item(keymap, LEFTCTRLKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_SNAP_GEARS);
548 WM_modalkeymap_add_item(keymap, LEFTCTRLKEY, KM_RELEASE, KM_ANY, 0, TFM_MODAL_SNAP_GEARS_OFF);
550 /* assign map to operators */
551 WM_modalkeymap_assign(keymap, "TFM_OT_transform");
552 WM_modalkeymap_assign(keymap, "TFM_OT_translate");
553 WM_modalkeymap_assign(keymap, "TFM_OT_rotate");
554 WM_modalkeymap_assign(keymap, "TFM_OT_tosphere");
555 WM_modalkeymap_assign(keymap, "TFM_OT_resize");
556 WM_modalkeymap_assign(keymap, "TFM_OT_shear");
557 WM_modalkeymap_assign(keymap, "TFM_OT_warp");
558 WM_modalkeymap_assign(keymap, "TFM_OT_shrink_fatten");
559 WM_modalkeymap_assign(keymap, "TFM_OT_tilt");
560 WM_modalkeymap_assign(keymap, "TFM_OT_trackball");
565 void transformEvent(TransInfo *t, wmEvent *event)
567 float mati[3][3] = {{1.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 1.0f}};
568 char cmode = constraintModeToChar(t);
570 t->redraw |= handleMouseInput(t, &t->mouse, event);
572 if (event->type == MOUSEMOVE)
574 t->mval[0] = event->x - t->ar->winrct.xmin;
575 t->mval[1] = event->y - t->ar->winrct.ymin;
579 applyMouseInput(t, &t->mouse, t->mval, t->values);
582 /* handle modal keymap first */
583 if (event->type == EVT_MODAL_MAP) {
584 switch (event->val) {
585 case TFM_MODAL_CANCEL:
586 t->state = TRANS_CANCEL;
588 case TFM_MODAL_CONFIRM:
589 t->state = TRANS_CONFIRM;
592 case TFM_MODAL_TRANSLATE:
593 /* only switch when... */
594 if( ELEM3(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL) ) {
595 resetTransRestrictions(t);
596 restoreTransObjects(t);
598 initSnapping(t, NULL); // need to reinit after mode change
602 case TFM_MODAL_ROTATE:
603 /* only switch when... */
604 if( ELEM4(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL, TFM_TRANSLATION) ) {
606 resetTransRestrictions(t);
608 if (t->mode == TFM_ROTATION) {
609 restoreTransObjects(t);
613 restoreTransObjects(t);
616 initSnapping(t, NULL); // need to reinit after mode change
620 case TFM_MODAL_RESIZE:
621 /* only switch when... */
622 if( ELEM3(t->mode, TFM_ROTATION, TFM_TRANSLATION, TFM_TRACKBALL) ) {
623 resetTransRestrictions(t);
624 restoreTransObjects(t);
626 initSnapping(t, NULL); // need to reinit after mode change
631 case TFM_MODAL_SNAP_GEARS:
632 t->modifiers |= MOD_SNAP_GEARS;
635 case TFM_MODAL_SNAP_GEARS_OFF:
636 t->modifiers &= ~MOD_SNAP_GEARS;
641 /* else do non-mapped events */
642 else if (event->val==KM_PRESS) {
643 switch (event->type){
645 t->state = TRANS_CANCEL;
647 /* enforce redraw of transform when modifiers are used */
650 t->modifiers |= MOD_SNAP_GEARS;
656 t->modifiers |= MOD_CONSTRAINT_PLANE;
661 if ((t->spacetype==SPACE_VIEW3D) && event->alt) {
662 #if 0 // TRANSFORM_FIX_ME
666 BIF_selectOrientation();
667 calc_manipulator_stats(curarea);
668 Mat3CpyMat4(t->spacemtx, G.vd->twmat);
669 warp_pointer(mval[0], mval[1]);
673 t->state = TRANS_CONFIRM;
678 if ((t->flag & T_NO_CONSTRAINT)==0) {
679 /* exception for switching to dolly, or trackball, in camera view */
680 if (t->flag & T_CAMERA) {
681 if (t->mode==TFM_TRANSLATION)
682 setLocalConstraint(t, (CON_AXIS2), "along local Z");
683 else if (t->mode==TFM_ROTATION) {
684 restoreTransObjects(t);
689 t->modifiers |= MOD_CONSTRAINT_SELECT;
690 if (t->con.mode & CON_APPLY) {
695 initSelectConstraint(t, t->spacemtx);
698 /* bit hackish... but it prevents mmb select to print the orientation from menu */
699 strcpy(t->spacename, "global");
700 initSelectConstraint(t, mati);
702 postSelectConstraint(t);
709 t->state = TRANS_CANCEL;
713 t->state = TRANS_CONFIRM;
716 /* only switch when... */
717 if( ELEM3(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL) ) {
718 resetTransRestrictions(t);
719 restoreTransObjects(t);
721 initSnapping(t, NULL); // need to reinit after mode change
726 /* only switch when... */
727 if( ELEM3(t->mode, TFM_ROTATION, TFM_TRANSLATION, TFM_TRACKBALL) ) {
728 resetTransRestrictions(t);
729 restoreTransObjects(t);
731 initSnapping(t, NULL); // need to reinit after mode change
736 /* only switch when... */
737 if( ELEM4(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL, TFM_TRANSLATION) ) {
739 resetTransRestrictions(t);
741 if (t->mode == TFM_ROTATION) {
742 restoreTransObjects(t);
746 restoreTransObjects(t);
749 initSnapping(t, NULL); // need to reinit after mode change
755 t->flag ^= T_PROP_CONNECTED;
756 sort_trans_data_dist(t);
757 calculatePropRatio(t);
766 if ((t->flag & T_NO_CONSTRAINT)==0) {
768 if (t->flag & T_2D_EDIT) {
772 if (t->con.mode & CON_USER) {
776 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
777 setUserConstraint(t, (CON_AXIS0), "along %s X");
778 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
779 setUserConstraint(t, (CON_AXIS1|CON_AXIS2), "locking %s X");
784 if (t->flag & T_2D_EDIT) {
785 setConstraint(t, mati, (CON_AXIS0), "along X axis");
788 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
789 setConstraint(t, mati, (CON_AXIS0), "along global X");
790 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
791 setConstraint(t, mati, (CON_AXIS1|CON_AXIS2), "locking global X");
798 if ((t->flag & T_NO_CONSTRAINT)==0) {
800 if (t->flag & T_2D_EDIT) {
804 if (t->con.mode & CON_USER) {
808 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
809 setUserConstraint(t, (CON_AXIS1), "along %s Y");
810 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
811 setUserConstraint(t, (CON_AXIS0|CON_AXIS2), "locking %s Y");
816 if (t->flag & T_2D_EDIT) {
817 setConstraint(t, mati, (CON_AXIS1), "along Y axis");
820 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
821 setConstraint(t, mati, (CON_AXIS1), "along global Y");
822 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
823 setConstraint(t, mati, (CON_AXIS0|CON_AXIS2), "locking global Y");
830 if ((t->flag & T_NO_CONSTRAINT)==0) {
832 if (t->con.mode & CON_USER) {
836 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
837 setUserConstraint(t, (CON_AXIS2), "along %s Z");
838 else if ((t->modifiers & MOD_CONSTRAINT_PLANE) && ((t->flag & T_2D_EDIT)==0))
839 setUserConstraint(t, (CON_AXIS0|CON_AXIS1), "locking %s Z");
842 else if ((t->flag & T_2D_EDIT)==0) {
843 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
844 setConstraint(t, mati, (CON_AXIS2), "along global Z");
845 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
846 setConstraint(t, mati, (CON_AXIS0|CON_AXIS1), "locking global Z");
852 if (t->flag & T_PROP_EDIT && event->shift) {
853 t->prop_mode = (t->prop_mode + 1) % 6;
854 calculatePropRatio(t);
859 if(event->alt && t->flag & T_PROP_EDIT) {
860 t->prop_size *= 1.1f;
861 calculatePropRatio(t);
867 if (t->flag & T_AUTOIK) {
868 transform_autoik_update(t, 1);
870 else if(t->flag & T_PROP_EDIT) {
872 calculatePropRatio(t);
874 else view_editmove(event->type);
878 if(event->alt && t->flag & T_PROP_EDIT) {
879 t->prop_size*= 0.90909090f;
880 calculatePropRatio(t);
886 if (t->flag & T_AUTOIK) {
887 transform_autoik_update(t, -1);
889 else if (t->flag & T_PROP_EDIT) {
890 t->prop_size*= 0.90909090f;
891 calculatePropRatio(t);
893 else view_editmove(event->type);
901 // Numerical input events
902 t->redraw |= handleNumInput(&(t->num), event);
905 switch(handleNDofInput(&(t->ndof), event))
908 if ((t->options & CTX_NDOF) == 0)
910 /* Confirm on normal transform only */
911 t->state = TRANS_CONFIRM;
915 if (t->options & CTX_NDOF)
917 /* Cancel on pure NDOF transform */
918 t->state = TRANS_CANCEL;
922 /* Otherwise, just redraw, NDof input was cancelled */
927 if (t->options & CTX_NDOF)
929 /* Confirm on pure NDOF transform */
930 t->state = TRANS_CONFIRM;
940 t->redraw |= handleSnapping(t, event);
942 //arrows_move_cursor(event->type);
945 switch (event->type){
947 t->state = TRANS_CONFIRM;
951 t->modifiers &= ~MOD_CONSTRAINT_PLANE;
957 t->modifiers &= ~MOD_SNAP_GEARS;
958 /* no redraw on release modifier keys! this makes sure you can assign the 'grid' still
959 after releasing modifer key */
963 if ((t->flag & T_NO_CONSTRAINT)==0) {
964 t->modifiers &= ~MOD_CONSTRAINT_SELECT;
965 postSelectConstraint(t);
971 // if(WM_modal_tweak_exit(event, t->event_type))
972 //// if (t->options & CTX_TWEAK)
973 // t->state = TRANS_CONFIRM;
978 // Per transform event, if present
980 t->redraw |= t->handleEvent(t, event);
983 int calculateTransformCenter(bContext *C, wmEvent *event, int centerMode, float *vec)
985 TransInfo *t = MEM_callocN(sizeof(TransInfo), "TransInfo data");
988 t->state = TRANS_RUNNING;
990 t->options = CTX_NONE;
994 initTransInfo(C, t, NULL, event); // internal data, mouse, vectors
996 createTransData(C, t); // make TransData structs from selection
998 t->around = centerMode; // override userdefined mode
1000 if (t->total == 0) {
1008 // Copy center from constraint center. Transform center can be local
1009 VECCOPY(vec, t->con.center);
1014 /* aftertrans does insert ipos and action channels, and clears base flags, doesnt read transdata */
1015 special_aftertrans_update(t);
1028 static void drawArrow(ArrowDirection d, short offset, short length, short size)
1038 glVertex2s( offset, 0);
1039 glVertex2s( offset + length, 0);
1040 glVertex2s( offset + length, 0);
1041 glVertex2s( offset + length - size, -size);
1042 glVertex2s( offset + length, 0);
1043 glVertex2s( offset + length - size, size);
1052 glVertex2s( 0, offset);
1053 glVertex2s( 0, offset + length);
1054 glVertex2s( 0, offset + length);
1055 glVertex2s(-size, offset + length - size);
1056 glVertex2s( 0, offset + length);
1057 glVertex2s( size, offset + length - size);
1063 static void drawArrowHead(ArrowDirection d, short size)
1072 glVertex2s( -size, -size);
1074 glVertex2s( -size, size);
1082 glVertex2s(-size, -size);
1084 glVertex2s( size, -size);
1090 static void drawArc(float size, float angle_start, float angle_end, int segments)
1092 float delta = (angle_end - angle_start) / segments;
1095 glBegin(GL_LINE_STRIP);
1097 for( angle = angle_start; angle < angle_end; angle += delta)
1099 glVertex2f( cosf(angle) * size, sinf(angle) * size);
1101 glVertex2f( cosf(angle_end) * size, sinf(angle_end) * size);
1106 void drawHelpline(const struct bContext *C, TransInfo *t)
1108 if (t->helpline != HLP_NONE && !(t->flag & T_USES_MANIPULATOR))
1110 float vecrot[3], cent[2];
1112 VECCOPY(vecrot, t->center);
1113 if(t->flag & T_EDIT) {
1114 Object *ob= t->obedit;
1115 if(ob) Mat4MulVecfl(ob->obmat, vecrot);
1117 else if(t->flag & T_POSE) {
1118 Object *ob=t->poseobj;
1119 if(ob) Mat4MulVecfl(ob->obmat, vecrot);
1122 projectFloatView(t, vecrot, cent); // no overflow in extreme cases
1124 glDisable(GL_DEPTH_TEST);
1126 glMatrixMode(GL_PROJECTION);
1128 glMatrixMode(GL_MODELVIEW);
1131 ED_region_pixelspace(t->ar);
1136 UI_ThemeColor(TH_WIRE);
1139 glBegin(GL_LINE_STRIP);
1140 glVertex2sv(t->mval);
1144 glTranslatef(t->mval[0], t->mval[1], 0);
1145 glRotatef(-180 / M_PI * atan2f(cent[0] - t->mval[0], cent[1] - t->mval[1]), 0, 0, 1);
1149 drawArrow(UP, 5, 10, 5);
1150 drawArrow(DOWN, 5, 10, 5);
1154 UI_ThemeColor(TH_WIRE);
1156 glTranslatef(t->mval[0], t->mval[1], 0);
1159 drawArrow(RIGHT, 5, 10, 5);
1160 drawArrow(LEFT, 5, 10, 5);
1164 UI_ThemeColor(TH_WIRE);
1166 glTranslatef(t->mval[0], t->mval[1], 0);
1170 drawArrow(UP, 5, 10, 5);
1171 drawArrow(DOWN, 5, 10, 5);
1176 float dx = t->mval[0] - cent[0], dy = t->mval[1] - cent[1];
1177 float angle = atan2f(dy, dx);
1178 float dist = sqrtf(dx*dx + dy*dy);
1179 float delta_angle = MIN2(15 / dist, M_PI/4);
1180 float spacing_angle = MIN2(5 / dist, M_PI/12);
1181 UI_ThemeColor(TH_WIRE);
1184 glBegin(GL_LINE_STRIP);
1185 glVertex2sv(t->mval);
1189 glTranslatef(cent[0], cent[1], 0);
1193 drawArc(dist, angle - delta_angle, angle - spacing_angle, 10);
1194 drawArc(dist, angle + spacing_angle, angle + delta_angle, 10);
1198 glTranslatef(cosf(angle - delta_angle) * dist, sinf(angle - delta_angle) * dist, 0);
1199 glRotatef(180 / M_PI * (angle - delta_angle), 0, 0, 1);
1201 drawArrowHead(DOWN, 5);
1205 glTranslatef(cosf(angle + delta_angle) * dist, sinf(angle + delta_angle) * dist, 0);
1206 glRotatef(180 / M_PI * (angle + delta_angle), 0, 0, 1);
1208 drawArrowHead(UP, 5);
1215 char col[3], col2[3];
1216 UI_GetThemeColor3ubv(TH_GRID, col);
1218 glTranslatef(t->mval[0], t->mval[1], 0);
1222 UI_make_axis_color(col, col2, 'x');
1223 glColor3ubv((GLubyte *)col2);
1225 drawArrow(RIGHT, 5, 10, 5);
1226 drawArrow(LEFT, 5, 10, 5);
1228 UI_make_axis_color(col, col2, 'y');
1229 glColor3ubv((GLubyte *)col2);
1231 drawArrow(UP, 5, 10, 5);
1232 drawArrow(DOWN, 5, 10, 5);
1238 glMatrixMode(GL_PROJECTION);
1240 glMatrixMode(GL_MODELVIEW);
1243 glEnable(GL_DEPTH_TEST);
1247 void drawTransform(const struct bContext *C, struct ARegion *ar, void *arg)
1251 drawConstraint(C, t);
1252 drawPropCircle(C, t);
1257 void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
1259 ToolSettings *ts = CTX_data_tool_settings(C);
1260 int constraint_axis[3] = {0, 0, 0};
1261 int proportional = 0;
1263 if (RNA_struct_find_property(op->ptr, "value"))
1265 if (t->flag & T_AUTOVALUES)
1267 RNA_float_set_array(op->ptr, "value", t->auto_values);
1271 RNA_float_set_array(op->ptr, "value", t->values);
1275 /* XXX convert stupid flag to enum */
1276 switch(t->flag & (T_PROP_EDIT|T_PROP_CONNECTED))
1278 case (T_PROP_EDIT|T_PROP_CONNECTED):
1288 if (RNA_struct_find_property(op->ptr, "proportional"))
1290 RNA_enum_set(op->ptr, "proportional", proportional);
1291 RNA_enum_set(op->ptr, "proportional_editing_falloff", t->prop_mode);
1292 RNA_float_set(op->ptr, "proportional_size", t->prop_size);
1295 if (RNA_struct_find_property(op->ptr, "mirror"))
1297 RNA_boolean_set(op->ptr, "mirror", t->flag & T_MIRROR);
1300 if (RNA_struct_find_property(op->ptr, "constraint_axis"))
1302 RNA_enum_set(op->ptr, "constraint_orientation", t->current_orientation);
1304 if (t->con.mode & CON_APPLY)
1306 if (t->con.mode & CON_AXIS0) {
1307 constraint_axis[0] = 1;
1309 if (t->con.mode & CON_AXIS1) {
1310 constraint_axis[1] = 1;
1312 if (t->con.mode & CON_AXIS2) {
1313 constraint_axis[2] = 1;
1317 RNA_boolean_set_array(op->ptr, "constraint_axis", constraint_axis);
1320 // XXX If modal, save settings back in scene
1321 if (t->flag & T_MODAL)
1323 ts->prop_mode = t->prop_mode;
1325 /* only save back if it wasn't automatically disabled */
1326 if ((t->options & CTX_NO_PET) == 0)
1328 ts->proportional = proportional;
1329 ts->proportional_size = t->prop_size;
1332 if(t->spacetype == SPACE_VIEW3D)
1334 View3D *v3d = t->view;
1336 v3d->twmode = t->current_orientation;
1341 int initTransform(bContext *C, TransInfo *t, wmOperator *op, wmEvent *event, int mode)
1345 /* added initialize, for external calls to set stuff in TransInfo, like undo string */
1347 t->state = TRANS_RUNNING;
1349 t->options = options;
1353 if (!initTransInfo(C, t, op, event)) // internal data, mouse, vectors
1358 if(t->spacetype == SPACE_VIEW3D)
1360 //calc_manipulator_stats(curarea);
1361 initTransformOrientation(C, t);
1363 t->draw_handle = ED_region_draw_cb_activate(t->ar->type, drawTransform, t, REGION_DRAW_POST);
1365 else if(t->spacetype == SPACE_IMAGE) {
1366 Mat3One(t->spacemtx);
1367 t->draw_handle = ED_region_draw_cb_activate(t->ar->type, drawTransform, t, REGION_DRAW_POST);
1370 Mat3One(t->spacemtx);
1372 createTransData(C, t); // make TransData structs from selection
1374 if (t->total == 0) {
1379 initSnapping(t, op); // Initialize snapping data AFTER mode flags
1381 /* EVIL! posemode code can switch translation to rotate when 1 bone is selected. will be removed (ton) */
1382 /* EVIL2: we gave as argument also texture space context bit... was cleared */
1383 /* EVIL3: extend mode for animation editors also switches modes... but is best way to avoid duplicate code */
1386 calculatePropRatio(t);
1389 initMouseInput(t, &t->mouse, t->center2d, t->imval);
1392 case TFM_TRANSLATION:
1410 case TFM_SHRINKFATTEN:
1411 initShrinkFatten(t);
1416 case TFM_CURVE_SHRINKFATTEN:
1417 initCurveShrinkFatten(t);
1429 { /* used for both B-Bone width (bonesize) as for deform-dist (envelope) */
1430 bArmature *arm= t->poseobj->data;
1431 if(arm->drawtype==ARM_ENVELOPE)
1432 initBoneEnvelope(t);
1437 case TFM_BONE_ENVELOPE:
1438 initBoneEnvelope(t);
1440 case TFM_EDGE_SLIDE:
1446 case TFM_TIME_TRANSLATE:
1447 initTimeTranslate(t);
1449 case TFM_TIME_SLIDE:
1452 case TFM_TIME_SCALE:
1455 case TFM_TIME_EXTEND:
1456 /* now that transdata has been made, do like for TFM_TIME_TRANSLATE (for most Animation
1457 * Editors because they have only 1D transforms for time values) or TFM_TRANSLATION
1458 * (for Graph/NLA Editors only since they uses 'standard' transforms to get 2D movement)
1459 * depending on which editor this was called from
1461 if ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)
1464 initTimeTranslate(t);
1483 /* overwrite initial values if operator supplied a non-null vector */
1484 if (RNA_property_is_set(op->ptr, "value"))
1487 RNA_float_get_array(op->ptr, "value", values);
1488 QUATCOPY(t->values, values);
1489 QUATCOPY(t->auto_values, values);
1490 t->flag |= T_AUTOVALUES;
1493 /* Constraint init from operator */
1494 if (RNA_struct_find_property(op->ptr, "constraint_axis") && RNA_property_is_set(op->ptr, "constraint_axis"))
1496 int constraint_axis[3];
1498 RNA_boolean_get_array(op->ptr, "constraint_axis", constraint_axis);
1500 if (constraint_axis[0] || constraint_axis[1] || constraint_axis[2])
1502 t->con.mode |= CON_APPLY;
1504 if (constraint_axis[0]) {
1505 t->con.mode |= CON_AXIS0;
1507 if (constraint_axis[1]) {
1508 t->con.mode |= CON_AXIS1;
1510 if (constraint_axis[2]) {
1511 t->con.mode |= CON_AXIS2;
1514 setUserConstraint(t, t->con.mode, "%s");
1521 void transformApply(bContext *C, TransInfo *t)
1525 if (t->modifiers & MOD_CONSTRAINT_SELECT)
1526 t->con.mode |= CON_SELECT;
1528 selectConstraint(t);
1530 t->transform(t, t->mval); // calls recalcData()
1531 viewRedrawForce(C, t);
1536 /* If auto confirm is on, break after one pass */
1537 if (t->options & CTX_AUTOCONFIRM)
1539 t->state = TRANS_CONFIRM;
1542 if (BKE_ptcache_get_continue_physics())
1545 //do_screenhandlers(G.curscreen);
1550 int transformEnd(bContext *C, TransInfo *t)
1552 int exit_code = OPERATOR_RUNNING_MODAL;
1554 if (t->state != TRANS_RUNNING)
1556 /* handle restoring objects */
1557 if(t->state == TRANS_CANCEL)
1559 exit_code = OPERATOR_CANCELLED;
1560 restoreTransObjects(t); // calls recalcData()
1564 exit_code = OPERATOR_FINISHED;
1570 /* aftertrans does insert keyframes, and clears base flags, doesnt read transdata */
1571 special_aftertrans_update(t);
1573 /* send events out for redraws */
1576 /* Undo as last, certainly after special_trans_update! */
1578 if(t->state == TRANS_CANCEL) {
1579 // if(t->undostr) ED_undo_push(C, t->undostr);
1582 // if(t->undostr) ED_undo_push(C, t->undostr);
1583 // else ED_undo_push(C, transform_to_undostr(t));
1587 viewRedrawForce(C, t);
1593 /* ************************** TRANSFORM LOCKS **************************** */
1595 static void protectedTransBits(short protectflag, float *vec)
1597 if(protectflag & OB_LOCK_LOCX)
1599 if(protectflag & OB_LOCK_LOCY)
1601 if(protectflag & OB_LOCK_LOCZ)
1605 static void protectedSizeBits(short protectflag, float *size)
1607 if(protectflag & OB_LOCK_SCALEX)
1609 if(protectflag & OB_LOCK_SCALEY)
1611 if(protectflag & OB_LOCK_SCALEZ)
1615 static void protectedRotateBits(short protectflag, float *eul, float *oldeul)
1617 if(protectflag & OB_LOCK_ROTX)
1619 if(protectflag & OB_LOCK_ROTY)
1621 if(protectflag & OB_LOCK_ROTZ)
1626 /* this function only does the delta rotation */
1627 /* axis-angle is usually internally stored as quats... */
1628 static void protectedAxisAngleBits(short protectflag, float *quat, float *oldquat)
1630 /* check that protection flags are set */
1631 if ((protectflag & (OB_LOCK_ROTX|OB_LOCK_ROTY|OB_LOCK_ROTZ|OB_LOCK_ROTW)) == 0)
1634 if (protectflag & OB_LOCK_ROT4D) {
1635 /* axis-angle getting limited as 4D entities that they are... */
1636 if (protectflag & OB_LOCK_ROTW)
1637 quat[0]= oldquat[0];
1638 if (protectflag & OB_LOCK_ROTX)
1639 quat[1]= oldquat[1];
1640 if (protectflag & OB_LOCK_ROTY)
1641 quat[2]= oldquat[2];
1642 if (protectflag & OB_LOCK_ROTZ)
1643 quat[3]= oldquat[3];
1646 /* axis-angle get limited with euler... */
1647 float eul[3], oldeul[3], quat1[4];
1649 QUATCOPY(quat1, quat);
1650 AxisAngleToEulO(quat+1, quat[0], eul, EULER_ORDER_DEFAULT);
1651 AxisAngleToEulO(oldquat+1, oldquat[0], oldeul, EULER_ORDER_DEFAULT);
1653 if (protectflag & OB_LOCK_ROTX)
1655 if (protectflag & OB_LOCK_ROTY)
1657 if (protectflag & OB_LOCK_ROTZ)
1660 EulOToAxisAngle(eul, EULER_ORDER_DEFAULT, quat+1, quat);
1662 /* when converting to axis-angle, we need a special exception for the case when there is no axis */
1663 if (IS_EQ(quat[1], quat[2]) && IS_EQ(quat[2], quat[3])) {
1664 /* for now, rotate around y-axis then (so that it simply becomes the roll) */
1670 /* this function only does the delta rotation */
1671 static void protectedQuaternionBits(short protectflag, float *quat, float *oldquat)
1673 /* check that protection flags are set */
1674 if ((protectflag & (OB_LOCK_ROTX|OB_LOCK_ROTY|OB_LOCK_ROTZ|OB_LOCK_ROTW)) == 0)
1677 if (protectflag & OB_LOCK_ROT4D) {
1678 /* quaternions getting limited as 4D entities that they are... */
1679 if (protectflag & OB_LOCK_ROTW)
1680 quat[0]= oldquat[0];
1681 if (protectflag & OB_LOCK_ROTX)
1682 quat[1]= oldquat[1];
1683 if (protectflag & OB_LOCK_ROTY)
1684 quat[2]= oldquat[2];
1685 if (protectflag & OB_LOCK_ROTZ)
1686 quat[3]= oldquat[3];
1689 /* quaternions get limited with euler... (compatability mode) */
1690 float eul[3], oldeul[3], quat1[4];
1692 QUATCOPY(quat1, quat);
1693 QuatToEul(quat, eul);
1694 QuatToEul(oldquat, oldeul);
1696 if (protectflag & OB_LOCK_ROTX)
1698 if (protectflag & OB_LOCK_ROTY)
1700 if (protectflag & OB_LOCK_ROTZ)
1703 EulToQuat(eul, quat);
1705 /* quaternions flip w sign to accumulate rotations correctly */
1706 if ( (quat1[0]<0.0f && quat[0]>0.0f) || (quat1[0]>0.0f && quat[0]<0.0f) ) {
1707 QuatMulf(quat, -1.0f);
1712 /* ******************* TRANSFORM LIMITS ********************** */
1714 static void constraintTransLim(TransInfo *t, TransData *td)
1717 bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_LOCLIMIT);
1721 /* Make a temporary bConstraintOb for using these limit constraints
1722 * - they only care that cob->matrix is correctly set ;-)
1723 * - current space should be local
1725 memset(&cob, 0, sizeof(bConstraintOb));
1726 Mat4One(cob.matrix);
1727 VECCOPY(cob.matrix[3], td->loc);
1729 /* Evaluate valid constraints */
1730 for (con= td->con; con; con= con->next) {
1733 /* only consider constraint if enabled */
1734 if (con->flag & CONSTRAINT_DISABLE) continue;
1735 if (con->enforce == 0.0f) continue;
1737 /* only use it if it's tagged for this purpose (and the right type) */
1738 if (con->type == CONSTRAINT_TYPE_LOCLIMIT) {
1739 bLocLimitConstraint *data= con->data;
1741 if ((data->flag2 & LIMIT_TRANSFORM)==0)
1744 /* do space conversions */
1745 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1746 /* just multiply by td->mtx (this should be ok) */
1747 Mat4CpyMat4(tmat, cob.matrix);
1748 Mat4MulMat34(cob.matrix, td->mtx, tmat);
1750 else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) {
1751 /* skip... incompatable spacetype */
1756 cti->evaluate_constraint(con, &cob, NULL);
1758 /* convert spaces again */
1759 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1760 /* just multiply by td->mtx (this should be ok) */
1761 Mat4CpyMat4(tmat, cob.matrix);
1762 Mat4MulMat34(cob.matrix, td->smtx, tmat);
1767 /* copy results from cob->matrix */
1768 VECCOPY(td->loc, cob.matrix[3]);
1772 static void constraintRotLim(TransInfo *t, TransData *td)
1775 bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_ROTLIMIT);
1779 /* Make a temporary bConstraintOb for using these limit constraints
1780 * - they only care that cob->matrix is correctly set ;-)
1781 * - current space should be local
1783 memset(&cob, 0, sizeof(bConstraintOb));
1784 if (td->rotOrder == ROT_MODE_QUAT) {
1787 QuatToMat4(td->ext->quat, cob.matrix);
1791 else if (td->rotOrder == ROT_MODE_AXISANGLE) {
1794 AxisAngleToMat4(&td->ext->quat[1], td->ext->quat[0], cob.matrix);
1801 EulOToMat4(td->ext->rot, td->rotOrder, cob.matrix);
1806 /* Evaluate valid constraints */
1807 for (con= td->con; con; con= con->next) {
1808 /* only consider constraint if enabled */
1809 if (con->flag & CONSTRAINT_DISABLE) continue;
1810 if (con->enforce == 0.0f) continue;
1812 /* we're only interested in Limit-Rotation constraints */
1813 if (con->type == CONSTRAINT_TYPE_ROTLIMIT) {
1814 bRotLimitConstraint *data= con->data;
1817 /* only use it if it's tagged for this purpose */
1818 if ((data->flag2 & LIMIT_TRANSFORM)==0)
1821 /* do space conversions */
1822 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1823 /* just multiply by td->mtx (this should be ok) */
1824 Mat4CpyMat4(tmat, cob.matrix);
1825 Mat4MulMat34(cob.matrix, td->mtx, tmat);
1827 else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) {
1828 /* skip... incompatable spacetype */
1833 cti->evaluate_constraint(con, &cob, NULL);
1835 /* convert spaces again */
1836 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1837 /* just multiply by td->mtx (this should be ok) */
1838 Mat4CpyMat4(tmat, cob.matrix);
1839 Mat4MulMat34(cob.matrix, td->smtx, tmat);
1844 /* copy results from cob->matrix */
1845 if (td->rotOrder == ROT_MODE_QUAT) {
1847 Mat4ToQuat(cob.matrix, td->ext->quat);
1849 else if (td->rotOrder == ROT_MODE_AXISANGLE) {
1851 Mat4ToAxisAngle(cob.matrix, &td->ext->quat[1], &td->ext->quat[0]);
1855 Mat4ToEulO(cob.matrix, td->ext->rot, td->rotOrder);
1860 static void constraintSizeLim(TransInfo *t, TransData *td)
1862 if (td->con && td->ext) {
1863 bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_SIZELIMIT);
1867 /* Make a temporary bConstraintOb for using these limit constraints
1868 * - they only care that cob->matrix is correctly set ;-)
1869 * - current space should be local
1871 memset(&cob, 0, sizeof(bConstraintOb));
1872 if ((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)) {
1873 /* scale val and reset size */
1874 return; // TODO: fix this case
1877 /* Reset val if SINGLESIZE but using a constraint */
1878 if (td->flag & TD_SINGLESIZE)
1881 SizeToMat4(td->ext->size, cob.matrix);
1884 /* Evaluate valid constraints */
1885 for (con= td->con; con; con= con->next) {
1886 /* only consider constraint if enabled */
1887 if (con->flag & CONSTRAINT_DISABLE) continue;
1888 if (con->enforce == 0.0f) continue;
1890 /* we're only interested in Limit-Scale constraints */
1891 if (con->type == CONSTRAINT_TYPE_SIZELIMIT) {
1892 bSizeLimitConstraint *data= con->data;
1895 /* only use it if it's tagged for this purpose */
1896 if ((data->flag2 & LIMIT_TRANSFORM)==0)
1899 /* do space conversions */
1900 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1901 /* just multiply by td->mtx (this should be ok) */
1902 Mat4CpyMat4(tmat, cob.matrix);
1903 Mat4MulMat34(cob.matrix, td->mtx, tmat);
1905 else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) {
1906 /* skip... incompatable spacetype */
1911 cti->evaluate_constraint(con, &cob, NULL);
1913 /* convert spaces again */
1914 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1915 /* just multiply by td->mtx (this should be ok) */
1916 Mat4CpyMat4(tmat, cob.matrix);
1917 Mat4MulMat34(cob.matrix, td->smtx, tmat);
1922 /* copy results from cob->matrix */
1923 if ((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)) {
1924 /* scale val and reset size */
1925 return; // TODO: fix this case
1928 /* Reset val if SINGLESIZE but using a constraint */
1929 if (td->flag & TD_SINGLESIZE)
1932 Mat4ToSize(cob.matrix, td->ext->size);
1937 /* ************************** WARP *************************** */
1939 void initWarp(TransInfo *t)
1941 float max[3], min[3];
1945 t->transform = Warp;
1946 t->handleEvent = handleEventWarp;
1948 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_RATIO);
1956 t->flag |= T_NO_CONSTRAINT;
1958 /* we need min/max in view space */
1959 for(i = 0; i < t->total; i++) {
1961 VECCOPY(center, t->data[i].center);
1962 Mat3MulVecfl(t->data[i].mtx, center);
1963 Mat4MulVecfl(t->viewmat, center);
1964 VecSubf(center, center, t->viewmat[3]);
1966 MinMax3(min, max, center);
1968 VECCOPY(max, center);
1969 VECCOPY(min, center);
1973 t->center[0]= (min[0]+max[0])/2.0f;
1974 t->center[1]= (min[1]+max[1])/2.0f;
1975 t->center[2]= (min[2]+max[2])/2.0f;
1977 if (max[0] == min[0]) max[0] += 0.1; /* not optimal, but flipping is better than invalid garbage (i.e. division by zero!) */
1978 t->val= (max[0]-min[0])/2.0f; /* t->val is X dimension projected boundbox */
1981 int handleEventWarp(TransInfo *t, wmEvent *event)
1985 if (event->type == MIDDLEMOUSE && event->val==KM_PRESS)
1987 // Use customData pointer to signal warp direction
1988 if (t->customData == 0)
1989 t->customData = (void*)1;
1999 int Warp(TransInfo *t, short mval[2])
2001 TransData *td = t->data;
2002 float vec[3], circumfac, dist, phi0, co, si, *curs, cursor[3], gcursor[3];
2006 curs= give_cursor(t->scene, t->view);
2008 * gcursor is the one used for helpline.
2009 * It has to be in the same space as the drawing loop
2010 * (that means it needs to be in the object's space when in edit mode and
2011 * in global space in object mode)
2013 * cursor is used for calculations.
2014 * It needs to be in view space, but we need to take object's offset
2015 * into account if in Edit mode.
2017 VECCOPY(cursor, curs);
2018 VECCOPY(gcursor, cursor);
2019 if (t->flag & T_EDIT) {
2020 VecSubf(cursor, cursor, t->obedit->obmat[3]);
2021 VecSubf(gcursor, gcursor, t->obedit->obmat[3]);
2022 Mat3MulVecfl(t->data->smtx, gcursor);
2024 Mat4MulVecfl(t->viewmat, cursor);
2025 VecSubf(cursor, cursor, t->viewmat[3]);
2027 /* amount of degrees for warp */
2028 circumfac = 360.0f * t->values[0];
2030 if (t->customData) /* non-null value indicates reversed input */
2035 snapGrid(t, &circumfac);
2036 applyNumInput(&t->num, &circumfac);
2038 /* header print for NumInput */
2039 if (hasNumInput(&t->num)) {
2042 outputNumInput(&(t->num), c);
2044 sprintf(str, "Warp: %s", c);
2047 /* default header print */
2048 sprintf(str, "Warp: %.3f", circumfac);
2051 circumfac*= (float)(-M_PI/360.0);
2053 for(i = 0; i < t->total; i++, td++) {
2055 if (td->flag & TD_NOACTION)
2058 if (td->flag & TD_SKIP)
2061 /* translate point to center, rotate in such a way that outline==distance */
2062 VECCOPY(vec, td->iloc);
2063 Mat3MulVecfl(td->mtx, vec);
2064 Mat4MulVecfl(t->viewmat, vec);
2065 VecSubf(vec, vec, t->viewmat[3]);
2067 dist= vec[0]-cursor[0];
2069 /* t->val is X dimension projected boundbox */
2070 phi0= (circumfac*dist/t->val);
2072 vec[1]= (vec[1]-cursor[1]);
2074 co= (float)cos(phi0);
2075 si= (float)sin(phi0);
2076 loc[0]= -si*vec[1]+cursor[0];
2077 loc[1]= co*vec[1]+cursor[1];
2080 Mat4MulVecfl(t->viewinv, loc);
2081 VecSubf(loc, loc, t->viewinv[3]);
2082 Mat3MulVecfl(td->smtx, loc);
2084 VecSubf(loc, loc, td->iloc);
2085 VecMulf(loc, td->factor);
2086 VecAddf(td->loc, td->iloc, loc);
2091 ED_area_headerprint(t->sa, str);
2096 /* ************************** SHEAR *************************** */
2098 void initShear(TransInfo *t)
2100 t->mode = TFM_SHEAR;
2101 t->transform = Shear;
2102 t->handleEvent = handleEventShear;
2104 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_ABSOLUTE);
2110 t->snap[2] = t->snap[1] * 0.1f;
2112 t->flag |= T_NO_CONSTRAINT;
2115 int handleEventShear(TransInfo *t, wmEvent *event)
2119 if (event->type == MIDDLEMOUSE && event->val==KM_PRESS)
2121 // Use customData pointer to signal Shear direction
2122 if (t->customData == 0)
2124 initMouseInputMode(t, &t->mouse, INPUT_VERTICAL_ABSOLUTE);
2125 t->customData = (void*)1;
2129 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_ABSOLUTE);
2140 int Shear(TransInfo *t, short mval[2])
2142 TransData *td = t->data;
2144 float smat[3][3], tmat[3][3], totmat[3][3], persmat[3][3], persinv[3][3];
2149 Mat3CpyMat4(persmat, t->viewmat);
2150 Mat3Inv(persinv, persmat);
2152 value = 0.05f * t->values[0];
2154 snapGrid(t, &value);
2156 applyNumInput(&t->num, &value);
2158 /* header print for NumInput */
2159 if (hasNumInput(&t->num)) {
2162 outputNumInput(&(t->num), c);
2164 sprintf(str, "Shear: %s %s", c, t->proptext);
2167 /* default header print */
2168 sprintf(str, "Shear: %.3f %s", value, t->proptext);
2173 // Custom data signals shear direction
2174 if (t->customData == 0)
2179 Mat3MulMat3(tmat, smat, persmat);
2180 Mat3MulMat3(totmat, persinv, tmat);
2182 for(i = 0 ; i < t->total; i++, td++) {
2183 if (td->flag & TD_NOACTION)
2186 if (td->flag & TD_SKIP)
2191 Mat3MulMat3(mat3, totmat, td->mtx);
2192 Mat3MulMat3(tmat, td->smtx, mat3);
2195 Mat3CpyMat3(tmat, totmat);
2197 VecSubf(vec, td->center, t->center);
2199 Mat3MulVecfl(tmat, vec);
2201 VecAddf(vec, vec, t->center);
2202 VecSubf(vec, vec, td->center);
2204 VecMulf(vec, td->factor);
2206 VecAddf(td->loc, td->iloc, vec);
2211 ED_area_headerprint(t->sa, str);
2216 /* ************************** RESIZE *************************** */
2218 void initResize(TransInfo *t)
2220 t->mode = TFM_RESIZE;
2221 t->transform = Resize;
2223 initMouseInputMode(t, &t->mouse, INPUT_SPRING_FLIP);
2225 t->flag |= T_NULL_ONE;
2226 t->num.flag |= NUM_NULL_ONE;
2227 t->num.flag |= NUM_AFFECT_ALL;
2229 t->flag |= T_NO_ZERO;
2230 t->num.flag |= NUM_NO_ZERO;
2237 t->snap[2] = t->snap[1] * 0.1f;
2240 static void headerResize(TransInfo *t, float vec[3], char *str) {
2242 if (hasNumInput(&t->num)) {
2243 outputNumInput(&(t->num), tvec);
2246 sprintf(&tvec[0], "%.4f", vec[0]);
2247 sprintf(&tvec[20], "%.4f", vec[1]);
2248 sprintf(&tvec[40], "%.4f", vec[2]);
2251 if (t->con.mode & CON_APPLY) {
2252 switch(t->num.idx_max) {
2254 sprintf(str, "Scale: %s%s %s", &tvec[0], t->con.text, t->proptext);
2257 sprintf(str, "Scale: %s : %s%s %s", &tvec[0], &tvec[20], t->con.text, t->proptext);
2260 sprintf(str, "Scale: %s : %s : %s%s %s", &tvec[0], &tvec[20], &tvec[40], t->con.text, t->proptext);
2264 if (t->flag & T_2D_EDIT)
2265 sprintf(str, "Scale X: %s Y: %s%s %s", &tvec[0], &tvec[20], t->con.text, t->proptext);
2267 sprintf(str, "Scale X: %s Y: %s Z: %s%s %s", &tvec[0], &tvec[20], &tvec[40], t->con.text, t->proptext);
2271 #define SIGN(a) (a<-FLT_EPSILON?1:a>FLT_EPSILON?2:3)
2272 #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)
2274 /* smat is reference matrix, only scaled */
2275 static void TransMat3ToSize( float mat[][3], float smat[][3], float *size)
2279 VecCopyf(vec, mat[0]);
2280 size[0]= Normalize(vec);
2281 VecCopyf(vec, mat[1]);
2282 size[1]= Normalize(vec);
2283 VecCopyf(vec, mat[2]);
2284 size[2]= Normalize(vec);
2286 /* first tried with dotproduct... but the sign flip is crucial */
2287 if( VECSIGNFLIP(mat[0], smat[0]) ) size[0]= -size[0];
2288 if( VECSIGNFLIP(mat[1], smat[1]) ) size[1]= -size[1];
2289 if( VECSIGNFLIP(mat[2], smat[2]) ) size[2]= -size[2];
2293 static void ElementResize(TransInfo *t, TransData *td, float mat[3][3]) {
2294 float tmat[3][3], smat[3][3], center[3];
2297 if (t->flag & T_EDIT) {
2298 Mat3MulMat3(smat, mat, td->mtx);
2299 Mat3MulMat3(tmat, td->smtx, smat);
2302 Mat3CpyMat3(tmat, mat);
2305 if (t->con.applySize) {
2306 t->con.applySize(t, td, tmat);
2309 /* local constraint shouldn't alter center */
2310 if (t->around == V3D_LOCAL) {
2311 if (t->flag & T_OBJECT) {
2312 VECCOPY(center, td->center);
2314 else if (t->flag & T_EDIT) {
2316 if(t->around==V3D_LOCAL && (t->settings->selectmode & SCE_SELECT_FACE)) {
2317 VECCOPY(center, td->center);
2320 VECCOPY(center, t->center);
2324 VECCOPY(center, t->center);
2328 VECCOPY(center, t->center);
2334 if (t->flag & (T_OBJECT|T_TEXTURE|T_POSE)) {
2335 float obsizemat[3][3];
2336 // Reorient the size mat to fit the oriented object.
2337 Mat3MulMat3(obsizemat, td->axismtx, tmat);
2338 //printmatrix3("obsizemat", obsizemat);
2339 TransMat3ToSize(obsizemat, td->axismtx, fsize);
2340 //printvecf("fsize", fsize);
2343 Mat3ToSize(tmat, fsize);
2346 protectedSizeBits(td->protectflag, fsize);
2348 if ((t->flag & T_V3D_ALIGN)==0) { // align mode doesn't resize objects itself
2349 if((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)){
2350 /* scale val and reset size */
2351 *td->val = td->ival * fsize[0] * td->factor;
2353 td->ext->size[0] = td->ext->isize[0];
2354 td->ext->size[1] = td->ext->isize[1];
2355 td->ext->size[2] = td->ext->isize[2];
2358 /* Reset val if SINGLESIZE but using a constraint */
2359 if (td->flag & TD_SINGLESIZE)
2360 *td->val = td->ival;
2362 td->ext->size[0] = td->ext->isize[0] * (fsize[0]) * td->factor;
2363 td->ext->size[1] = td->ext->isize[1] * (fsize[1]) * td->factor;
2364 td->ext->size[2] = td->ext->isize[2] * (fsize[2]) * td->factor;
2368 constraintSizeLim(t, td);
2371 /* For individual element center, Editmode need to use iloc */
2372 if (t->flag & T_POINTS)
2373 VecSubf(vec, td->iloc, center);
2375 VecSubf(vec, td->center, center);
2377 Mat3MulVecfl(tmat, vec);
2379 VecAddf(vec, vec, center);
2380 if (t->flag & T_POINTS)
2381 VecSubf(vec, vec, td->iloc);
2383 VecSubf(vec, vec, td->center);
2385 VecMulf(vec, td->factor);
2387 if (t->flag & (T_OBJECT|T_POSE)) {
2388 Mat3MulVecfl(td->smtx, vec);
2391 protectedTransBits(td->protectflag, vec);
2392 VecAddf(td->loc, td->iloc, vec);
2394 constraintTransLim(t, td);
2397 int Resize(TransInfo *t, short mval[2])
2400 float size[3], mat[3][3];
2405 /* for manipulator, center handle, the scaling can't be done relative to center */
2406 if( (t->flag & T_USES_MANIPULATOR) && t->con.mode==0)
2408 ratio = 1.0f - ((t->imval[0] - mval[0]) + (t->imval[1] - mval[1]))/100.0f;
2412 ratio = t->values[0];
2415 size[0] = size[1] = size[2] = ratio;
2419 if (hasNumInput(&t->num)) {
2420 applyNumInput(&t->num, size);
2421 constraintNumInput(t, size);
2424 applySnapping(t, size);
2426 if (t->flag & T_AUTOVALUES)
2428 VECCOPY(size, t->auto_values);
2431 VECCOPY(t->values, size);
2433 SizeToMat3(size, mat);
2435 if (t->con.applySize) {
2436 t->con.applySize(t, NULL, mat);
2439 Mat3CpyMat3(t->mat, mat); // used in manipulator
2441 headerResize(t, size, str);
2443 for(i = 0, td=t->data; i < t->total; i++, td++) {
2444 if (td->flag & TD_NOACTION)
2447 if (td->flag & TD_SKIP)
2450 ElementResize(t, td, mat);
2453 /* evil hack - redo resize if cliping needed */
2454 if (t->flag & T_CLIP_UV && clipUVTransform(t, size, 1)) {
2455 SizeToMat3(size, mat);
2457 if (t->con.applySize)
2458 t->con.applySize(t, NULL, mat);
2460 for(i = 0, td=t->data; i < t->total; i++, td++)
2461 ElementResize(t, td, mat);
2466 ED_area_headerprint(t->sa, str);
2471 /* ************************** TOSPHERE *************************** */
2473 void initToSphere(TransInfo *t)
2475 TransData *td = t->data;
2478 t->mode = TFM_TOSPHERE;
2479 t->transform = ToSphere;
2481 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_RATIO);
2487 t->snap[2] = t->snap[1] * 0.1f;
2489 t->num.flag |= NUM_NULL_ONE | NUM_NO_NEGATIVE;
2490 t->flag |= T_NO_CONSTRAINT;
2492 // Calculate average radius
2493 for(i = 0 ; i < t->total; i++, td++) {
2494 t->val += VecLenf(t->center, td->iloc);
2497 t->val /= (float)t->total;
2500 int ToSphere(TransInfo *t, short mval[2])
2503 float ratio, radius;
2506 TransData *td = t->data;
2508 ratio = t->values[0];
2510 snapGrid(t, &ratio);
2512 applyNumInput(&t->num, &ratio);
2519 /* header print for NumInput */
2520 if (hasNumInput(&t->num)) {
2523 outputNumInput(&(t->num), c);
2525 sprintf(str, "To Sphere: %s %s", c, t->proptext);
2528 /* default header print */
2529 sprintf(str, "To Sphere: %.4f %s", ratio, t->proptext);
2533 for(i = 0 ; i < t->total; i++, td++) {
2535 if (td->flag & TD_NOACTION)
2538 if (td->flag & TD_SKIP)
2541 VecSubf(vec, td->iloc, t->center);
2543 radius = Normalize(vec);
2545 tratio = ratio * td->factor;
2547 VecMulf(vec, radius * (1.0f - tratio) + t->val * tratio);
2549 VecAddf(td->loc, t->center, vec);
2555 ED_area_headerprint(t->sa, str);
2560 /* ************************** ROTATION *************************** */
2563 void initRotation(TransInfo *t)
2565 t->mode = TFM_ROTATION;
2566 t->transform = Rotation;
2568 initMouseInputMode(t, &t->mouse, INPUT_ANGLE);
2571 /* Scale down and flip input for rotation */
2572 t->ndof.factor[0] = -0.2f;
2577 t->snap[1] = (float)((5.0/180)*M_PI);
2578 t->snap[2] = t->snap[1] * 0.2f;
2580 if (t->flag & T_2D_EDIT)
2581 t->flag |= T_NO_CONSTRAINT;
2584 static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short around) {
2585 float vec[3], totmat[3][3], smat[3][3];
2586 float eul[3], fmat[3][3], quat[4];
2587 float *center = t->center;
2589 /* local constraint shouldn't alter center */
2590 if (around == V3D_LOCAL) {
2591 if (t->flag & (T_OBJECT|T_POSE)) {
2592 center = td->center;
2595 /* !TODO! Make this if not rely on G */
2596 if(around==V3D_LOCAL && (t->settings->selectmode & SCE_SELECT_FACE)) {
2597 center = td->center;
2602 if (t->flag & T_POINTS) {
2603 Mat3MulMat3(totmat, mat, td->mtx);
2604 Mat3MulMat3(smat, td->smtx, totmat);
2606 VecSubf(vec, td->iloc, center);
2607 Mat3MulVecfl(smat, vec);
2609 VecAddf(td->loc, vec, center);
2611 VecSubf(vec,td->loc,td->iloc);
2612 protectedTransBits(td->protectflag, vec);
2613 VecAddf(td->loc, td->iloc, vec);
2616 if(td->flag & TD_USEQUAT) {
2617 Mat3MulSerie(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0);
2618 Mat3ToQuat(fmat, quat); // Actual transform
2621 QuatMul(td->ext->quat, quat, td->ext->iquat);
2623 /* is there a reason not to have this here? -jahka */
2624 protectedQuaternionBits(td->protectflag, td->ext->quat, td->ext->iquat);
2631 * This is some VERY ugly special case to deal with pose mode.
2633 * The problem is that mtx and smtx include each bone orientation.
2635 * That is needed to rotate each bone properly, HOWEVER, to calculate
2636 * the translation component, we only need the actual armature object's
2637 * matrix (and inverse). That is not all though. Once the proper translation
2638 * has been computed, it has to be converted back into the bone's space.
2640 else if (t->flag & T_POSE) {
2641 float pmtx[3][3], imtx[3][3];
2643 // Extract and invert armature object matrix
2644 Mat3CpyMat4(pmtx, t->poseobj->obmat);
2645 Mat3Inv(imtx, pmtx);
2647 if ((td->flag & TD_NO_LOC) == 0)
2649 VecSubf(vec, td->center, center);
2651 Mat3MulVecfl(pmtx, vec); // To Global space
2652 Mat3MulVecfl(mat, vec); // Applying rotation
2653 Mat3MulVecfl(imtx, vec); // To Local space
2655 VecAddf(vec, vec, center);
2656 /* vec now is the location where the object has to be */
2658 VecSubf(vec, vec, td->center); // Translation needed from the initial location
2660 Mat3MulVecfl(pmtx, vec); // To Global space
2661 Mat3MulVecfl(td->smtx, vec);// To Pose space
2663 protectedTransBits(td->protectflag, vec);
2665 VecAddf(td->loc, td->iloc, vec);
2667 constraintTransLim(t, td);
2671 if ((t->flag & T_V3D_ALIGN)==0) { // align mode doesn't rotate objects itself
2672 /* euler or quaternion/axis-angle? */
2673 if (td->rotOrder == ROT_MODE_QUAT) {
2674 Mat3MulSerie(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0);
2676 Mat3ToQuat(fmat, quat); // Actual transform
2678 QuatMul(td->ext->quat, quat, td->ext->iquat);
2679 /* this function works on end result */
2680 protectedQuaternionBits(td->protectflag, td->ext->quat, td->ext->iquat);
2683 else if (td->rotOrder == ROT_MODE_AXISANGLE) {
2684 /* calculate effect based on quats */
2687 /* td->ext->(i)quat is in axis-angle form, not quats! */
2688 AxisAngleToQuat(iquat, &td->ext->iquat[1], td->ext->iquat[0]);
2690 Mat3MulSerie(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0);
2691 Mat3ToQuat(fmat, quat); // Actual transform
2693 QuatMul(td->ext->quat, quat, iquat);
2695 /* make temp copy (since stored in same place) */
2696 QUATCOPY(quat, td->ext->quat); // this is just a 4d vector copying macro
2697 QuatToAxisAngle(quat, &td->ext->quat[1], &td->ext->quat[0]);
2699 /* this function works on end result */
2700 protectedAxisAngleBits(td->protectflag, td->ext->quat, td->ext->iquat);
2705 Mat3MulMat3(totmat, mat, td->mtx);
2706 Mat3MulMat3(smat, td->smtx, totmat);
2708 /* calculate the total rotatation in eulers */
2709 VECCOPY(eul, td->ext->irot);
2710 EulOToMat3(eul, td->rotOrder, eulmat);
2712 /* mat = transform, obmat = bone rotation */
2713 Mat3MulMat3(fmat, smat, eulmat);
2715 Mat3ToCompatibleEulO(fmat, eul, td->ext->rot, td->rotOrder);
2717 /* and apply (to end result only) */
2718 protectedRotateBits(td->protectflag, eul, td->ext->irot);
2719 VECCOPY(td->ext->rot, eul);
2722 constraintRotLim(t, td);
2726 if ((td->flag & TD_NO_LOC) == 0)
2729 VecSubf(vec, td->center, center);
2730 Mat3MulVecfl(mat, vec);
2731 VecAddf(vec, vec, center);
2732 /* vec now is the location where the object has to be */
2733 VecSubf(vec, vec, td->center);
2734 Mat3MulVecfl(td->smtx, vec);
2736 protectedTransBits(td->protectflag, vec);
2738 VecAddf(td->loc, td->iloc, vec);
2742 constraintTransLim(t, td);
2745 if ((t->flag & T_V3D_ALIGN)==0) { // align mode doesn't rotate objects itself
2746 /* euler or quaternion? */
2747 if ((td->rotOrder == ROT_MODE_QUAT) || (td->flag & TD_USEQUAT)) {
2748 Mat3MulSerie(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0);
2749 Mat3ToQuat(fmat, quat); // Actual transform
2751 QuatMul(td->ext->quat, quat, td->ext->iquat);
2752 /* this function works on end result */
2753 protectedQuaternionBits(td->protectflag, td->ext->quat, td->ext->iquat);
2755 else if (td->rotOrder == ROT_MODE_AXISANGLE) {
2756 /* calculate effect based on quats */
2759 /* td->ext->(i)quat is in axis-angle form, not quats! */
2760 AxisAngleToQuat(iquat, &td->ext->iquat[1], td->ext->iquat[0]);
2762 Mat3MulSerie(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0);
2763 Mat3ToQuat(fmat, quat); // Actual transform
2765 QuatMul(td->ext->quat, quat, iquat);
2767 /* make temp copy (since stored in same place) */
2768 QUATCOPY(quat, td->ext->quat); // this is just a 4d vector copying macro
2769 QuatToAxisAngle(quat, &td->ext->quat[1], &td->ext->quat[0]);
2771 /* this function works on end result */
2772 protectedAxisAngleBits(td->protectflag, td->ext->quat, td->ext->iquat);
2777 Mat3MulMat3(totmat, mat, td->mtx);
2778 Mat3MulMat3(smat, td->smtx, totmat);
2780 /* calculate the total rotatation in eulers */
2781 VecAddf(eul, td->ext->irot, td->ext->drot); /* we have to correct for delta rot */
2782 EulOToMat3(eul, td->rotOrder, obmat);
2783 /* mat = transform, obmat = object rotation */
2784 Mat3MulMat3(fmat, smat, obmat);
2786 Mat3ToCompatibleEulO(fmat, eul, td->ext->rot, td->rotOrder);
2788 /* correct back for delta rot */
2789 VecSubf(eul, eul, td->ext->drot);
2792 protectedRotateBits(td->protectflag, eul, td->ext->irot);
2793 VECCOPY(td->ext->rot, eul);
2796 constraintRotLim(t, td);
2801 static void applyRotation(TransInfo *t, float angle, float axis[3])
2803 TransData *td = t->data;
2807 VecRotToMat3(axis, angle, mat);
2809 for(i = 0 ; i < t->total; i++, td++) {
2811 if (td->flag & TD_NOACTION)
2814 if (td->flag & TD_SKIP)
2817 if (t->con.applyRot) {
2818 t->con.applyRot(t, td, axis, NULL);
2819 VecRotToMat3(axis, angle * td->factor, mat);
2821 else if (t->flag & T_PROP_EDIT) {
2822 VecRotToMat3(axis, angle * td->factor, mat);
2825 ElementRotation(t, td, mat, t->around);
2829 int Rotation(TransInfo *t, short mval[2])
2838 VECCOPY(axis, t->viewinv[2]);
2839 VecMulf(axis, -1.0f);
2842 final = t->values[0];
2844 applyNDofInput(&t->ndof, &final);
2846 snapGrid(t, &final);
2848 if (t->con.applyRot) {
2849 t->con.applyRot(t, NULL, axis, &final);
2852 applySnapping(t, &final);
2854 if (hasNumInput(&t->num)) {
2857 applyNumInput(&t->num, &final);
2859 outputNumInput(&(t->num), c);
2861 sprintf(str, "Rot: %s %s %s", &c[0], t->con.text, t->proptext);
2863 /* Clamp between -180 and 180 */
2864 while (final >= 180.0)
2867 while (final <= -180.0)
2870 final *= (float)(M_PI / 180.0);
2873 sprintf(str, "Rot: %.2f%s %s", 180.0*final/M_PI, t->con.text, t->proptext);
2876 VecRotToMat3(axis, final, mat);
2879 // t->values[0] = final; // used in manipulator
2880 // Mat3CpyMat3(t->mat, mat); // used in manipulator
2882 applyRotation(t, final, axis);
2886 ED_area_headerprint(t->sa, str);
2892 /* ************************** TRACKBALL *************************** */
2894 void initTrackball(TransInfo *t)
2896 t->mode = TFM_TRACKBALL;
2897 t->transform = Trackball;
2899 initMouseInputMode(t, &t->mouse, INPUT_TRACKBALL);
2902 /* Scale down input for rotation */
2903 t->ndof.factor[0] = 0.2f;
2904 t->ndof.factor[1] = 0.2f;
2909 t->snap[1] = (float)((5.0/180)*M_PI);
2910 t->snap[2] = t->snap[1] * 0.2f;
2912 t->flag |= T_NO_CONSTRAINT;
2915 static void applyTrackball(TransInfo *t, float axis1[3], float axis2[3], float angles[2])
2917 TransData *td = t->data;
2918 float mat[3][3], smat[3][3], totmat[3][3];
2921 VecRotToMat3(axis1, angles[0], smat