4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21 * All rights reserved.
23 * The Original Code is: all of this file.
25 * Contributor(s): none yet.
27 * ***** END GPL LICENSE BLOCK *****
46 #include "MEM_guardedalloc.h"
48 #include "DNA_anim_types.h"
49 #include "DNA_armature_types.h"
50 #include "DNA_action_types.h" /* for some special action-editor settings */
51 #include "DNA_constraint_types.h"
52 #include "DNA_ipo_types.h" /* some silly ipo flag */
53 #include "DNA_listBase.h"
54 #include "DNA_meshdata_types.h"
55 #include "DNA_mesh_types.h"
56 #include "DNA_object_types.h"
57 #include "DNA_scene_types.h" /* PET modes */
58 #include "DNA_screen_types.h" /* area dimensions */
59 #include "DNA_texture_types.h"
60 #include "DNA_userdef_types.h"
61 #include "DNA_view3d_types.h"
62 #include "DNA_space_types.h"
63 #include "DNA_windowmanager_types.h"
65 #include "RNA_access.h"
67 //#include "BIF_editview.h" /* arrows_move_cursor */
69 #include "BIF_glutil.h"
70 //#include "BIF_mywindow.h"
71 //#include "BIF_resources.h"
72 //#include "BIF_screen.h"
73 //#include "BIF_space.h" /* undo */
74 //#include "BIF_toets.h" /* persptoetsen */
75 //#include "BIF_mywindow.h" /* warp_pointer */
76 //#include "BIF_toolbox.h" /* notice */
77 //#include "BIF_editmesh.h"
78 //#include "BIF_editsima.h"
79 //#include "BIF_editparticle.h"
81 #include "BKE_action.h"
83 //#include "BKE_bad_level_calls.h"/* popmenu and error */
84 #include "BKE_bmesh.h"
85 #include "BKE_context.h"
86 #include "BKE_constraint.h"
87 #include "BKE_global.h"
88 #include "BKE_particle.h"
89 #include "BKE_pointcache.h"
90 #include "BKE_utildefines.h"
91 #include "BKE_context.h"
93 //#include "BSE_view.h"
96 #include "ED_screen.h"
97 #include "ED_space_api.h"
98 #include "ED_markers.h"
100 #include "ED_view3d.h"
102 #include "UI_view2d.h"
103 #include "WM_types.h"
106 #include "BLI_arithb.h"
107 #include "BLI_blenlib.h"
108 #include "BLI_editVert.h"
110 #include "PIL_time.h" /* sleep */
112 #include "UI_resources.h"
114 //#include "blendef.h"
116 //#include "mydevice.h"
118 #include "transform.h"
120 /* ************************** SPACE DEPENDANT CODE **************************** */
122 void setTransformViewMatrices(TransInfo *t)
124 if(t->spacetype==SPACE_VIEW3D && t->ar->regiontype == RGN_TYPE_WINDOW) {
125 RegionView3D *rv3d = t->ar->regiondata;
127 Mat4CpyMat4(t->viewmat, rv3d->viewmat);
128 Mat4CpyMat4(t->viewinv, rv3d->viewinv);
129 Mat4CpyMat4(t->persmat, rv3d->persmat);
130 Mat4CpyMat4(t->persinv, rv3d->persinv);
131 t->persp = rv3d->persp;
138 t->persp = V3D_ORTHO;
141 calculateCenter2D(t);
144 void convertViewVec(TransInfo *t, float *vec, short dx, short dy)
146 if (t->spacetype==SPACE_VIEW3D) {
147 if (t->ar->regiontype == RGN_TYPE_WINDOW)
149 window_to_3d_delta(t->ar, vec, dx, dy);
152 else if(t->spacetype==SPACE_IMAGE) {
153 View2D *v2d = t->view;
154 float divx, divy, aspx, aspy;
156 ED_space_image_uv_aspect(t->sa->spacedata.first, &aspx, &aspy);
158 divx= v2d->mask.xmax-v2d->mask.xmin;
159 divy= v2d->mask.ymax-v2d->mask.ymin;
161 vec[0]= aspx*(v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx;
162 vec[1]= aspy*(v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy;
165 else if(ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)) {
166 View2D *v2d = t->view;
169 divx= v2d->mask.xmax-v2d->mask.xmin;
170 divy= v2d->mask.ymax-v2d->mask.ymin;
172 vec[0]= (v2d->cur.xmax-v2d->cur.xmin)*(dx) / (divx);
173 vec[1]= (v2d->cur.ymax-v2d->cur.ymin)*(dy) / (divy);
176 else if(t->spacetype==SPACE_NODE) {
177 View2D *v2d = &t->ar->v2d;
180 divx= v2d->mask.xmax-v2d->mask.xmin;
181 divy= v2d->mask.ymax-v2d->mask.ymin;
183 vec[0]= (v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx;
184 vec[1]= (v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy;
187 else if(t->spacetype==SPACE_SEQ) {
188 View2D *v2d = &t->ar->v2d;
191 divx= v2d->mask.xmax-v2d->mask.xmin;
192 divy= v2d->mask.ymax-v2d->mask.ymin;
194 vec[0]= (v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx;
195 vec[1]= (v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy;
200 void projectIntView(TransInfo *t, float *vec, int *adr)
202 if (t->spacetype==SPACE_VIEW3D) {
203 if(t->ar->regiontype == RGN_TYPE_WINDOW)
204 project_int_noclip(t->ar, vec, adr);
206 else if(t->spacetype==SPACE_IMAGE) {
207 float aspx, aspy, v[2];
209 ED_space_image_uv_aspect(t->sa->spacedata.first, &aspx, &aspy);
213 UI_view2d_to_region_no_clip(t->view, v[0], v[1], adr, adr+1);
215 else if(ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)) {
218 UI_view2d_view_to_region((View2D *)t->view, vec[0], vec[1], out, out+1);
222 else if(t->spacetype==SPACE_SEQ) { /* XXX not tested yet, but should work */
225 UI_view2d_view_to_region((View2D *)t->view, vec[0], vec[1], out, out+1);
231 void projectFloatView(TransInfo *t, float *vec, float *adr)
233 if (t->spacetype==SPACE_VIEW3D) {
234 if(t->ar->regiontype == RGN_TYPE_WINDOW)
235 project_float_noclip(t->ar, vec, adr);
237 else if(t->spacetype==SPACE_IMAGE) {
240 projectIntView(t, vec, a);
244 else if(ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)) {
247 projectIntView(t, vec, a);
253 void applyAspectRatio(TransInfo *t, float *vec)
255 SpaceImage *sima= t->sa->spacedata.first;
257 if ((t->spacetype==SPACE_IMAGE) && (t->mode==TFM_TRANSLATION)) {
260 if((sima->flag & SI_COORDFLOATS)==0) {
262 ED_space_image_size(sima, &width, &height);
268 ED_space_image_uv_aspect(sima, &aspx, &aspy);
274 void removeAspectRatio(TransInfo *t, float *vec)
276 SpaceImage *sima= t->sa->spacedata.first;
278 if ((t->spacetype==SPACE_IMAGE) && (t->mode==TFM_TRANSLATION)) {
281 if((sima->flag & SI_COORDFLOATS)==0) {
283 ED_space_image_size(sima, &width, &height);
289 ED_space_image_uv_aspect(sima, &aspx, &aspy);
295 static void viewRedrawForce(bContext *C, TransInfo *t)
297 if (t->spacetype == SPACE_VIEW3D)
299 /* Do we need more refined tags? */
300 WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
302 else if (t->spacetype == SPACE_ACTION) {
303 //SpaceAction *saction= (SpaceAction *)t->sa->spacedata.first;
304 WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME_EDIT, NULL);
306 else if (t->spacetype == SPACE_IPO) {
307 //SpaceIpo *sipo= (SpaceIpo *)t->sa->spacedata.first;
308 WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME_EDIT, NULL);
310 else if (t->spacetype == SPACE_NLA) {
311 WM_event_add_notifier(C, NC_ANIMATION|ND_NLA_EDIT, NULL);
313 else if(t->spacetype == SPACE_NODE)
315 //ED_area_tag_redraw(t->sa);
316 WM_event_add_notifier(C, NC_SCENE|ND_NODES, NULL);
318 else if(t->spacetype == SPACE_SEQ)
320 WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, NULL);
322 else if (t->spacetype==SPACE_IMAGE) {
323 // XXX how to deal with lock?
325 SpaceImage *sima= (SpaceImage*)t->sa->spacedata.first;
326 if(sima->lock) force_draw_plus(SPACE_VIEW3D, 0);
330 WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_DATA, t->obedit);
334 static void viewRedrawPost(TransInfo *t)
336 ED_area_headerprint(t->sa, NULL);
338 #if 0 // TRANSFORM_FIX_ME
339 if(t->spacetype==SPACE_VIEW3D) {
340 allqueue(REDRAWBUTSOBJECT, 0);
341 allqueue(REDRAWVIEW3D, 0);
343 else if(t->spacetype==SPACE_IMAGE) {
344 allqueue(REDRAWIMAGE, 0);
345 allqueue(REDRAWVIEW3D, 0);
347 else if(ELEM3(t->spacetype, SPACE_ACTION, SPACE_NLA, SPACE_IPO)) {
348 allqueue(REDRAWVIEW3D, 0);
349 allqueue(REDRAWACTION, 0);
350 allqueue(REDRAWNLA, 0);
351 allqueue(REDRAWIPO, 0);
352 allqueue(REDRAWTIME, 0);
353 allqueue(REDRAWBUTSOBJECT, 0);
356 scrarea_queue_headredraw(curarea);
360 /* ************************** TRANSFORMATIONS **************************** */
362 void BIF_selectOrientation() {
363 #if 0 // TRANSFORM_FIX_ME
365 char *str_menu = BIF_menustringTransformOrientation("Orientation");
366 val= pupmenu(str_menu);
375 static void view_editmove(unsigned short event)
377 #if 0 // TRANSFORM_FIX_ME
379 /* Regular: Zoom in */
380 /* Shift: Scroll up */
381 /* Ctrl: Scroll right */
382 /* Alt-Shift: Rotate up */
383 /* Alt-Ctrl: Rotate right */
385 /* only work in 3D window for now
386 * In the end, will have to send to event to a 2D window handler instead
388 if (Trans.flag & T_2D_EDIT)
394 if( G.qual & LR_SHIFTKEY ) {
395 if( G.qual & LR_ALTKEY ) {
396 G.qual &= ~LR_SHIFTKEY;
398 G.qual |= LR_SHIFTKEY;
402 } else if( G.qual & LR_CTRLKEY ) {
403 if( G.qual & LR_ALTKEY ) {
404 G.qual &= ~LR_CTRLKEY;
406 G.qual |= LR_CTRLKEY;
410 } else if(U.uiflag & USER_WHEELZOOMDIR)
411 persptoetsen(PADMINUS);
413 persptoetsen(PADPLUSKEY);
418 if( G.qual & LR_SHIFTKEY ) {
419 if( G.qual & LR_ALTKEY ) {
420 G.qual &= ~LR_SHIFTKEY;
422 G.qual |= LR_SHIFTKEY;
426 } else if( G.qual & LR_CTRLKEY ) {
427 if( G.qual & LR_ALTKEY ) {
428 G.qual &= ~LR_CTRLKEY;
430 G.qual |= LR_CTRLKEY;
434 } else if(U.uiflag & USER_WHEELZOOMDIR)
435 persptoetsen(PADPLUSKEY);
437 persptoetsen(PADMINUS);
444 setTransformViewMatrices(&Trans);
449 static char *transform_to_undostr(TransInfo *t)
452 case TFM_TRANSLATION:
464 case TFM_SHRINKFATTEN:
465 return "Shrink/Fatten";
475 return "Bevel Weight";
480 case TFM_BONE_ENVELOPE:
481 return "Bone Envelope";
482 case TFM_TIME_TRANSLATE:
483 return "Translate Anim. Data";
485 return "Scale Anim. Data";
497 /* ************************************************* */
499 void transformEvent(TransInfo *t, wmEvent *event)
501 float mati[3][3] = {{1.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 1.0f}};
502 char cmode = constraintModeToChar(t);
504 t->redraw |= handleMouseInput(t, &t->mouse, event);
506 if (event->type == MOUSEMOVE)
508 t->mval[0] = event->x - t->ar->winrct.xmin;
509 t->mval[1] = event->y - t->ar->winrct.ymin;
513 applyMouseInput(t, &t->mouse, t->mval, t->values);
517 switch (event->type){
518 /* enforce redraw of transform when modifiers are used */
521 t->modifiers |= MOD_SNAP_GEARS;
527 t->modifiers |= MOD_CONSTRAINT_PLANE;
532 if ((t->spacetype==SPACE_VIEW3D) && event->alt) {
533 #if 0 // TRANSFORM_FIX_ME
537 BIF_selectOrientation();
538 calc_manipulator_stats(curarea);
539 Mat3CpyMat4(t->spacemtx, G.vd->twmat);
540 warp_pointer(mval[0], mval[1]);
544 t->state = TRANS_CONFIRM;
549 if ((t->flag & T_NO_CONSTRAINT)==0) {
550 /* exception for switching to dolly, or trackball, in camera view */
551 if (t->flag & T_CAMERA) {
552 if (t->mode==TFM_TRANSLATION)
553 setLocalConstraint(t, (CON_AXIS2), "along local Z");
554 else if (t->mode==TFM_ROTATION) {
555 restoreTransObjects(t);
560 t->modifiers |= MOD_CONSTRAINT_SELECT;
561 if (t->con.mode & CON_APPLY) {
566 initSelectConstraint(t, t->spacemtx);
569 /* bit hackish... but it prevents mmb select to print the orientation from menu */
570 strcpy(t->spacename, "global");
571 initSelectConstraint(t, mati);
573 postSelectConstraint(t);
580 t->state = TRANS_CANCEL;
584 t->state = TRANS_CONFIRM;
587 /* only switch when... */
588 if( ELEM3(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL) ) {
589 resetTransRestrictions(t);
590 restoreTransObjects(t);
592 initSnapping(t, NULL); // need to reinit after mode change
597 /* only switch when... */
598 if( ELEM3(t->mode, TFM_ROTATION, TFM_TRANSLATION, TFM_TRACKBALL) ) {
599 resetTransRestrictions(t);
600 restoreTransObjects(t);
602 initSnapping(t, NULL); // need to reinit after mode change
607 /* only switch when... */
608 if( ELEM4(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL, TFM_TRANSLATION) ) {
610 resetTransRestrictions(t);
612 if (t->mode == TFM_ROTATION) {
613 restoreTransObjects(t);
617 restoreTransObjects(t);
620 initSnapping(t, NULL); // need to reinit after mode change
626 t->flag ^= T_PROP_CONNECTED;
627 sort_trans_data_dist(t);
628 calculatePropRatio(t);
637 if ((t->flag & T_NO_CONSTRAINT)==0) {
639 if (t->flag & T_2D_EDIT) {
643 if (t->con.mode & CON_USER) {
647 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
648 setUserConstraint(t, (CON_AXIS0), "along %s X");
649 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
650 setUserConstraint(t, (CON_AXIS1|CON_AXIS2), "locking %s X");
655 if (t->flag & T_2D_EDIT) {
656 setConstraint(t, mati, (CON_AXIS0), "along X axis");
659 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
660 setConstraint(t, mati, (CON_AXIS0), "along global X");
661 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
662 setConstraint(t, mati, (CON_AXIS1|CON_AXIS2), "locking global X");
669 if ((t->flag & T_NO_CONSTRAINT)==0) {
671 if (t->flag & T_2D_EDIT) {
675 if (t->con.mode & CON_USER) {
679 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
680 setUserConstraint(t, (CON_AXIS1), "along %s Y");
681 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
682 setUserConstraint(t, (CON_AXIS0|CON_AXIS2), "locking %s Y");
687 if (t->flag & T_2D_EDIT) {
688 setConstraint(t, mati, (CON_AXIS1), "along Y axis");
691 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
692 setConstraint(t, mati, (CON_AXIS1), "along global Y");
693 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
694 setConstraint(t, mati, (CON_AXIS0|CON_AXIS2), "locking global Y");
701 if ((t->flag & T_NO_CONSTRAINT)==0) {
703 if (t->con.mode & CON_USER) {
707 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
708 setUserConstraint(t, (CON_AXIS2), "along %s Z");
709 else if ((t->modifiers & MOD_CONSTRAINT_PLANE) && ((t->flag & T_2D_EDIT)==0))
710 setUserConstraint(t, (CON_AXIS0|CON_AXIS1), "locking %s Z");
713 else if ((t->flag & T_2D_EDIT)==0) {
714 if ((t->modifiers & MOD_CONSTRAINT_PLANE) == 0)
715 setConstraint(t, mati, (CON_AXIS2), "along global Z");
716 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
717 setConstraint(t, mati, (CON_AXIS0|CON_AXIS1), "locking global Z");
723 if (t->flag & T_PROP_EDIT && event->shift) {
724 t->prop_mode = (t->prop_mode + 1) % 6;
725 calculatePropRatio(t);
730 if(event->alt && t->flag & T_PROP_EDIT) {
731 t->prop_size *= 1.1f;
732 calculatePropRatio(t);
738 if (t->flag & T_AUTOIK) {
739 transform_autoik_update(t, 1);
741 else if(t->flag & T_PROP_EDIT) {
743 calculatePropRatio(t);
745 else view_editmove(event->type);
749 if(event->alt && t->flag & T_PROP_EDIT) {
750 t->prop_size*= 0.90909090f;
751 calculatePropRatio(t);
757 if (t->flag & T_AUTOIK) {
758 transform_autoik_update(t, -1);
760 else if (t->flag & T_PROP_EDIT) {
761 t->prop_size*= 0.90909090f;
762 calculatePropRatio(t);
764 else view_editmove(event->type);
772 // Numerical input events
773 t->redraw |= handleNumInput(&(t->num), event);
776 switch(handleNDofInput(&(t->ndof), event))
779 if ((t->options & CTX_NDOF) == 0)
781 /* Confirm on normal transform only */
782 t->state = TRANS_CONFIRM;
786 if (t->options & CTX_NDOF)
788 /* Cancel on pure NDOF transform */
789 t->state = TRANS_CANCEL;
793 /* Otherwise, just redraw, NDof input was cancelled */
798 if (t->options & CTX_NDOF)
800 /* Confirm on pure NDOF transform */
801 t->state = TRANS_CONFIRM;
811 t->redraw |= handleSnapping(t, event);
813 //arrows_move_cursor(event->type);
816 switch (event->type){
818 t->state = TRANS_CANCEL;
821 t->state = TRANS_CONFIRM;
825 t->modifiers &= ~MOD_CONSTRAINT_PLANE;
831 t->modifiers &= ~MOD_SNAP_GEARS;
832 /* no redraw on release modifier keys! this makes sure you can assign the 'grid' still
833 after releasing modifer key */
837 if ((t->flag & T_NO_CONSTRAINT)==0) {
838 t->modifiers &= ~MOD_CONSTRAINT_SELECT;
839 postSelectConstraint(t);
845 // if(WM_modal_tweak_exit(event, t->event_type))
846 //// if (t->options & CTX_TWEAK)
847 // t->state = TRANS_CONFIRM;
852 // Per transform event, if present
854 t->redraw |= t->handleEvent(t, event);
857 int calculateTransformCenter(bContext *C, wmEvent *event, int centerMode, float *vec)
859 TransInfo *t = MEM_callocN(sizeof(TransInfo), "TransInfo data");
862 t->state = TRANS_RUNNING;
864 t->options = CTX_NONE;
868 initTransInfo(C, t, NULL, event); // internal data, mouse, vectors
870 createTransData(C, t); // make TransData structs from selection
872 t->around = centerMode; // override userdefined mode
882 // Copy center from constraint center. Transform center can be local
883 VECCOPY(vec, t->con.center);
888 /* aftertrans does insert ipos and action channels, and clears base flags, doesnt read transdata */
889 special_aftertrans_update(t);
902 static void drawArrow(ArrowDirection d, short offset, short length, short size)
912 glVertex2s( offset, 0);
913 glVertex2s( offset + length, 0);
914 glVertex2s( offset + length, 0);
915 glVertex2s( offset + length - size, -size);
916 glVertex2s( offset + length, 0);
917 glVertex2s( offset + length - size, size);
926 glVertex2s( 0, offset);
927 glVertex2s( 0, offset + length);
928 glVertex2s( 0, offset + length);
929 glVertex2s(-size, offset + length - size);
930 glVertex2s( 0, offset + length);
931 glVertex2s( size, offset + length - size);
937 static void drawArrowHead(ArrowDirection d, short size)
946 glVertex2s( -size, -size);
948 glVertex2s( -size, size);
956 glVertex2s(-size, -size);
958 glVertex2s( size, -size);
964 static void drawArc(float size, float angle_start, float angle_end, int segments)
966 float delta = (angle_end - angle_start) / segments;
969 glBegin(GL_LINE_STRIP);
971 for( angle = angle_start; angle < angle_end; angle += delta)
973 glVertex2f( cosf(angle) * size, sinf(angle) * size);
975 glVertex2f( cosf(angle_end) * size, sinf(angle_end) * size);
980 void drawHelpline(const struct bContext *C, TransInfo *t)
982 if (t->helpline != HLP_NONE && !(t->flag & T_USES_MANIPULATOR))
984 float vecrot[3], cent[2];
986 VECCOPY(vecrot, t->center);
987 if(t->flag & T_EDIT) {
988 Object *ob= t->obedit;
989 if(ob) Mat4MulVecfl(ob->obmat, vecrot);
991 else if(t->flag & T_POSE) {
992 Object *ob=t->poseobj;
993 if(ob) Mat4MulVecfl(ob->obmat, vecrot);
996 projectFloatView(t, vecrot, cent); // no overflow in extreme cases
998 glDisable(GL_DEPTH_TEST);
1000 glMatrixMode(GL_PROJECTION);
1002 glMatrixMode(GL_MODELVIEW);
1005 ED_region_pixelspace(t->ar);
1010 UI_ThemeColor(TH_WIRE);
1013 glBegin(GL_LINE_STRIP);
1014 glVertex2sv(t->mval);
1018 glTranslatef(t->mval[0], t->mval[1], 0);
1019 glRotatef(-180 / M_PI * atan2f(cent[0] - t->mval[0], cent[1] - t->mval[1]), 0, 0, 1);
1023 drawArrow(UP, 5, 10, 5);
1024 drawArrow(DOWN, 5, 10, 5);
1028 UI_ThemeColor(TH_WIRE);
1030 glTranslatef(t->mval[0], t->mval[1], 0);
1033 drawArrow(RIGHT, 5, 10, 5);
1034 drawArrow(LEFT, 5, 10, 5);
1038 UI_ThemeColor(TH_WIRE);
1040 glTranslatef(t->mval[0], t->mval[1], 0);
1044 drawArrow(UP, 5, 10, 5);
1045 drawArrow(DOWN, 5, 10, 5);
1050 float dx = t->mval[0] - cent[0], dy = t->mval[1] - cent[1];
1051 float angle = atan2f(dy, dx);
1052 float dist = sqrtf(dx*dx + dy*dy);
1053 float delta_angle = MIN2(15 / dist, M_PI/4);
1054 float spacing_angle = MIN2(5 / dist, M_PI/12);
1055 UI_ThemeColor(TH_WIRE);
1058 glBegin(GL_LINE_STRIP);
1059 glVertex2sv(t->mval);
1063 glTranslatef(cent[0], cent[1], 0);
1067 drawArc(dist, angle - delta_angle, angle - spacing_angle, 10);
1068 drawArc(dist, angle + spacing_angle, angle + delta_angle, 10);
1072 glTranslatef(cosf(angle - delta_angle) * dist, sinf(angle - delta_angle) * dist, 0);
1073 glRotatef(180 / M_PI * (angle - delta_angle), 0, 0, 1);
1075 drawArrowHead(DOWN, 5);
1079 glTranslatef(cosf(angle + delta_angle) * dist, sinf(angle + delta_angle) * dist, 0);
1080 glRotatef(180 / M_PI * (angle + delta_angle), 0, 0, 1);
1082 drawArrowHead(UP, 5);
1089 char col[3], col2[3];
1090 UI_GetThemeColor3ubv(TH_GRID, col);
1092 glTranslatef(t->mval[0], t->mval[1], 0);
1096 UI_make_axis_color(col, col2, 'x');
1097 glColor3ubv((GLubyte *)col2);
1099 drawArrow(RIGHT, 5, 10, 5);
1100 drawArrow(LEFT, 5, 10, 5);
1102 UI_make_axis_color(col, col2, 'y');
1103 glColor3ubv((GLubyte *)col2);
1105 drawArrow(UP, 5, 10, 5);
1106 drawArrow(DOWN, 5, 10, 5);
1112 glMatrixMode(GL_PROJECTION);
1114 glMatrixMode(GL_MODELVIEW);
1117 glEnable(GL_DEPTH_TEST);
1121 void drawTransform(const struct bContext *C, struct ARegion *ar, void *arg)
1125 drawConstraint(C, t);
1126 drawPropCircle(C, t);
1131 void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
1133 ToolSettings *ts = CTX_data_tool_settings(C);
1134 int constraint_axis[3] = {0, 0, 0};
1135 int proportional = 0;
1137 if (t->flag & T_AUTOVALUES)
1139 RNA_float_set_array(op->ptr, "value", t->auto_values);
1143 RNA_float_set_array(op->ptr, "value", t->values);
1146 /* XXX convert stupid flag to enum */
1147 switch(t->flag & (T_PROP_EDIT|T_PROP_CONNECTED))
1149 case (T_PROP_EDIT|T_PROP_CONNECTED):
1159 if (RNA_struct_find_property(op->ptr, "proportional"))
1161 RNA_enum_set(op->ptr, "proportional", proportional);
1162 RNA_enum_set(op->ptr, "proportional_editing_falloff", t->prop_mode);
1163 RNA_float_set(op->ptr, "proportional_size", t->prop_size);
1166 if (RNA_struct_find_property(op->ptr, "mirror"))
1168 RNA_boolean_set(op->ptr, "mirror", t->flag & T_MIRROR);
1171 if (RNA_struct_find_property(op->ptr, "constraint_axis"))
1173 RNA_int_set(op->ptr, "constraint_orientation", t->current_orientation);
1175 if (t->con.mode & CON_APPLY)
1177 if (t->con.mode & CON_AXIS0) {
1178 constraint_axis[0] = 1;
1180 if (t->con.mode & CON_AXIS1) {
1181 constraint_axis[1] = 1;
1183 if (t->con.mode & CON_AXIS2) {
1184 constraint_axis[2] = 1;
1188 RNA_boolean_set_array(op->ptr, "constraint_axis", constraint_axis);
1191 // XXX If modal, save settings back in scene
1192 if (t->flag & T_MODAL)
1194 ts->prop_mode = t->prop_mode;
1195 ts->proportional = proportional;
1197 if(t->spacetype == SPACE_VIEW3D)
1199 View3D *v3d = t->view;
1201 v3d->twmode = t->current_orientation;
1206 int initTransform(bContext *C, TransInfo *t, wmOperator *op, wmEvent *event, int mode)
1210 /* added initialize, for external calls to set stuff in TransInfo, like undo string */
1212 t->state = TRANS_RUNNING;
1214 t->options = options;
1218 if (!initTransInfo(C, t, op, event)) // internal data, mouse, vectors
1223 if(t->spacetype == SPACE_VIEW3D)
1225 //calc_manipulator_stats(curarea);
1226 initTransformOrientation(C, t);
1228 t->draw_handle = ED_region_draw_cb_activate(t->ar->type, drawTransform, t, REGION_DRAW_POST);
1230 else if(t->spacetype == SPACE_IMAGE) {
1231 Mat3One(t->spacemtx);
1232 t->draw_handle = ED_region_draw_cb_activate(t->ar->type, drawTransform, t, REGION_DRAW_POST);
1235 Mat3One(t->spacemtx);
1237 createTransData(C, t); // make TransData structs from selection
1239 if (t->total == 0) {
1244 initSnapping(t, op); // Initialize snapping data AFTER mode flags
1246 /* EVIL! posemode code can switch translation to rotate when 1 bone is selected. will be removed (ton) */
1247 /* EVIL2: we gave as argument also texture space context bit... was cleared */
1248 /* EVIL3: extend mode for animation editors also switches modes... but is best way to avoid duplicate code */
1251 calculatePropRatio(t);
1254 initMouseInput(t, &t->mouse, t->center2d, t->imval);
1257 case TFM_TRANSLATION:
1275 case TFM_SHRINKFATTEN:
1276 initShrinkFatten(t);
1281 case TFM_CURVE_SHRINKFATTEN:
1282 initCurveShrinkFatten(t);
1294 { /* used for both B-Bone width (bonesize) as for deform-dist (envelope) */
1295 bArmature *arm= t->poseobj->data;
1296 if(arm->drawtype==ARM_ENVELOPE)
1297 initBoneEnvelope(t);
1302 case TFM_BONE_ENVELOPE:
1303 initBoneEnvelope(t);
1308 case TFM_TIME_TRANSLATE:
1309 initTimeTranslate(t);
1311 case TFM_TIME_SLIDE:
1314 case TFM_TIME_SCALE:
1317 case TFM_TIME_EXTEND:
1318 /* now that transdata has been made, do like for TFM_TIME_TRANSLATE (for most Animation
1319 * Editors because they have only 1D transforms for time values) or TFM_TRANSLATION
1320 * (for Graph/NLA Editors only since they uses 'standard' transforms to get 2D movement)
1321 * depending on which editor this was called from
1323 if ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)
1326 initTimeTranslate(t);
1345 /* overwrite initial values if operator supplied a non-null vector */
1346 if (RNA_property_is_set(op->ptr, "value"))
1349 RNA_float_get_array(op->ptr, "value", values);
1350 QUATCOPY(t->values, values);
1351 QUATCOPY(t->auto_values, values);
1352 t->flag |= T_AUTOVALUES;
1355 /* Constraint init from operator */
1356 if (RNA_struct_find_property(op->ptr, "constraint_axis") && RNA_property_is_set(op->ptr, "constraint_axis"))
1358 int constraint_axis[3];
1360 RNA_boolean_get_array(op->ptr, "constraint_axis", constraint_axis);
1362 if (constraint_axis[0] || constraint_axis[1] || constraint_axis[2])
1364 t->con.mode |= CON_APPLY;
1366 if (constraint_axis[0]) {
1367 t->con.mode |= CON_AXIS0;
1369 if (constraint_axis[1]) {
1370 t->con.mode |= CON_AXIS1;
1372 if (constraint_axis[2]) {
1373 t->con.mode |= CON_AXIS2;
1376 setUserConstraint(t, t->con.mode, "%s");
1383 void transformApply(bContext *C, TransInfo *t)
1387 if (t->modifiers & MOD_CONSTRAINT_SELECT)
1388 t->con.mode |= CON_SELECT;
1390 selectConstraint(t);
1392 t->transform(t, t->mval); // calls recalcData()
1393 viewRedrawForce(C, t);
1398 /* If auto confirm is on, break after one pass */
1399 if (t->options & CTX_AUTOCONFIRM)
1401 t->state = TRANS_CONFIRM;
1404 if (BKE_ptcache_get_continue_physics())
1407 //do_screenhandlers(G.curscreen);
1412 int transformEnd(bContext *C, TransInfo *t)
1414 int exit_code = OPERATOR_RUNNING_MODAL;
1416 if (t->state != TRANS_RUNNING)
1418 /* handle restoring objects */
1419 if(t->state == TRANS_CANCEL)
1421 exit_code = OPERATOR_CANCELLED;
1422 restoreTransObjects(t); // calls recalcData()
1426 exit_code = OPERATOR_FINISHED;
1432 /* aftertrans does insert keyframes, and clears base flags, doesnt read transdata */
1433 special_aftertrans_update(t);
1435 /* send events out for redraws */
1438 /* Undo as last, certainly after special_trans_update! */
1440 if(t->state == TRANS_CANCEL) {
1441 // if(t->undostr) ED_undo_push(C, t->undostr);
1444 // if(t->undostr) ED_undo_push(C, t->undostr);
1445 // else ED_undo_push(C, transform_to_undostr(t));
1449 viewRedrawForce(C, t);
1455 /* ************************** Manipulator init and main **************************** */
1457 void initManipulator(int mode)
1459 printf("init manipulator mode %d\n", mode);
1461 #if 0 // TRANSFORM_FIX_ME
1462 Trans.state = TRANS_RUNNING;
1464 Trans.options = CTX_NONE;
1468 /* automatic switch to scaling bone envelopes */
1469 if(mode==TFM_RESIZE && t->obedit && t->obedit->type==OB_ARMATURE) {
1470 bArmature *arm= t->obedit->data;
1471 if(arm->drawtype==ARM_ENVELOPE)
1472 mode= TFM_BONE_ENVELOPE;
1475 initTrans(&Trans); // internal data, mouse, vectors
1477 G.moving |= G_TRANSFORM_MANIP; // signal to draw manipuls while transform
1478 createTransData(&Trans); // make TransData structs from selection
1480 if (Trans.total == 0)
1483 initSnapping(&Trans); // Initialize snapping data AFTER mode flags
1485 /* EVIL! posemode code can switch translation to rotate when 1 bone is selected. will be removed (ton) */
1486 /* EVIL2: we gave as argument also texture space context bit... was cleared */
1489 calculatePropRatio(&Trans);
1490 calculateCenter(&Trans);
1493 case TFM_TRANSLATION:
1494 initTranslation(&Trans);
1497 initRotation(&Trans);
1503 initTrackball(&Trans);
1507 Trans.flag |= T_USES_MANIPULATOR;
1511 void ManipulatorTransform()
1513 #if 0 // TRANSFORM_FIX_ME
1514 int mouse_moved = 0;
1515 short pmval[2] = {0, 0}, mval[2], val;
1516 unsigned short event;
1518 if (Trans.total == 0)
1521 Trans.redraw = 1; /* initial draw */
1523 while (Trans.state == TRANS_RUNNING) {
1525 getmouseco_areawin(mval);
1527 if (mval[0] != pmval[0] || mval[1] != pmval[1]) {
1534 //selectConstraint(&Trans); needed?
1535 if (Trans.transform) {
1536 Trans.transform(&Trans, mval);
1541 /* essential for idling subloop */
1542 if( qtest()==0) PIL_sleep_ms(2);
1545 event= extern_qread(&val);
1552 /* enforce redraw of transform when modifiers are used */
1555 if(val) Trans.redraw = 1;
1559 /* shift is modifier for higher resolution transform, works nice to store this mouse position */
1561 getmouseco_areawin(Trans.shiftmval);
1562 Trans.flag |= T_SHIFT_MOD;
1565 else Trans.flag &= ~T_SHIFT_MOD;
1570 Trans.state = TRANS_CANCEL;
1573 if(mouse_moved==0 && val==0) break;
1574 // else we pass on event to next, which cancels
1578 Trans.state = TRANS_CONFIRM;
1587 if(G.qual & LR_ALTKEY && Trans.flag & T_PROP_EDIT) {
1588 Trans.propsize*= 1.1f;
1589 calculatePropRatio(&Trans);
1594 case WHEELDOWNMOUSE:
1595 if (Trans.flag & T_AUTOIK) {
1596 transform_autoik_update(&Trans, 1);
1598 else if(Trans.flag & T_PROP_EDIT) {
1599 Trans.propsize*= 1.1f;
1600 calculatePropRatio(&Trans);
1602 else view_editmove(event);
1606 if(G.qual & LR_ALTKEY && Trans.flag & T_PROP_EDIT) {
1607 Trans.propsize*= 0.90909090f;
1608 calculatePropRatio(&Trans);
1614 if (Trans.flag & T_AUTOIK) {
1615 transform_autoik_update(&Trans, -1);
1617 else if (Trans.flag & T_PROP_EDIT) {
1618 Trans.propsize*= 0.90909090f;
1619 calculatePropRatio(&Trans);
1621 else view_editmove(event);
1626 // Numerical input events
1627 Trans.redraw |= handleNumInput(&(Trans.num), event);
1632 if(Trans.state == TRANS_CANCEL) {
1633 restoreTransObjects(&Trans);
1636 /* free data, reset vars */
1639 /* aftertrans does insert ipos and action channels, and clears base flags */
1640 special_aftertrans_update(&Trans);
1642 /* send events out for redraws */
1643 viewRedrawPost(&Trans);
1645 if(Trans.state != TRANS_CANCEL) {
1646 BIF_undo_push(transform_to_undostr(&Trans));
1651 /* ************************** TRANSFORM LOCKS **************************** */
1653 static void protectedTransBits(short protectflag, float *vec)
1655 if(protectflag & OB_LOCK_LOCX)
1657 if(protectflag & OB_LOCK_LOCY)
1659 if(protectflag & OB_LOCK_LOCZ)
1663 static void protectedSizeBits(short protectflag, float *size)
1665 if(protectflag & OB_LOCK_SCALEX)
1667 if(protectflag & OB_LOCK_SCALEY)
1669 if(protectflag & OB_LOCK_SCALEZ)
1673 static void protectedRotateBits(short protectflag, float *eul, float *oldeul)
1675 if(protectflag & OB_LOCK_ROTX)
1677 if(protectflag & OB_LOCK_ROTY)
1679 if(protectflag & OB_LOCK_ROTZ)
1683 static void protectedQuaternionBits(short protectflag, float *quat, float *oldquat)
1685 /* quaternions get limited with euler... */
1686 /* this function only does the delta rotation */
1689 float eul[3], oldeul[3], quat1[4];
1691 QUATCOPY(quat1, quat);
1692 QuatToEul(quat, eul);
1693 QuatToEul(oldquat, oldeul);
1695 if(protectflag & OB_LOCK_ROTX)
1697 if(protectflag & OB_LOCK_ROTY)
1699 if(protectflag & OB_LOCK_ROTZ)
1702 EulToQuat(eul, quat);
1703 /* quaternions flip w sign to accumulate rotations correctly */
1704 if( (quat1[0]<0.0f && quat[0]>0.0f) || (quat1[0]>0.0f && quat[0]<0.0f) ) {
1705 QuatMulf(quat, -1.0f);
1710 /* ******************* TRANSFORM LIMITS ********************** */
1712 static void constraintTransLim(TransInfo *t, TransData *td)
1715 bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_LOCLIMIT);
1719 /* Make a temporary bConstraintOb for using these limit constraints
1720 * - they only care that cob->matrix is correctly set ;-)
1721 * - current space should be local
1723 memset(&cob, 0, sizeof(bConstraintOb));
1724 Mat4One(cob.matrix);
1726 TransDataIpokey *tdi= td->tdi;
1727 cob.matrix[3][0]= tdi->locx[0];
1728 cob.matrix[3][1]= tdi->locy[0];
1729 cob.matrix[3][2]= tdi->locz[0];
1732 VECCOPY(cob.matrix[3], td->loc);
1735 /* Evaluate valid constraints */
1736 for (con= td->con; con; con= con->next) {
1739 /* only consider constraint if enabled */
1740 if (con->flag & CONSTRAINT_DISABLE) continue;
1741 if (con->enforce == 0.0f) continue;
1743 /* only use it if it's tagged for this purpose (and the right type) */
1744 if (con->type == CONSTRAINT_TYPE_LOCLIMIT) {
1745 bLocLimitConstraint *data= con->data;
1747 if ((data->flag2 & LIMIT_TRANSFORM)==0)
1750 /* do space conversions */
1751 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1752 /* just multiply by td->mtx (this should be ok) */
1753 Mat4CpyMat4(tmat, cob.matrix);
1754 Mat4MulMat34(cob.matrix, td->mtx, tmat);
1756 else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) {
1757 /* skip... incompatable spacetype */
1762 cti->evaluate_constraint(con, &cob, NULL);
1764 /* convert spaces again */
1765 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1766 /* just multiply by td->mtx (this should be ok) */
1767 Mat4CpyMat4(tmat, cob.matrix);
1768 Mat4MulMat34(cob.matrix, td->smtx, tmat);
1773 /* copy results from cob->matrix */
1775 TransDataIpokey *tdi= td->tdi;
1776 tdi->locx[0]= cob.matrix[3][0];
1777 tdi->locy[0]= cob.matrix[3][1];
1778 tdi->locz[0]= cob.matrix[3][2];
1781 VECCOPY(td->loc, cob.matrix[3]);
1786 static void constraintRotLim(TransInfo *t, TransData *td)
1789 bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_ROTLIMIT);
1793 /* Make a temporary bConstraintOb for using these limit constraints
1794 * - they only care that cob->matrix is correctly set ;-)
1795 * - current space should be local
1797 memset(&cob, 0, sizeof(bConstraintOb));
1798 if (td->flag & TD_USEQUAT) {
1801 QuatToMat4(td->ext->quat, cob.matrix);
1806 /* ipo-keys eulers */
1807 TransDataIpokey *tdi= td->tdi;
1810 eul[0]= tdi->rotx[0];
1811 eul[1]= tdi->roty[0];
1812 eul[2]= tdi->rotz[0];
1814 EulToMat4(eul, cob.matrix);
1819 EulToMat4(td->ext->rot, cob.matrix);
1824 /* Evaluate valid constraints */
1825 for (con= td->con; con; con= con->next) {
1826 /* only consider constraint if enabled */
1827 if (con->flag & CONSTRAINT_DISABLE) continue;
1828 if (con->enforce == 0.0f) continue;
1830 /* we're only interested in Limit-Rotation constraints */
1831 if (con->type == CONSTRAINT_TYPE_ROTLIMIT) {
1832 bRotLimitConstraint *data= con->data;
1835 /* only use it if it's tagged for this purpose */
1836 if ((data->flag2 & LIMIT_TRANSFORM)==0)
1839 /* do space conversions */
1840 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1841 /* just multiply by td->mtx (this should be ok) */
1842 Mat4CpyMat4(tmat, cob.matrix);
1843 Mat4MulMat34(cob.matrix, td->mtx, tmat);
1845 else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) {
1846 /* skip... incompatable spacetype */
1851 cti->evaluate_constraint(con, &cob, NULL);
1853 /* convert spaces again */
1854 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1855 /* just multiply by td->mtx (this should be ok) */
1856 Mat4CpyMat4(tmat, cob.matrix);
1857 Mat4MulMat34(cob.matrix, td->smtx, tmat);
1862 /* copy results from cob->matrix */
1863 if (td->flag & TD_USEQUAT) {
1865 Mat4ToQuat(cob.matrix, td->ext->quat);
1868 /* ipo-keys eulers */
1869 TransDataIpokey *tdi= td->tdi;
1872 Mat4ToEul(cob.matrix, eul);
1874 tdi->rotx[0]= eul[0];
1875 tdi->roty[0]= eul[1];
1876 tdi->rotz[0]= eul[2];
1880 Mat4ToEul(cob.matrix, td->ext->rot);
1885 static void constraintSizeLim(TransInfo *t, TransData *td)
1887 if (td->con && td->ext) {
1888 bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_SIZELIMIT);
1892 /* Make a temporary bConstraintOb for using these limit constraints
1893 * - they only care that cob->matrix is correctly set ;-)
1894 * - current space should be local
1896 memset(&cob, 0, sizeof(bConstraintOb));
1898 TransDataIpokey *tdi= td->tdi;
1901 size[0]= tdi->sizex[0];
1902 size[1]= tdi->sizey[0];
1903 size[2]= tdi->sizez[0];
1904 SizeToMat4(size, cob.matrix);
1906 else if ((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)) {
1907 /* scale val and reset size */
1908 return; // TODO: fix this case
1911 /* Reset val if SINGLESIZE but using a constraint */
1912 if (td->flag & TD_SINGLESIZE)
1915 SizeToMat4(td->ext->size, cob.matrix);
1918 /* Evaluate valid constraints */
1919 for (con= td->con; con; con= con->next) {
1920 /* only consider constraint if enabled */
1921 if (con->flag & CONSTRAINT_DISABLE) continue;
1922 if (con->enforce == 0.0f) continue;
1924 /* we're only interested in Limit-Scale constraints */
1925 if (con->type == CONSTRAINT_TYPE_SIZELIMIT) {
1926 bSizeLimitConstraint *data= con->data;
1929 /* only use it if it's tagged for this purpose */
1930 if ((data->flag2 & LIMIT_TRANSFORM)==0)
1933 /* do space conversions */
1934 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1935 /* just multiply by td->mtx (this should be ok) */
1936 Mat4CpyMat4(tmat, cob.matrix);
1937 Mat4MulMat34(cob.matrix, td->mtx, tmat);
1939 else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) {
1940 /* skip... incompatable spacetype */
1945 cti->evaluate_constraint(con, &cob, NULL);
1947 /* convert spaces again */
1948 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
1949 /* just multiply by td->mtx (this should be ok) */
1950 Mat4CpyMat4(tmat, cob.matrix);
1951 Mat4MulMat34(cob.matrix, td->smtx, tmat);
1956 /* copy results from cob->matrix */
1958 TransDataIpokey *tdi= td->tdi;
1961 Mat4ToSize(cob.matrix, size);
1963 tdi->sizex[0]= size[0];
1964 tdi->sizey[0]= size[1];
1965 tdi->sizez[0]= size[2];
1967 else if ((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)) {
1968 /* scale val and reset size */
1969 return; // TODO: fix this case
1972 /* Reset val if SINGLESIZE but using a constraint */
1973 if (td->flag & TD_SINGLESIZE)
1976 Mat4ToSize(cob.matrix, td->ext->size);
1981 /* ************************** WARP *************************** */
1983 void initWarp(TransInfo *t)
1985 float max[3], min[3];
1989 t->transform = Warp;
1990 t->handleEvent = handleEventWarp;
1992 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_RATIO);
2000 t->flag |= T_NO_CONSTRAINT;
2002 /* we need min/max in view space */
2003 for(i = 0; i < t->total; i++) {
2005 VECCOPY(center, t->data[i].center);
2006 Mat3MulVecfl(t->data[i].mtx, center);
2007 Mat4MulVecfl(t->viewmat, center);
2008 VecSubf(center, center, t->viewmat[3]);
2010 MinMax3(min, max, center);
2012 VECCOPY(max, center);
2013 VECCOPY(min, center);
2017 t->center[0]= (min[0]+max[0])/2.0f;
2018 t->center[1]= (min[1]+max[1])/2.0f;
2019 t->center[2]= (min[2]+max[2])/2.0f;
2021 if (max[0] == min[0]) max[0] += 0.1; /* not optimal, but flipping is better than invalid garbage (i.e. division by zero!) */
2022 t->val= (max[0]-min[0])/2.0f; /* t->val is X dimension projected boundbox */
2025 int handleEventWarp(TransInfo *t, wmEvent *event)
2029 if (event->type == MIDDLEMOUSE && event->val)
2031 // Use customData pointer to signal warp direction
2032 if (t->customData == 0)
2033 t->customData = (void*)1;
2043 int Warp(TransInfo *t, short mval[2])
2045 TransData *td = t->data;
2046 float vec[3], circumfac, dist, phi0, co, si, *curs, cursor[3], gcursor[3];
2050 curs= give_cursor(t->scene, t->view);
2052 * gcursor is the one used for helpline.
2053 * It has to be in the same space as the drawing loop
2054 * (that means it needs to be in the object's space when in edit mode and
2055 * in global space in object mode)
2057 * cursor is used for calculations.
2058 * It needs to be in view space, but we need to take object's offset
2059 * into account if in Edit mode.
2061 VECCOPY(cursor, curs);
2062 VECCOPY(gcursor, cursor);
2063 if (t->flag & T_EDIT) {
2064 VecSubf(cursor, cursor, t->obedit->obmat[3]);
2065 VecSubf(gcursor, gcursor, t->obedit->obmat[3]);
2066 Mat3MulVecfl(t->data->smtx, gcursor);
2068 Mat4MulVecfl(t->viewmat, cursor);
2069 VecSubf(cursor, cursor, t->viewmat[3]);
2071 /* amount of degrees for warp */
2072 circumfac = 360.0f * t->values[0];
2074 if (t->customData) /* non-null value indicates reversed input */
2079 snapGrid(t, &circumfac);
2080 applyNumInput(&t->num, &circumfac);
2082 /* header print for NumInput */
2083 if (hasNumInput(&t->num)) {
2086 outputNumInput(&(t->num), c);
2088 sprintf(str, "Warp: %s", c);
2091 /* default header print */
2092 sprintf(str, "Warp: %.3f", circumfac);
2095 circumfac*= (float)(-M_PI/360.0);
2097 for(i = 0; i < t->total; i++, td++) {
2099 if (td->flag & TD_NOACTION)
2102 if (td->flag & TD_SKIP)
2105 /* translate point to center, rotate in such a way that outline==distance */
2106 VECCOPY(vec, td->iloc);
2107 Mat3MulVecfl(td->mtx, vec);
2108 Mat4MulVecfl(t->viewmat, vec);
2109 VecSubf(vec, vec, t->viewmat[3]);
2111 dist= vec[0]-cursor[0];
2113 /* t->val is X dimension projected boundbox */
2114 phi0= (circumfac*dist/t->val);
2116 vec[1]= (vec[1]-cursor[1]);
2118 co= (float)cos(phi0);
2119 si= (float)sin(phi0);
2120 loc[0]= -si*vec[1]+cursor[0];
2121 loc[1]= co*vec[1]+cursor[1];
2124 Mat4MulVecfl(t->viewinv, loc);
2125 VecSubf(loc, loc, t->viewinv[3]);
2126 Mat3MulVecfl(td->smtx, loc);
2128 VecSubf(loc, loc, td->iloc);
2129 VecMulf(loc, td->factor);
2130 VecAddf(td->loc, td->iloc, loc);
2135 ED_area_headerprint(t->sa, str);
2140 /* ************************** SHEAR *************************** */
2142 void initShear(TransInfo *t)
2144 t->mode = TFM_SHEAR;
2145 t->transform = Shear;
2146 t->handleEvent = handleEventShear;
2148 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_ABSOLUTE);
2154 t->snap[2] = t->snap[1] * 0.1f;
2156 t->flag |= T_NO_CONSTRAINT;
2159 int handleEventShear(TransInfo *t, wmEvent *event)
2163 if (event->type == MIDDLEMOUSE && event->val)
2165 // Use customData pointer to signal Shear direction
2166 if (t->customData == 0)
2168 initMouseInputMode(t, &t->mouse, INPUT_VERTICAL_ABSOLUTE);
2169 t->customData = (void*)1;
2173 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_ABSOLUTE);
2184 int Shear(TransInfo *t, short mval[2])
2186 TransData *td = t->data;
2188 float smat[3][3], tmat[3][3], totmat[3][3], persmat[3][3], persinv[3][3];
2193 Mat3CpyMat4(persmat, t->viewmat);
2194 Mat3Inv(persinv, persmat);
2196 value = 0.05f * t->values[0];
2198 snapGrid(t, &value);
2200 applyNumInput(&t->num, &value);
2202 /* header print for NumInput */
2203 if (hasNumInput(&t->num)) {
2206 outputNumInput(&(t->num), c);
2208 sprintf(str, "Shear: %s %s", c, t->proptext);
2211 /* default header print */
2212 sprintf(str, "Shear: %.3f %s", value, t->proptext);
2217 // Custom data signals shear direction
2218 if (t->customData == 0)
2223 Mat3MulMat3(tmat, smat, persmat);
2224 Mat3MulMat3(totmat, persinv, tmat);
2226 for(i = 0 ; i < t->total; i++, td++) {
2227 if (td->flag & TD_NOACTION)
2230 if (td->flag & TD_SKIP)
2235 Mat3MulMat3(mat3, totmat, td->mtx);
2236 Mat3MulMat3(tmat, td->smtx, mat3);
2239 Mat3CpyMat3(tmat, totmat);
2241 VecSubf(vec, td->center, t->center);
2243 Mat3MulVecfl(tmat, vec);
2245 VecAddf(vec, vec, t->center);
2246 VecSubf(vec, vec, td->center);
2248 VecMulf(vec, td->factor);
2250 VecAddf(td->loc, td->iloc, vec);
2255 ED_area_headerprint(t->sa, str);
2260 /* ************************** RESIZE *************************** */
2262 void initResize(TransInfo *t)
2264 t->mode = TFM_RESIZE;
2265 t->transform = Resize;
2267 initMouseInputMode(t, &t->mouse, INPUT_SPRING_FLIP);
2269 t->flag |= T_NULL_ONE;
2270 t->num.flag |= NUM_NULL_ONE;
2271 t->num.flag |= NUM_AFFECT_ALL;
2273 t->flag |= T_NO_ZERO;
2274 t->num.flag |= NUM_NO_ZERO;
2281 t->snap[2] = t->snap[1] * 0.1f;
2284 static void headerResize(TransInfo *t, float vec[3], char *str) {
2286 if (hasNumInput(&t->num)) {
2287 outputNumInput(&(t->num), tvec);
2290 sprintf(&tvec[0], "%.4f", vec[0]);
2291 sprintf(&tvec[20], "%.4f", vec[1]);
2292 sprintf(&tvec[40], "%.4f", vec[2]);
2295 if (t->con.mode & CON_APPLY) {
2296 switch(t->num.idx_max) {
2298 sprintf(str, "Scale: %s%s %s", &tvec[0], t->con.text, t->proptext);
2301 sprintf(str, "Scale: %s : %s%s %s", &tvec[0], &tvec[20], t->con.text, t->proptext);
2304 sprintf(str, "Scale: %s : %s : %s%s %s", &tvec[0], &tvec[20], &tvec[40], t->con.text, t->proptext);
2308 if (t->flag & T_2D_EDIT)
2309 sprintf(str, "Scale X: %s Y: %s%s %s", &tvec[0], &tvec[20], t->con.text, t->proptext);
2311 sprintf(str, "Scale X: %s Y: %s Z: %s%s %s", &tvec[0], &tvec[20], &tvec[40], t->con.text, t->proptext);
2315 #define SIGN(a) (a<-FLT_EPSILON?1:a>FLT_EPSILON?2:3)
2316 #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)
2318 /* smat is reference matrix, only scaled */
2319 static void TransMat3ToSize( float mat[][3], float smat[][3], float *size)
2323 VecCopyf(vec, mat[0]);
2324 size[0]= Normalize(vec);
2325 VecCopyf(vec, mat[1]);
2326 size[1]= Normalize(vec);
2327 VecCopyf(vec, mat[2]);
2328 size[2]= Normalize(vec);
2330 /* first tried with dotproduct... but the sign flip is crucial */
2331 if( VECSIGNFLIP(mat[0], smat[0]) ) size[0]= -size[0];
2332 if( VECSIGNFLIP(mat[1], smat[1]) ) size[1]= -size[1];
2333 if( VECSIGNFLIP(mat[2], smat[2]) ) size[2]= -size[2];
2337 static void ElementResize(TransInfo *t, TransData *td, float mat[3][3]) {
2338 float tmat[3][3], smat[3][3], center[3];
2341 if (t->flag & T_EDIT) {
2342 Mat3MulMat3(smat, mat, td->mtx);
2343 Mat3MulMat3(tmat, td->smtx, smat);
2346 Mat3CpyMat3(tmat, mat);
2349 if (t->con.applySize) {
2350 t->con.applySize(t, td, tmat);
2353 /* local constraint shouldn't alter center */
2354 if (t->around == V3D_LOCAL) {
2355 if (t->flag & T_OBJECT) {
2356 VECCOPY(center, td->center);
2358 else if (t->flag & T_EDIT) {
2360 if(t->around==V3D_LOCAL && (t->settings->selectmode & SCE_SELECT_FACE)) {
2361 VECCOPY(center, td->center);
2364 VECCOPY(center, t->center);
2368 VECCOPY(center, t->center);
2372 VECCOPY(center, t->center);
2378 if (t->flag & (T_OBJECT|T_TEXTURE|T_POSE)) {
2379 float obsizemat[3][3];
2380 // Reorient the size mat to fit the oriented object.
2381 Mat3MulMat3(obsizemat, tmat, td->axismtx);
2382 //printmatrix3("obsizemat", obsizemat);
2383 TransMat3ToSize(obsizemat, td->axismtx, fsize);
2384 //printvecf("fsize", fsize);
2387 Mat3ToSize(tmat, fsize);
2390 protectedSizeBits(td->protectflag, fsize);
2392 if ((t->flag & T_V3D_ALIGN)==0) { // align mode doesn't resize objects itself
2393 /* handle ipokeys? */
2395 TransDataIpokey *tdi= td->tdi;
2396 /* calculate delta size (equal for size and dsize) */
2398 vec[0]= (tdi->oldsize[0])*(fsize[0] -1.0f) * td->factor;
2399 vec[1]= (tdi->oldsize[1])*(fsize[1] -1.0f) * td->factor;
2400 vec[2]= (tdi->oldsize[2])*(fsize[2] -1.0f) * td->factor;
2402 add_tdi_poin(tdi->sizex, tdi->oldsize, vec[0]);
2403 add_tdi_poin(tdi->sizey, tdi->oldsize+1, vec[1]);
2404 add_tdi_poin(tdi->sizez, tdi->oldsize+2, vec[2]);
2407 else if((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)){
2408 /* scale val and reset size */
2409 *td->val = td->ival * fsize[0] * td->factor;
2411 td->ext->size[0] = td->ext->isize[0];
2412 td->ext->size[1] = td->ext->isize[1];
2413 td->ext->size[2] = td->ext->isize[2];
2416 /* Reset val if SINGLESIZE but using a constraint */
2417 if (td->flag & TD_SINGLESIZE)
2418 *td->val = td->ival;
2420 td->ext->size[0] = td->ext->isize[0] * (fsize[0]) * td->factor;
2421 td->ext->size[1] = td->ext->isize[1] * (fsize[1]) * td->factor;
2422 td->ext->size[2] = td->ext->isize[2] * (fsize[2]) * td->factor;
2426 constraintSizeLim(t, td);
2429 /* For individual element center, Editmode need to use iloc */
2430 if (t->flag & T_POINTS)
2431 VecSubf(vec, td->iloc, center);
2433 VecSubf(vec, td->center, center);
2435 Mat3MulVecfl(tmat, vec);
2437 VecAddf(vec, vec, center);
2438 if (t->flag & T_POINTS)
2439 VecSubf(vec, vec, td->iloc);
2441 VecSubf(vec, vec, td->center);
2443 VecMulf(vec, td->factor);
2445 if (t->flag & (T_OBJECT|T_POSE)) {
2446 Mat3MulVecfl(td->smtx, vec);
2449 protectedTransBits(td->protectflag, vec);
2452 TransDataIpokey *tdi= td->tdi;
2453 add_tdi_poin(tdi->locx, tdi->oldloc, vec[0]);
2454 add_tdi_poin(tdi->locy, tdi->oldloc+1, vec[1]);
2455 add_tdi_poin(tdi->locz, tdi->oldloc+2, vec[2]);
2457 else VecAddf(td->loc, td->iloc, vec);
2459 constraintTransLim(t, td);
2462 int Resize(TransInfo *t, short mval[2])
2465 float size[3], mat[3][3];
2470 /* for manipulator, center handle, the scaling can't be done relative to center */
2471 if( (t->flag & T_USES_MANIPULATOR) && t->con.mode==0)
2473 ratio = 1.0f - ((t->imval[0] - mval[0]) + (t->imval[1] - mval[1]))/100.0f;
2477 ratio = t->values[0];
2480 size[0] = size[1] = size[2] = ratio;
2484 if (hasNumInput(&t->num)) {
2485 applyNumInput(&t->num, size);
2486 constraintNumInput(t, size);
2489 applySnapping(t, size);
2491 if (t->flag & T_AUTOVALUES)
2493 VECCOPY(size, t->auto_values);
2496 VECCOPY(t->values, size);
2498 SizeToMat3(size, mat);
2500 if (t->con.applySize) {
2501 t->con.applySize(t, NULL, mat);
2504 Mat3CpyMat3(t->mat, mat); // used in manipulator
2506 headerResize(t, size, str);
2508 for(i = 0, td=t->data; i < t->total; i++, td++) {
2509 if (td->flag & TD_NOACTION)
2512 if (td->flag & TD_SKIP)
2515 ElementResize(t, td, mat);
2518 /* evil hack - redo resize if cliping needed */
2519 if (t->flag & T_CLIP_UV && clipUVTransform(t, size, 1)) {
2520 SizeToMat3(size, mat);
2522 if (t->con.applySize)
2523 t->con.applySize(t, NULL, mat);
2525 for(i = 0, td=t->data; i < t->total; i++, td++)
2526 ElementResize(t, td, mat);
2531 ED_area_headerprint(t->sa, str);
2536 /* ************************** TOSPHERE *************************** */
2538 void initToSphere(TransInfo *t)
2540 TransData *td = t->data;
2543 t->mode = TFM_TOSPHERE;
2544 t->transform = ToSphere;
2546 initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_RATIO);
2552 t->snap[2] = t->snap[1] * 0.1f;
2554 t->num.flag |= NUM_NULL_ONE | NUM_NO_NEGATIVE;
2555 t->flag |= T_NO_CONSTRAINT;
2557 // Calculate average radius
2558 for(i = 0 ; i < t->total; i++, td++) {
2559 t->val += VecLenf(t->center, td->iloc);
2562 t->val /= (float)t->total;
2565 int ToSphere(TransInfo *t, short mval[2])
2568 float ratio, radius;
2571 TransData *td = t->data;
2573 ratio = t->values[0];
2575 snapGrid(t, &ratio);
2577 applyNumInput(&t->num, &ratio);
2584 /* header print for NumInput */
2585 if (hasNumInput(&t->num)) {
2588 outputNumInput(&(t->num), c);
2590 sprintf(str, "To Sphere: %s %s", c, t->proptext);
2593 /* default header print */
2594 sprintf(str, "To Sphere: %.4f %s", ratio, t->proptext);
2598 for(i = 0 ; i < t->total; i++, td++) {
2600 if (td->flag & TD_NOACTION)
2603 if (td->flag & TD_SKIP)
2606 VecSubf(vec, td->iloc, t->center);
2608 radius = Normalize(vec);
2610 tratio = ratio * td->factor;
2612 VecMulf(vec, radius * (1.0f - tratio) + t->val * tratio);
2614 VecAddf(td->loc, t->center, vec);
2620 ED_area_headerprint(t->sa, str);
2625 /* ************************** ROTATION *************************** */
2628 void initRotation(TransInfo *t)
2630 t->mode = TFM_ROTATION;
2631 t->transform = Rotation;
2633 initMouseInputMode(t, &t->mouse, INPUT_ANGLE);
2636 /* Scale down and flip input for rotation */
2637 t->ndof.factor[0] = -0.2f;
2642 t->snap[1] = (float)((5.0/180)*M_PI);
2643 t->snap[2] = t->snap[1] * 0.2f;
2645 if (t->flag & T_2D_EDIT)
2646 t->flag |= T_NO_CONSTRAINT;
2649 static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short around) {
2650 float vec[3], totmat[3][3], smat[3][3];
2651 float eul[3], fmat[3][3], quat[4];
2652 float *center = t->center;
2654 /* local constraint shouldn't alter center */
2655 if (around == V3D_LOCAL) {
2656 if (t->flag & (T_OBJECT|T_POSE)) {
2657 center = td->center;
2660 /* !TODO! Make this if not rely on G */
2661 if(around==V3D_LOCAL && (t->settings->selectmode & SCE_SELECT_FACE)) {
2662 center = td->center;
2667 if (t->flag & T_POINTS) {
2668 Mat3MulMat3(totmat, mat, td->mtx);
2669 Mat3MulMat3(smat, td->smtx, totmat);
2671 VecSubf(vec, td->iloc, center);
2672 Mat3MulVecfl(smat, vec);
2674 VecAddf(td->loc, vec, center);
2676 VecSubf(vec,td->loc,td->iloc);
2677 protectedTransBits(td->protectflag, vec);
2678 VecAddf(td->loc, td->iloc, vec);
2680 if(td->flag & TD_USEQUAT) {
2681 Mat3MulSerie(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0);
2682 Mat3ToQuat(fmat, quat); // Actual transform
2685 QuatMul(td->ext->quat, quat, td->ext->iquat);
2687 /* is there a reason not to have this here? -jahka */
2688 protectedQuaternionBits(td->protectflag, td->ext->quat, td->ext->iquat);
2695 * This is some VERY ugly special case to deal with pose mode.
2697 * The problem is that mtx and smtx include each bone orientation.
2699 * That is needed to rotate each bone properly, HOWEVER, to calculate
2700 * the translation component, we only need the actual armature object's
2701 * matrix (and inverse). That is not all though. Once the proper translation
2702 * has been computed, it has to be converted back into the bone's space.
2704 else if (t->flag & T_POSE) {
2705 float pmtx[3][3], imtx[3][3];
2707 // Extract and invert armature object matrix
2708 Mat3CpyMat4(pmtx, t->poseobj->obmat);
2709 Mat3Inv(imtx, pmtx);
2711 if ((td->flag & TD_NO_LOC) == 0)
2713 VecSubf(vec, td->center, center);
2715 Mat3MulVecfl(pmtx, vec); // To Global space
2716 Mat3MulVecfl(mat, vec); // Applying rotation
2717 Mat3MulVecfl(imtx, vec); // To Local space
2719 VecAddf(vec, vec, center);
2720 /* vec now is the location where the object has to be */
2722 VecSubf(vec, vec, td->center); // Translation needed from the initial location
2724 Mat3MulVecfl(pmtx, vec); // To Global space
2725 Mat3MulVecfl(td->smtx, vec);// To Pose space
2727 protectedTransBits(td->protectflag, vec);
2729 VecAddf(td->loc, td->iloc, vec);
2731 constraintTransLim(t, td);
2735 if ((t->flag & T_V3D_ALIGN)==0) { // align mode doesn't rotate objects itself
2736 /* euler or quaternion? */
2737 if (td->flag & TD_USEQUAT) {
2738 Mat3MulSerie(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0);
2740 Mat3ToQuat(fmat, quat); // Actual transform
2742 QuatMul(td->ext->quat, quat, td->ext->iquat);
2743 /* this function works on end result */
2744 protectedQuaternionBits(td->protectflag, td->ext->quat, td->ext->iquat);
2749 Mat3MulMat3(totmat, mat, td->mtx);
2750 Mat3MulMat3(smat, td->smtx, totmat);
2752 /* calculate the total rotatation in eulers */
2753 VECCOPY(eul, td->ext->irot);
2754 EulToMat3(eul, eulmat);
2756 /* mat = transform, obmat = bone rotation */
2757 Mat3MulMat3(fmat, smat, eulmat);
2759 Mat3ToCompatibleEul(fmat, eul, td->ext->rot);
2761 /* and apply (to end result only) */
2762 protectedRotateBits(td->protectflag, eul, td->ext->irot);
2763 VECCOPY(td->ext->rot, eul);
2766 constraintRotLim(t, td);
2770 if ((td->flag & TD_NO_LOC) == 0)
2773 VecSubf(vec, td->center, center);
2774 Mat3MulVecfl(mat, vec);
2775 VecAddf(vec, vec, center);
2776 /* vec now is the location where the object has to be */
2777 VecSubf(vec, vec, td->center);
2778 Mat3MulVecfl(td->smtx, vec);
2780 protectedTransBits(td->protectflag, vec);
2783 TransDataIpokey *tdi= td->tdi;
2784 add_tdi_poin(tdi->locx, tdi->oldloc, vec[0]);
2785 add_tdi_poin(tdi->locy, tdi->oldloc+1, vec[1]);
2786 add_tdi_poin(tdi->locz, tdi->oldloc+2, vec[2]);
2788 else VecAddf(td->loc, td->iloc, vec);
2792 constraintTransLim(t, td);
2795 if ((t->flag & T_V3D_ALIGN)==0) { // align mode doesn't rotate objects itself
2796 /* euler or quaternion? */
2797 if (td->flag & TD_USEQUAT) {
2798 Mat3MulSerie(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0);
2799 Mat3ToQuat(fmat, quat); // Actual transform
2801 QuatMul(td->ext->quat, quat, td->ext->iquat);
2802 /* this function works on end result */
2803 protectedQuaternionBits(td->protectflag, td->ext->quat, td->ext->iquat);
2808 /* are there ipo keys? */
2810 TransDataIpokey *tdi= td->tdi;
2811 float current_rot[3];
2814 /* current IPO value for compatible euler */
2815 current_rot[0] = (tdi->rotx) ? tdi->rotx[0] : 0.0f;
2816 current_rot[1] = (tdi->roty) ? tdi->roty[0] : 0.0f;
2817 current_rot[2] = (tdi->rotz) ? tdi->rotz[0] : 0.0f;
2818 VecMulf(current_rot, (float)(M_PI_2 / 9.0));
2820 /* calculate the total rotatation in eulers */
2821 VecAddf(eul, td->ext->irot, td->ext->drot);
2822 EulToMat3(eul, obmat);
2823 /* mat = transform, obmat = object rotation */
2824 Mat3MulMat3(fmat, mat, obmat);
2826 Mat3ToCompatibleEul(fmat, eul, current_rot);
2828 /* correct back for delta rot */
2829 if(tdi->flag & TOB_IPODROT) {
2830 VecSubf(rot, eul, td->ext->irot);
2833 VecSubf(rot, eul, td->ext->drot);
2836 VecMulf(rot, (float)(9.0/M_PI_2));
2837 VecSubf(rot, rot, tdi->oldrot);
2839 protectedRotateBits(td->protectflag, rot, tdi->oldrot);
2841 add_tdi_poin(tdi->rotx, tdi->oldrot, rot[0]);
2842 add_tdi_poin(tdi->roty, tdi->oldrot+1, rot[1]);
2843 add_tdi_poin(tdi->rotz, tdi->oldrot+2, rot[2]);
2846 Mat3MulMat3(totmat, mat, td->mtx);
2847 Mat3MulMat3(smat, td->smtx, totmat);
2849 /* calculate the total rotatation in eulers */
2850 VecAddf(eul, td->ext->irot, td->ext->drot); /* we have to correct for delta rot */
2851 EulToMat3(eul, obmat);
2852 /* mat = transform, obmat = object rotation */
2853 Mat3MulMat3(fmat, smat, obmat);
2855 Mat3ToCompatibleEul(fmat, eul, td->ext->rot);
2857 /* correct back for delta rot */
2858 VecSubf(eul, eul, td->ext->drot);
2861 protectedRotateBits(td->protectflag, eul, td->ext->irot);
2862 VECCOPY(td->ext->rot, eul);
2866 constraintRotLim(t, td);
2871 static void applyRotation(TransInfo *t, float angle, float axis[3])
2873 TransData *td = t->data;
2877 VecRotToMat3(axis, angle, mat);
2879 for(i = 0 ; i < t->total; i++, td++) {
2881 if (td->flag & TD_NOACTION)
2884 if (td->flag & TD_SKIP)
2887 if (t->con.applyRot) {
2888 t->con.applyRot(t, td, axis, NULL);
2889 VecRotToMat3(axis, angle * td->factor, mat);
2891 else if (t->flag & T_PROP_EDIT) {
2892 VecRotToMat3(axis, angle * td->factor, mat);
2895 ElementRotation(t, td, mat, t->around);
2899 int Rotation(TransInfo *t, short mval[2])
2908 VECCOPY(axis, t->viewinv[2]);
2909 VecMulf(axis, -1.0f);
2912 final = t->values[0];
2914 applyNDofInput(&t->ndof, &final);
2916 snapGrid(t, &final);
2918 if (t->con.applyRot) {
2919 t->con.applyRot(t, NULL, axis, &final);
2922 applySnapping(t, &final);
2924 if (hasNumInput(&t->num)) {
2927 applyNumInput(&t->num, &final);
2929 outputNumInput(&(t->num), c);
2931 sprintf(str, "Rot: %s %s %s", &c[0], t->con.text, t->proptext);
2933 /* Clamp between -180 and 180 */
2934 while (final >= 180.0)
2937 while (final <= -180.0)
2940 final *= (float)(M_PI / 180.0);
2943 sprintf(str, "Rot: %.2f%s %s", 180.0*final/M_PI, t->con.text, t->proptext);
2946 VecRotToMat3(axis, final, mat);
2949 // t->values[0] = final; // used in manipulator
2950 // Mat3CpyMat3(t->mat, mat); // used in manipulator
2952 applyRotation(t, final, axis);
2956 ED_area_headerprint(t->sa, str);
2962 /* ************************** TRACKBALL *************************** */
2964 void initTrackball(TransInfo *t)
2966 t->mode = TFM_TRACKBALL;
2967 t->transform = Trackball;
2969 initMouseInputMode(t, &t->mouse, INPUT_TRACKBALL);
2972 /* Scale down input for rotation */
2973 t->ndof.factor[0] = 0.2f;
2974 t->ndof.factor[1] = 0.2f;