Bretch's patch for 2D transform. Thanks
[blender.git] / source / blender / src / transform_generics.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5  *
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. The Blender
10  * Foundation also sells licenses for use in proprietary software under
11  * the Blender License.  See http://www.blender.org/BL/ for information
12  * about this.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  *
23  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24  * All rights reserved.
25  *
26  * The Original Code is: all of this file.
27  *
28  * Contributor(s): none yet.
29  *
30  * ***** END GPL/BL DUAL LICENSE BLOCK *****
31  */
32
33 #include <string.h>
34 #include <math.h>
35
36 #include "MEM_guardedalloc.h"
37
38 #include "DNA_action_types.h"
39 #include "DNA_armature_types.h"
40 #include "DNA_curve_types.h"
41 #include "DNA_lattice_types.h"
42 #include "DNA_scene_types.h"
43 #include "DNA_view3d_types.h"
44 #include "DNA_userdef_types.h"
45 #include "DNA_constraint_types.h"
46 #include "DNA_screen_types.h"
47 #include "DNA_space_types.h"
48 #include "DNA_mesh_types.h"
49
50 #include "BIF_screen.h"
51 #include "BIF_resources.h"
52 #include "BIF_mywindow.h"
53 #include "BIF_gl.h"
54 #include "BIF_editarmature.h"
55 #include "BIF_editmesh.h"
56 #include "BIF_editsima.h"
57
58 #include "BKE_action.h"
59 #include "BKE_anim.h"
60 #include "BKE_armature.h"
61 #include "BKE_curve.h"
62 #include "BKE_depsgraph.h"
63 #include "BKE_displist.h"
64 #include "BKE_depsgraph.h"
65 #include "BKE_global.h"
66 #include "BKE_ipo.h"
67 #include "BKE_lattice.h"
68 #include "BKE_mesh.h"
69 #include "BKE_object.h"
70 #include "BKE_utildefines.h"
71
72 #include "BSE_view.h"
73
74 #include "BLI_arithb.h"
75 #include "BLI_blenlib.h"
76
77 #include "blendef.h"
78
79 #include "mydevice.h"
80
81 #include "transform.h"
82
83 extern ListBase editNurb;
84 extern ListBase editelems;
85
86 extern TransInfo Trans; /* From transform.c */
87
88 /* ************************** Functions *************************** */
89
90
91 void getViewVector(float coord[3], float vec[3])
92 {
93         TransInfo *t = BIF_GetTransInfo();
94
95         if (t->persp)
96         {
97                 float p1[4], p2[4];
98
99                 VECCOPY(p1, coord);
100                 p1[3] = 1.0f;
101                 VECCOPY(p2, p1);
102                 p2[3] = 1.0f;
103                 Mat4MulVec4fl(t->viewmat, p2);
104
105                 p2[0] = 2.0f * p2[0];
106                 p2[1] = 2.0f * p2[1];
107                 p2[2] = 2.0f * p2[2];
108
109                 Mat4MulVec4fl(t->viewinv, p2);
110
111                 VecSubf(vec, p1, p2);
112         }
113         else {
114                 VECCOPY(vec, t->viewinv[2]);
115         }
116         Normalise(vec);
117 }
118
119 /* ************************** GENERICS **************************** */
120
121 /* if editbone (partial) selected, copy data */
122 /* context; editmode armature, with mirror editing enabled */
123 static void transform_armature_mirror_update(void)
124 {
125         EditBone *ebo, *eboflip;
126         
127         for (ebo=G.edbo.first; ebo; ebo=ebo->next) {
128                 if(ebo->flag & (BONE_TIPSEL|BONE_ROOTSEL)) {
129                         
130                         eboflip= armature_bone_get_mirrored(ebo);
131                         
132                         if(eboflip) {
133                                 /* we assume X-axis flipping for now */
134                                 if(ebo->flag & BONE_TIPSEL) {
135                                         eboflip->tail[0]= -ebo->tail[0];
136                                         eboflip->tail[1]= ebo->tail[1];
137                                         eboflip->tail[2]= ebo->tail[2];
138                                         eboflip->rad_tail= ebo->rad_tail;
139                                 }
140                                 if(ebo->flag & BONE_ROOTSEL) {
141                                         eboflip->head[0]= -ebo->head[0];
142                                         eboflip->head[1]= ebo->head[1];
143                                         eboflip->head[2]= ebo->head[2];
144                                         eboflip->rad_head= ebo->rad_head;
145                                 }
146                                 if(ebo->flag & BONE_SELECTED)
147                                         eboflip->dist= ebo->dist;
148                         }
149                 }
150         }
151 }
152
153
154 /* called for objects updating while transform acts, once per redraw */
155 void recalcData(TransInfo *t)
156 {
157         
158         if (G.obedit) {
159                 if (G.obedit->type == OB_MESH) {
160                         DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);  /* sets recalc flags */
161                         
162                         recalc_editnormals();
163                 }
164                 else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) {
165                         Nurb *nu= editNurb.first;
166                         DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);  /* sets recalc flags */
167                         
168                         while(nu) {
169                                 test2DNurb(nu);
170                                 testhandlesNurb(nu); /* test for bezier too */
171                                 nu= nu->next;
172                         }
173                 }
174                 else if(G.obedit->type==OB_ARMATURE){   /* no recalc flag, does pose */
175                         bArmature *arm= G.obedit->data;
176                         EditBone *ebo;
177                         
178                         /* Ensure all bones are correctly adjusted */
179                         for (ebo=G.edbo.first; ebo; ebo=ebo->next){
180                                 
181                                 if ((ebo->flag & BONE_IK_TOPARENT) && ebo->parent){
182                                         /* If this bone has a parent tip that has been moved */
183                                         if (ebo->parent->flag & BONE_TIPSEL){
184                                                 VECCOPY (ebo->head, ebo->parent->tail);
185                                                 if(t->mode==TFM_BONE_ENVELOPE) ebo->rad_head= ebo->parent->rad_tail;
186                                         }
187                                         /* If this bone has a parent tip that has NOT been moved */
188                                         else{
189                                                 VECCOPY (ebo->parent->tail, ebo->head);
190                                                 if(t->mode==TFM_BONE_ENVELOPE) ebo->parent->rad_tail= ebo->rad_head;
191                                         }
192                                 }
193                                 
194                                 /* on extrude bones, oldlength==0.0f, so we scale radius of points */
195                                 if(ebo->oldlength==0.0f) {
196                                         ebo->rad_head= 0.25f*ebo->length;
197                                         ebo->rad_tail= 0.10f*ebo->length;
198                                         ebo->dist= 0.25f*ebo->length;
199                                         if(ebo->parent) {
200                                                 if(ebo->rad_head > ebo->parent->rad_tail)
201                                                         ebo->rad_head= ebo->parent->rad_tail;
202                                         }
203                                 }
204                                 else if(t->mode!=TFM_BONE_ENVELOPE) {
205                                         /* if bones change length, lets do that for the deform distance as well */
206                                         ebo->dist*= ebo->length/ebo->oldlength;
207                                         ebo->rad_head*= ebo->length/ebo->oldlength;
208                                         ebo->rad_tail*= ebo->length/ebo->oldlength;
209                                         ebo->oldlength= ebo->length;
210                                 }
211                         }
212                         if(arm->flag & ARM_MIRROR_EDIT) 
213                                 transform_armature_mirror_update();
214                         
215                 }
216                 else if(G.obedit->type==OB_LATTICE) {
217                         DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);  /* sets recalc flags */
218                         
219                         if(editLatt->flag & LT_OUTSIDE) outside_lattice(editLatt);
220                 }
221                 else {
222                         DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);  /* sets recalc flags */
223                 }
224         }
225         else if( (t->flag & T_POSE) && t->poseobj) {
226                 Object *ob= t->poseobj;
227                 bArmature *arm= ob->data;
228                 
229                 /* old optimize trick... this enforces to bypass the depgraph */
230                 if (!(arm->flag & ARM_DELAYDEFORM)) 
231                         DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);  /* sets recalc flags */
232                 else
233                         where_is_pose(ob);
234         }
235         else if(t->spacetype==SPACE_IMAGE) {
236                 flushTransUVs(t);
237         }
238         else {
239                 Base *base;
240                 
241                 base= FIRSTBASE;
242                 while(base) {
243                         /* this flag is from depgraph, was stored in nitialize phase, handled in drawview.c */
244                         if(base->flag & BA_HAS_RECALC_OB)
245                                 base->object->recalc |= OB_RECALC_OB;
246                         if(base->flag & BA_HAS_RECALC_DATA)
247                                 base->object->recalc |= OB_RECALC_DATA;
248                         
249                         /* thanks to ob->ctime usage, ipos are not called in where_is_object,
250                            unless we edit ipokeys */
251                         if(base->flag & BA_DO_IPO) {
252                                 if(base->object->ipo) {
253                                         IpoCurve *icu;
254                                         
255                                         base->object->ctime= -1234567.0;
256                                         
257                                         icu= base->object->ipo->curve.first;
258                                         while(icu) {
259                                                 calchandles_ipocurve(icu);
260                                                 icu= icu->next;
261                                         }
262                                 }                               
263                         }
264                         
265                         base= base->next;
266                 } 
267         }
268         
269         /* update shaded drawmode while transform */
270         if(t->spacetype==SPACE_VIEW3D && G.vd->drawtype == OB_SHADED)
271                 reshadeall_displist();
272         
273 }
274
275 void initTransModeFlags(TransInfo *t, int mode) 
276 {
277         t->mode = mode;
278         t->num.flag = 0;
279
280         /* REMOVING RESTRICTIONS FLAGS */
281         t->flag &= ~T_ALL_RESTRICTIONS;
282         
283         switch (mode) {
284         case TFM_RESIZE:
285                 t->flag |= T_NULL_ONE;
286                 t->num.flag |= NUM_NULL_ONE;
287                 t->num.flag |= NUM_AFFECT_ALL;
288                 if (!G.obedit) {
289                         t->flag |= T_NO_ZERO;
290                         t->num.flag |= NUM_NO_ZERO;
291                 }
292                 break;
293         case TFM_TOSPHERE:
294                 t->num.flag |= NUM_NULL_ONE;
295                 t->num.flag |= NUM_NO_NEGATIVE;
296                 t->flag |= T_NO_CONSTRAINT;
297                 break;
298         case TFM_SHEAR:
299         case TFM_CREASE:
300         case TFM_BONE_ENVELOPE:
301                 t->flag |= T_NO_CONSTRAINT;
302                 break;
303         }
304 }
305
306 void drawLine(float *center, float *dir, char axis, short options)
307 {
308         extern void make_axis_color(char *col, char *col2, char axis);  // drawview.c
309         float v1[3], v2[3], v3[3];
310         char col[3], col2[3];
311         
312         //if(G.obedit) mymultmatrix(G.obedit->obmat);   // sets opengl viewing
313
314         VecCopyf(v3, dir);
315         VecMulf(v3, G.vd->far);
316         
317         VecSubf(v2, center, v3);
318         VecAddf(v1, center, v3);
319
320         if (options & DRAWLIGHT) {
321                 col[0] = col[1] = col[2] = 220;
322         }
323         else {
324                 BIF_GetThemeColor3ubv(TH_GRID, col);
325         }
326         make_axis_color(col, col2, axis);
327         glColor3ubv(col2);
328
329         setlinestyle(0);
330         glBegin(GL_LINE_STRIP); 
331                 glVertex3fv(v1); 
332                 glVertex3fv(v2); 
333         glEnd();
334         
335         myloadmatrix(G.vd->viewmat);
336 }
337
338 void initTrans (TransInfo *t)
339 {
340         
341         /* moving: is shown in drawobject() (transform color) */
342         if(G.obedit || (t->flag & T_POSE) ) G.moving= G_TRANSFORM_EDIT;
343         else G.moving= G_TRANSFORM_OBJ;
344
345         t->data = NULL;
346         t->ext = NULL;
347
348         t->flag = 0;
349
350         /* setting PET flag */
351         if ((t->context & CTX_NO_PET) == 0 && (G.scene->proportional)) {
352                 t->flag |= T_PROP_EDIT;
353                 if(G.scene->proportional==2) t->flag |= T_PROP_CONNECTED;       // yes i know, has to become define
354         }
355
356         getmouseco_areawin(t->imval);
357         t->con.imval[0] = t->imval[0];
358         t->con.imval[1] = t->imval[1];
359
360         t->transform            = NULL;
361
362         t->total                        =
363                 t->num.idx              =
364                 t->num.idx_max  =
365                 t->num.ctrl[0]  = 
366                 t->num.ctrl[1]  = 
367                 t->num.ctrl[2]  = 0;
368
369         t->val = 0.0f;
370
371         t->num.val[0]           = 
372                 t->num.val[1]   = 
373                 t->num.val[2]   = 0.0f;
374
375         t->vec[0]                       =
376                 t->vec[1]               =
377                 t->vec[2]               = 0.0f;
378         
379         Mat3One(t->mat);
380         
381         t->spacetype = curarea->spacetype;
382         if(t->spacetype==SPACE_VIEW3D) {
383                 if(G.vd->flag & V3D_ALIGN) t->flag |= T_V3D_ALIGN;
384                 t->around = G.vd->around;
385         }
386         else
387                 t->around = V3D_CENTRE;
388
389         setTransformViewMatrices(t);
390 }
391
392 /* Here I would suggest only TransInfo related issues, like free data & reset vars. Not redraws */
393 void postTrans (TransInfo *t) 
394 {
395         G.moving = 0; // Set moving flag off (display as usual)
396
397         stopConstraint(t);
398         
399         /* postTrans can be called when nothing is selected, so data is NULL already */
400         if (t->data) {
401                 TransData *td;
402                 int a;
403
404                 /* since ipokeys are optional on objects, we mallocced them per trans-data */
405                 for(a=0, td= t->data; a<t->total; a++, td++) {
406                         if(td->tdi) MEM_freeN(td->tdi);
407                 }
408                 MEM_freeN(t->data);
409         }
410
411         if (t->ext) MEM_freeN(t->ext);
412         if (t->data2d) {
413                 MEM_freeN(t->data2d);
414                 t->data2d= NULL;
415         }
416 }
417
418 static void apply_grid3(TransInfo *t, float *val, int max_index, float fac1, float fac2, float fac3)
419 {
420         /* fac1 is for 'nothing', fac2 for CTRL, fac3 for SHIFT */
421         int invert = U.flag & USER_AUTOGRABGRID;
422         int ctrl;
423         int i;
424         float asp= 1.0f;
425
426         for (i=0; i<=max_index; i++) {
427
428                 /* evil hack - snapping needs to be adapted for image aspect ratio */
429                 if(t->spacetype==SPACE_IMAGE) {
430                         float aspx, aspy;
431                         transform_aspect_ratio_tface_uv(&aspx, &aspy);
432                         if(i==0) asp= aspx;
433                         else asp= aspy;
434                 }
435
436                 if(invert) {
437                         if(G.qual & LR_CTRLKEY) ctrl= 0;
438                         else ctrl= 1;
439                 }
440                 else ctrl= (G.qual & LR_CTRLKEY);
441
442                 if(ctrl && (G.qual & LR_SHIFTKEY)) {
443                         if(fac3!= 0.0) {
444                                 for (i=0; i<=max_index; i++) {
445                                         val[i]= fac3*asp*(float)floor(val[i]/(fac3*asp) +.5);
446                                 }
447                         }
448                 }
449                 else if(ctrl) {
450                         if(fac2!= 0.0) {
451                                 for (i=0; i<=max_index; i++) {
452                                         val[i]= fac2*asp*(float)floor(val[i]/(fac2*asp) +.5);
453                                 }
454                         }
455                 }
456                 else {
457                         if(fac1!= 0.0) {
458                                 for (i=0; i<=max_index; i++) {
459                                         val[i]= fac1*asp*(float)floor(val[i]/(fac1*asp) +.5);
460                                 }
461                         }
462                 }
463         }
464 }
465
466 void snapGrid(TransInfo *t, float *val) {
467         apply_grid3(t, val, t->idx_max, t->snap[0], t->snap[1], t->snap[2]);
468 }
469
470 void applyTransObjects(TransInfo *t)
471 {
472         TransData *td;
473         
474         for (td = t->data; td < t->data + t->total; td++) {
475                 VECCOPY(td->iloc, td->loc);
476                 if (td->ext->rot) {
477                         VECCOPY(td->ext->irot, td->ext->rot);
478                 }
479                 if (td->ext->size) {
480                         VECCOPY(td->ext->isize, td->ext->size);
481                 }
482         }       
483         recalcData(t);
484
485
486 /* helper for below */
487 static void restore_ipokey(float *poin, float *old)
488 {
489         if(poin) {
490                 poin[0]= old[0];
491                 poin[-3]= old[3];
492                 poin[3]= old[6];
493         }
494 }
495
496 static void restoreElement(TransData *td) {
497         /* TransData for crease has no loc */
498         if (td->loc) {
499                 VECCOPY(td->loc, td->iloc);
500         }
501         if (td->val) {
502                 *td->val = td->ival;
503         }
504         if (td->ext) {
505                 if (td->ext->rot) {
506                         VECCOPY(td->ext->rot, td->ext->irot);
507                 }
508                 if (td->ext->size) {
509                         VECCOPY(td->ext->size, td->ext->isize);
510                 }
511                 if(td->flag & TD_USEQUAT) {
512                         if (td->ext->quat) {
513                                 QUATCOPY(td->ext->quat, td->ext->iquat);
514                         }
515                 }
516         }
517         if(td->tdi) {
518                 TransDataIpokey *tdi= td->tdi;
519                 
520                 restore_ipokey(tdi->locx, tdi->oldloc);
521                 restore_ipokey(tdi->locy, tdi->oldloc+1);
522                 restore_ipokey(tdi->locz, tdi->oldloc+2);
523
524                 restore_ipokey(tdi->rotx, tdi->oldrot);
525                 restore_ipokey(tdi->roty, tdi->oldrot+1);
526                 restore_ipokey(tdi->rotz, tdi->oldrot+2);
527                 
528                 restore_ipokey(tdi->sizex, tdi->oldsize);
529                 restore_ipokey(tdi->sizey, tdi->oldsize+1);
530                 restore_ipokey(tdi->sizez, tdi->oldsize+2);
531         }
532 }
533
534 void restoreTransObjects(TransInfo *t)
535 {
536         TransData *td;
537         
538         for (td = t->data; td < t->data + t->total; td++) {
539                 restoreElement(td);
540         }       
541         recalcData(t);
542
543
544 void calculateCenterCursor(TransInfo *t)
545 {
546         float *cursor;
547
548         cursor = give_cursor();
549         VECCOPY(t->center, cursor);
550
551         if(t->flag & (T_EDIT|T_POSE)) {
552                 Object *ob= G.obedit?G.obedit:t->poseobj;
553                 float mat[3][3], imat[3][3];
554                 float vec[3];
555                 
556                 VecSubf(t->center, t->center, ob->obmat[3]);
557                 Mat3CpyMat4(mat, ob->obmat);
558                 Mat3Inv(imat, mat);
559                 Mat3MulVecfl(imat, t->center);
560                 
561                 VECCOPY(vec, t->center);
562                 Mat4MulVecfl(ob->obmat, vec);
563                 projectIntView(t, vec, t->center2d);
564         }
565         else {
566                 projectIntView(t, t->center, t->center2d);
567         }
568 }
569
570 void calculateCenterMedian(TransInfo *t)
571 {
572         float partial[3] = {0.0f, 0.0f, 0.0f};
573         int i;
574         for(i = 0; i < t->total; i++) {
575                 if (t->data[i].flag & TD_SELECTED) {
576                         VecAddf(partial, partial, t->data[i].center);
577                 }
578                 else {
579                         /* 
580                            All the selected elements are at the head of the array 
581                            which means we can stop when it finds unselected data
582                         */
583                         break;
584                 }
585         }
586         VecMulf(partial, 1.0f / i);
587         VECCOPY(t->center, partial);
588
589         if (t->flag & (T_EDIT|T_POSE)) {
590                 Object *ob= G.obedit?G.obedit:t->poseobj;
591                 float vec[3];
592                 
593                 VECCOPY(vec, t->center);
594                 Mat4MulVecfl(ob->obmat, vec);
595                 projectIntView(t, vec, t->center2d);
596         }
597         else {
598                 projectIntView(t, t->center, t->center2d);
599         }
600 }
601
602 void calculateCenterBound(TransInfo *t)
603 {
604         float max[3];
605         float min[3];
606         int i;
607         for(i = 0; i < t->total; i++) {
608                 if (i) {
609                         if (t->data[i].flag & TD_SELECTED) {
610                                 MinMax3(min, max, t->data[i].center);
611                         }
612                         else {
613                                 /* 
614                                    All the selected elements are at the head of the array 
615                                    which means we can stop when it finds unselected data
616                                 */
617                                 break;
618                         }
619                 }
620                 else {
621                         VECCOPY(max, t->data[i].center);
622                         VECCOPY(min, t->data[i].center);
623                 }
624         }
625         VecAddf(t->center, min, max);
626         VecMulf(t->center, 0.5);
627
628         if (t->flag & (T_EDIT|T_POSE)) {
629                 Object *ob= G.obedit?G.obedit:t->poseobj;
630                 float vec[3];
631                 
632                 VECCOPY(vec, t->center);
633                 Mat4MulVecfl(ob->obmat, vec);
634                 projectIntView(t, vec, t->center2d);
635         }
636         else {
637                 projectIntView(t, t->center, t->center2d);
638         }
639 }
640
641 void calculateCenter(TransInfo *t) 
642 {
643         switch(t->around) {
644         case V3D_CENTRE:
645                 calculateCenterBound(t);
646                 break;
647         case V3D_CENTROID:
648                 calculateCenterMedian(t);
649                 break;
650         case V3D_CURSOR:
651                 calculateCenterCursor(t);
652                 break;
653         case V3D_LOCAL:
654                 /* Individual element center uses median center for helpline and such */
655                 calculateCenterMedian(t);
656                 break;
657         case V3D_ACTIVE:
658                 /* set median, and if if if... do object center */
659                 calculateCenterMedian(t);
660                 if((t->flag & (T_EDIT|T_POSE))==0) {
661                         Object *ob= OBACT;
662                         if(ob) {
663                                 VECCOPY(t->center, ob->obmat[3]);
664                                 projectIntView(t, t->center, t->center2d);
665                         }
666                 }
667                 
668         }
669
670         /* setting constraint center */
671         VECCOPY(t->con.center, t->center);
672         if(t->flag & (T_EDIT|T_POSE)) {
673                 Object *ob= G.obedit?G.obedit:t->poseobj;
674                 Mat4MulVecfl(ob->obmat, t->con.center);
675         }
676
677         /* voor panning from cameraview */
678         if(t->flag & T_OBJECT) {
679                 if( G.vd->camera==OBACT && G.vd->persp>1) {
680                         float axis[3];
681                         /* persinv is nasty, use viewinv instead, always right */
682                         VECCOPY(axis, t->viewinv[2]);
683                         Normalise(axis);
684
685                         /* 6.0 = 6 grid units */
686                         axis[0]= t->center[0]- 6.0f*axis[0];
687                         axis[1]= t->center[1]- 6.0f*axis[1];
688                         axis[2]= t->center[2]- 6.0f*axis[2];
689                         
690                         projectIntView(t, axis, t->center2d);
691                         
692                         /* rotate only needs correct 2d center, grab needs initgrabz() value */
693                         if(t->mode==TFM_TRANSLATION) VECCOPY(t->center, axis);
694                 }
695         }       
696
697         if(t->spacetype==SPACE_VIEW3D)
698                 initgrabz(t->center[0], t->center[1], t->center[2]);
699 }
700
701 void calculatePropRatio(TransInfo *t)
702 {
703         TransData *td = t->data;
704         int i;
705         float dist;
706         short connected = t->flag & T_PROP_CONNECTED;
707
708         if (t->flag & T_PROP_EDIT) {
709                 for(i = 0 ; i < t->total; i++, td++) {
710                         if (td->flag & TD_SELECTED) {
711                                 td->factor = 1.0f;
712                         }
713                         else if ((connected && 
714                                                 (td->flag & TD_NOTCONNECTED || td->dist > t->propsize))
715                                 ||
716                                         (connected == 0 &&
717                                                 td->rdist > t->propsize)) {
718                                 /* 
719                                    The elements are sorted according to their dist member in the array,
720                                    that means we can stop when it finds one element outside of the propsize.
721                                 */
722                                 td->flag |= TD_NOACTION;
723                                 td->factor = 0.0f;
724                                 restoreElement(td);
725                         }
726                         else {
727                                 /* Use rdist for falloff calculations, it is the real distance */
728                                 td->flag &= ~TD_NOACTION;
729                                 dist= (t->propsize-td->rdist)/t->propsize;
730                                 switch(G.scene->prop_mode) {
731                                 case PROP_SHARP:
732                                         td->factor= dist*dist;
733                                         break;
734                                 case PROP_SMOOTH:
735                                         td->factor= 3.0f*dist*dist - 2.0f*dist*dist*dist;
736                                         break;
737                                 case PROP_ROOT:
738                                         td->factor = (float)sqrt(dist);
739                                         break;
740                                 case PROP_LIN:
741                                         td->factor = dist;
742                                         break;
743                                 case PROP_CONST:
744                                         td->factor = 1.0f;
745                                         break;
746                                 case PROP_SPHERE:
747                                         td->factor = (float)sqrt(2*dist - dist * dist);
748                                         break;
749                                 default:
750                                         td->factor = 1;
751                                 }
752                         }
753                 }
754                 switch(G.scene->prop_mode) {
755                 case PROP_SHARP:
756                         strcpy(t->proptext, "(Sharp)");
757                         break;
758                 case PROP_SMOOTH:
759                         strcpy(t->proptext, "(Smooth)");
760                         break;
761                 case PROP_ROOT:
762                         strcpy(t->proptext, "(Root)");
763                         break;
764                 case PROP_LIN:
765                         strcpy(t->proptext, "(Linear)");
766                         break;
767                 case PROP_CONST:
768                         strcpy(t->proptext, "(Constant)");
769                         break;
770                 case PROP_SPHERE:
771                         strcpy(t->proptext, "(Sphere)");
772                         break;
773                 default:
774                         strcpy(t->proptext, "");
775                 }
776         }
777         else {
778                 for(i = 0 ; i < t->total; i++, td++) {
779                         td->factor = 1.0;
780                 }
781                 strcpy(t->proptext, "");
782         }
783 }
784
785 TransInfo * BIF_GetTransInfo() {
786         return &Trans;
787 }
788