Merging r40653 through r40847 from trunk into soc-2011-tomato
[blender.git] / source / blender / editors / space_view3d / drawobject.c
index 35de623..c820ef5 100644 (file)
@@ -1593,16 +1593,13 @@ static void drawcamera(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base
        /* a standing up pyramid with (0,0,0) as top */
        Camera *cam;
        Object *ob= base->object;
-       float vec[8][4], facx, facy, depth, aspx, aspy, caspx, caspy, shx, shy;
+       float tvec[3];
+       float vec[4][3], asp[2], shift[2], scale[3];
        int i;
        float drawsize;
        const short is_view= (rv3d->persp==RV3D_CAMOB && ob==v3d->camera);
        MovieClip *clip= object_get_movieclip(scene, base->object);
 
-       const float scax= 1.0f / len_v3(ob->obmat[0]);
-       const float scay= 1.0f / len_v3(ob->obmat[1]);
-       const float scaz= 1.0f / len_v3(ob->obmat[2]);
-
        /* draw data for movie clip set as active for scene */
        if(clip)
                draw_viewport_reconstruction(scene, base, v3d, clip, flag);
@@ -1616,82 +1613,43 @@ static void drawcamera(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base
 #endif
 
        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(cam->type==CAM_ORTHO) {
-               facx= 0.5f * cam->ortho_scale * caspx * scax;
-               facy= 0.5f * cam->ortho_scale * caspy * scay;
-               shx= cam->shiftx * cam->ortho_scale * scax;
-               shy= cam->shifty * cam->ortho_scale * scay;
-               depth= is_view ? -((cam->clipsta * scaz) + 0.1f) : - cam->drawsize * cam->ortho_scale * scaz;
-               
-               drawsize= 0.5f * cam->ortho_scale;
-       }
-       else {
-               /* that way it's always visible - clipsta+0.1 */
-               float fac;
-               drawsize= cam->drawsize / ((scax + scay + scaz) / 3.0f);
+       scale[0]= 1.0f / len_v3(ob->obmat[0]);
+       scale[1]= 1.0f / len_v3(ob->obmat[1]);
+       scale[2]= 1.0f / len_v3(ob->obmat[2]);
 
-               if(is_view) {
-                       /* fixed depth, variable size (avoids exceeding clipping range) */
-                       depth = -(cam->clipsta + 0.1f);
-                       fac = depth / (cam->lens/ (cam->sensor_x / 2.0f));
-               }
-               else {
-                       /* fixed size, variable depth (stays a reasonable size in the 3D view) */
-                       depth= drawsize * cam->lens/-16.0f * scaz;
-                       fac= drawsize;
-               }
+       camera_view_frame_ex(scene, cam, cam->drawsize, is_view, scale,
+                            asp, shift, &drawsize, vec);
 
-               facx= fac * caspx * scax;
-               facy= fac * caspy * scay;
-               shx= cam->shiftx*fac*2 * scax;
-               shy= cam->shifty*fac*2 * scay;
-       }
-       
-       vec[0][0]= 0.0; vec[0][1]= 0.0; vec[0][2]= 0.0;
-       vec[1][0]= shx + facx; vec[1][1]= shy + facy; vec[1][2]= depth;
-       vec[2][0]= shx + facx; vec[2][1]= shy - facy; vec[2][2]= depth;
-       vec[3][0]= shx - facx; vec[3][1]= shy - facy; vec[3][2]= depth;
-       vec[4][0]= shx - facx; vec[4][1]= shy + facy; vec[4][2]= depth;
+       glDisable(GL_LIGHTING);
+       glDisable(GL_CULL_FACE);
 
        /* camera frame */
        glBegin(GL_LINE_LOOP);
-               glVertex3fv(vec[1]); 
-               glVertex3fv(vec[2]); 
-               glVertex3fv(vec[3]); 
-               glVertex3fv(vec[4]);
+       glVertex3fv(vec[0]);
+       glVertex3fv(vec[1]);
+       glVertex3fv(vec[2]);
+       glVertex3fv(vec[3]);
        glEnd();
 
        if(is_view)
                return;
 
+       zero_v3(tvec);
+
        /* center point to camera frame */
        glBegin(GL_LINE_STRIP);
-               glVertex3fv(vec[2]); 
-               glVertex3fv(vec[0]);
-               glVertex3fv(vec[1]);
-               glVertex3fv(vec[4]);
-               glVertex3fv(vec[0]);
-               glVertex3fv(vec[3]); 
+       glVertex3fv(vec[1]);
+       glVertex3fv(tvec);
+       glVertex3fv(vec[0]);
+       glVertex3fv(vec[3]);
+       glVertex3fv(tvec);
+       glVertex3fv(vec[2]);
        glEnd();
 
 
        /* arrow on top */
-       vec[0][2]= depth;
+       tvec[2]= vec[1][2]; /* copy the depth */
 
 
        /* draw an outline arrow for inactive cameras and filled
@@ -1702,16 +1660,16 @@ static void drawcamera(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base
                else if (i==1 && (ob == v3d->camera)) glBegin(GL_TRIANGLES);
                else break;
 
-               vec[0][0]= shx + ((-0.7f * drawsize) * scax);
-               vec[0][1]= shy + ((drawsize * (caspy + 0.1f)) * scay);
-               glVertex3fv(vec[0]); /* left */
+               tvec[0]= shift[0] + ((-0.7f * drawsize) * scale[0]);
+               tvec[1]= shift[1] + ((drawsize * (asp[1] + 0.1f)) * scale[1]);
+               glVertex3fv(tvec); /* left */
                
-               vec[0][0]= shx + ((0.7f * drawsize) * scax);
-               glVertex3fv(vec[0]); /* right */
+               tvec[0]= shift[0] + ((0.7f * drawsize) * scale[0]);
+               glVertex3fv(tvec); /* right */
                
-               vec[0][0]= shx;
-               vec[0][1]= shy + ((1.1f * drawsize * (caspy + 0.7f)) * scay);
-               glVertex3fv(vec[0]); /* top */
+               tvec[0]= shift[0];
+               tvec[1]= shift[1] + ((1.1f * drawsize * (asp[1] + 0.7f)) * scale[1]);
+               glVertex3fv(tvec); /* top */
        
                glEnd();
        }
@@ -5373,8 +5331,6 @@ static void drawspiral(const float cent[3], float rad, float tmat[][4], int star
                }
        }
        else {
-               a= 0;
-
                fac= (float)(CIRCLE_RESOL-1) * tot_inv;
                x= sinval[start] * fac;
                y= cosval[start] * fac;