Revision: 41456
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=41456
Author:   nicholasbishop
Date:     2011-11-02 00:17:37 +0000 (Wed, 02 Nov 2011)
Log Message:
-----------
Function convertViewVec() contained some piece of code duplicated four
times, pulled out into separate function and cleaned up a bit. Should
be no functional changes.

Review link: http://codereview.appspot.com/5308073/

Modified Paths:
--------------
    trunk/blender/source/blender/editors/transform/transform.c

Modified: trunk/blender/source/blender/editors/transform/transform.c
===================================================================
--- trunk/blender/source/blender/editors/transform/transform.c  2011-11-01 
23:38:34 UTC (rev 41455)
+++ trunk/blender/source/blender/editors/transform/transform.c  2011-11-02 
00:17:37 UTC (rev 41456)
@@ -118,10 +118,22 @@
        calculateCenter2D(t);
 }
 
+static void convertViewVec2D(View2D *v2d, float *vec, int dx, int dy)
+{
+       float divx, divy;
+       
+       divx= v2d->mask.xmax - v2d->mask.xmin;
+       divy= v2d->mask.ymax - v2d->mask.ymin;
+
+       vec[0]= (v2d->cur.xmax - v2d->cur.xmin) * dx / divx;
+       vec[1]= (v2d->cur.ymax - v2d->cur.ymin) * dy / divy;
+       vec[2]= 0.0f;
+}
+
 void convertViewVec(TransInfo *t, float *vec, int dx, int dy)
 {
-       if (t->spacetype==SPACE_VIEW3D) {
-               if (t->ar->regiontype == RGN_TYPE_WINDOW) {
+       if(t->spacetype==SPACE_VIEW3D) {
+               if(t->ar->regiontype == RGN_TYPE_WINDOW) {
                        float mval_f[2];
                        mval_f[0]= dx;
                        mval_f[1]= dy;
@@ -129,51 +141,20 @@
                }
        }
        else if(t->spacetype==SPACE_IMAGE) {
-               View2D *v2d = t->view;
-               float divx, divy, aspx, aspy;
+               float aspx, aspy;
 
-               ED_space_image_uv_aspect(t->sa->spacedata.first, &aspx, &aspy);
+               convertViewVec2D(t->view, vec, dx, dy);
 
-               divx= v2d->mask.xmax-v2d->mask.xmin;
-               divy= v2d->mask.ymax-v2d->mask.ymin;
-
-               vec[0]= aspx*(v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx;
-               vec[1]= aspy*(v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy;
-               vec[2]= 0.0f;
+               ED_space_image_uv_aspect(t->sa->spacedata.first, &aspx, &aspy);
+               vec[0]*= aspx;
+               vec[1]*= aspy;
        }
        else if(ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)) {
-               View2D *v2d = t->view;
-               float divx, divy;
-
-               divx= v2d->mask.xmax-v2d->mask.xmin;
-               divy= v2d->mask.ymax-v2d->mask.ymin;
-
-               vec[0]= (v2d->cur.xmax-v2d->cur.xmin)*(dx) / (divx);
-               vec[1]= (v2d->cur.ymax-v2d->cur.ymin)*(dy) / (divy);
-               vec[2]= 0.0f;
+               convertViewVec2D(t->view, vec, dx, dy);
        }
-       else if(t->spacetype==SPACE_NODE) {
-               View2D *v2d = &t->ar->v2d;
-               float divx, divy;
-
-               divx= v2d->mask.xmax-v2d->mask.xmin;
-               divy= v2d->mask.ymax-v2d->mask.ymin;
-
-               vec[0]= (v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx;
-               vec[1]= (v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy;
-               vec[2]= 0.0f;
+       else if(ELEM(t->spacetype, SPACE_NODE, SPACE_SEQ)) {
+               convertViewVec2D(&t->ar->v2d, vec, dx, dy);
        }
-       else if(t->spacetype==SPACE_SEQ) {
-               View2D *v2d = &t->ar->v2d;
-               float divx, divy;
-
-               divx= v2d->mask.xmax-v2d->mask.xmin;
-               divy= v2d->mask.ymax-v2d->mask.ymin;
-
-               vec[0]= (v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx;
-               vec[1]= (v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy;
-               vec[2]= 0.0f;
-       }
 }
 
 void projectIntView(TransInfo *t, float *vec, int *adr)

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to