patch [#22901] pixel- and aspectratio corrected camera representation in 3dview
authorCampbell Barton <ideasman42@gmail.com>
Mon, 26 Jul 2010 21:35:24 +0000 (21:35 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 26 Jul 2010 21:35:24 +0000 (21:35 +0000)
from Ralf H√∂lzemer (cheleb) with my own edits to make the selected camera more clear in the camera view, this also works around the problem where you cant see the camera to select it with passepartout close to 1.0.

--- snip ---
Attached patch changes the camera representation to draw pixel- and aspectratio corrected in 3dview. It does also fix
a little issue where the camera name would jump when the title save would be (de)activated in the camera view.

source/blender/editors/space_view3d/drawobject.c
source/blender/editors/space_view3d/view3d_draw.c

index 6e9b437dbc50e17b594902063b6164ac09b9ef92..30bfa12300712e7c340a4b3b48083cecfe83aa7e 100644 (file)
@@ -1248,17 +1248,28 @@ static void drawcamera(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob
        /* a standing up pyramid with (0,0,0) as top */
        Camera *cam;
        World *wrld;
-       float nobmat[4][4], vec[8][4], fac, facx, facy, depth;
+       float nobmat[4][4], vec[8][4], fac, facx, facy, depth, aspx, aspy, caspx, caspy;
        int i;
 
        cam= ob->data;
+       aspx= (float) scene->r.xsch*scene->r.xasp;
+       aspy= (float) scene->r.ysch*scene->r.yasp;
+
+       if(aspx < aspy) {
+               caspx= aspx / aspy;
+               caspy= 1.0;
+       }
+       else {
+               caspx= 1.0;
+               caspy= aspy / aspx;
+       }
        
        glDisable(GL_LIGHTING);
        glDisable(GL_CULL_FACE);
        
        if(rv3d->persp>=2 && cam->type==CAM_ORTHO && ob==v3d->camera) {
-               facx= 0.5*cam->ortho_scale*1.28;
-               facy= 0.5*cam->ortho_scale*1.024;
+               facx= 0.5*cam->ortho_scale*caspx;
+               facy= 0.5*cam->ortho_scale*caspy;
                depth= -cam->clipsta-0.1;
        }
        else {
@@ -1266,8 +1277,8 @@ static void drawcamera(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob
                if(rv3d->persp>=2 && ob==v3d->camera) fac= cam->clipsta+0.1; /* that way it's always visible */
                
                depth= - fac*cam->lens/16.0;
-               facx= fac*1.28;
-               facy= fac*1.024;
+               facx= fac*caspx;
+               facy= fac*caspy;
        }
        
        vec[0][0]= 0.0; vec[0][1]= 0.0; vec[0][2]= 0.001;       /* GLBUG: for picking at iris Entry (well thats old!) */
@@ -1308,16 +1319,16 @@ static void drawcamera(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob
                else if (i==1 && (ob == v3d->camera)) glBegin(GL_TRIANGLES);
                else break;
                
-               vec[0][0]= -0.7*cam->drawsize;
-               vec[0][1]= 1.1*cam->drawsize;
+               vec[0][0]= -0.7*cam->drawsize*caspx;
+               vec[0][1]= 1.1*cam->drawsize*caspy;
                glVertex3fv(vec[0]);
                
                vec[0][0]= 0.0; 
-               vec[0][1]= 1.8*cam->drawsize;
+               vec[0][1]= 1.8*cam->drawsize*caspy;
                glVertex3fv(vec[0]);
                
-               vec[0][0]= 0.7*cam->drawsize; 
-               vec[0][1]= 1.1*cam->drawsize;
+               vec[0][0]= 0.7*cam->drawsize*caspx
+               vec[0][1]= 1.1*cam->drawsize*caspy;
                glVertex3fv(vec[0]);
        
                glEnd();
@@ -6138,7 +6149,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
 
                /* draw extra: after normal draw because of makeDispList */
                if(dtx && (G.f & G_RENDER_OGL)==0) {
-        
+
                        if(dtx & OB_AXIS) {
                                drawaxes(rv3d, rv3d->viewmatob, 1.0f, flag, OB_ARROWS);
                        }
index 38e763e6f88a8728bed26abe82dc451ac4f708a2..3d78ddeec08d20fc1596de65d1f964e84c5c7961 100644 (file)
@@ -971,6 +971,7 @@ static void drawviewborder(Scene *scene, ARegion *ar, View3D *v3d)
        extern void gl_round_box(int mode, float minx, float miny, float maxx, float maxy, float rad);          // interface_panel.c
        float fac, a;
        float x1, x2, y1, y2;
+       float x1i, x2i, y1i, y2i;
        float x3, y3, x4, y4;
        rctf viewborder;
        Camera *ca= NULL;
@@ -982,11 +983,18 @@ static void drawviewborder(Scene *scene, ARegion *ar, View3D *v3d)
                ca = v3d->camera->data;
        
        calc_viewborder(scene, ar, rv3d, v3d, &viewborder);
+       /* the offsets */
        x1= viewborder.xmin;
        y1= viewborder.ymin;
        x2= viewborder.xmax;
        y2= viewborder.ymax;
        
+       /* apply offsets so the real 3D camera shows through */
+       x1i= (int)(x1 - 1.0f);
+       y1i= (int)(y1 - 1.0f);
+       x2i= (int)(x2 + 1.0f);
+       y2i= (int)(y2 + 1.0f);
+       
        /* passepartout, specified in camera edit buttons */
        if (ca && (ca->flag & CAM_SHOWPASSEPARTOUT) && ca->passepartalpha > 0.000001) {
                if (ca->passepartalpha == 1.0) {
@@ -996,29 +1004,29 @@ static void drawviewborder(Scene *scene, ARegion *ar, View3D *v3d)
                        glEnable(GL_BLEND);
                        glColor4f(0, 0, 0, ca->passepartalpha);
                }
-               if (x1 > 0.0)
-                       glRectf(0.0, (float)ar->winy, x1, 0.0);
-               if (x2 < (float)ar->winx)
-                       glRectf(x2, (float)ar->winy, (float)ar->winx, 0.0);
-               if (y2 < (float)ar->winy)
-                       glRectf(x1, (float)ar->winy, x2, y2);
-               if (y2 > 0.0) 
-                       glRectf(x1, y1, x2, 0.0);
+               if (x1i > 0.0)
+                       glRectf(0.0, (float)ar->winy, x1i, 0.0);
+               if (x2i < (float)ar->winx)
+                       glRectf(x2i, (float)ar->winy, (float)ar->winx, 0.0);
+               if (y2i < (float)ar->winy)
+                       glRectf(x1i, (float)ar->winy, x2i, y2i);
+               if (y2i > 0.0) 
+                       glRectf(x1i, y1i, x2i, 0.0);
                
                glDisable(GL_BLEND);
        }
-       
+
        /* edge */
-       glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); 
-       
+       glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);      
+
        setlinestyle(0);
        UI_ThemeColor(TH_BACK);
-       glRectf(x1, y1, x2, y2);
+       glRectf(x1i, y1i, x2i, y2i);
        
        setlinestyle(3);
        UI_ThemeColor(TH_WIRE);
-       glRectf(x1, y1, x2, y2);
-       
+       glRectf(x1i, y1i, x2i, y2i);
+
        /* border */
        if(scene->r.mode & R_BORDER) {
                
@@ -1031,7 +1039,7 @@ static void drawviewborder(Scene *scene, ARegion *ar, View3D *v3d)
                cpack(0x4040FF);
                glRectf(x3,  y3,  x4,  y4); 
        }
-       
+    
        /* safety border */
        if (ca && (ca->flag & CAM_SHOWTITLESAFE)) {
                fac= 0.1;
@@ -1049,14 +1057,14 @@ static void drawviewborder(Scene *scene, ARegion *ar, View3D *v3d)
                uiSetRoundBox(15);
                gl_round_box(GL_LINE_LOOP, x1, y1, x2, y2, 12.0);
        }
-       
+
        setlinestyle(0);
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
-       
+
        /* camera name - draw in highlighted text color */
        if (ca && (ca->flag & CAM_SHOWNAME)) {
                UI_ThemeColor(TH_TEXT_HI);
-               BLF_draw_default(x1, y1-15, 0.0f, v3d->camera->id.name+2);
+               BLF_draw_default(x1i, y1i-15, 0.0f, v3d->camera->id.name+2);
                UI_ThemeColor(TH_WIRE);
        }
 }