- added GCC warning -Wstrict-prototypes
[blender.git] / source / blender / editors / space_view3d / drawobject.c
index 5c95a6a3026253b671ba49ba09d43379d77c275c..65b621b1d7a3928289abedb1fa114e05d9d1f8ee 100644 (file)
@@ -413,9 +413,6 @@ void drawaxes(float size, char drawtype)
        
        case OB_PLAINAXES:
                for (axis=0; axis<3; axis++) {
-                       float v1[3]= {0.0, 0.0, 0.0};
-                       float v2[3]= {0.0, 0.0, 0.0};
-                       
                        glBegin(GL_LINES);
                        
                        v1[axis]= size;
@@ -478,8 +475,6 @@ void drawaxes(float size, char drawtype)
        case OB_ARROWS:
        default:
                for (axis=0; axis<3; axis++) {
-                       float v1[3]= {0.0, 0.0, 0.0};
-                       float v2[3]= {0.0, 0.0, 0.0};
                        int arrow_axis= (axis==0)?1:0;
                        
                        glBegin(GL_LINES);
@@ -643,10 +638,10 @@ void view3d_cached_text_draw_end(View3D *v3d, ARegion *ar, int depth_write, floa
                                const char *str= (char *)(vos+1);
                                glColor3fv(vos->col);
                                if(vos->flag & V3D_CACHE_TEXT_ASCII) {
-                                       BLF_draw_default_ascii((float)vos->mval[0]+vos->xoffs, (float)vos->mval[1], (depth_write)? 0.0f: 2.0f, str);
+                                       BLF_draw_default_ascii((float)vos->mval[0]+vos->xoffs, (float)vos->mval[1], (depth_write)? 0.0f: 2.0f, str, 65535); /* XXX, use real length */
                                }
                                else {
-                                       BLF_draw_default((float)vos->mval[0]+vos->xoffs, (float)vos->mval[1], (depth_write)? 0.0f: 2.0f, str);
+                                       BLF_draw_default((float)vos->mval[0]+vos->xoffs, (float)vos->mval[1], (depth_write)? 0.0f: 2.0f, str, 65535); /* XXX, use real length */
                                }
                        }
                }
@@ -1218,10 +1213,15 @@ 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, aspx, aspy, caspx, caspy, shx, shy;
+       float vec[8][4], facx, facy, depth, aspx, aspy, caspx, caspy, shx, shy;
        int i;
+       float drawsize;
+       const short is_view= (rv3d->persp==RV3D_CAMOB && ob==v3d->camera);
 
+       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]);
+       
        cam= ob->data;
        aspx= (float) scene->r.xsch*scene->r.xasp;
        aspy= (float) scene->r.ysch*scene->r.yasp;
@@ -1238,40 +1238,46 @@ static void drawcamera(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob
        glDisable(GL_LIGHTING);
        glDisable(GL_CULL_FACE);
        
-       if(rv3d->persp==RV3D_CAMOB && cam->type==CAM_ORTHO && ob==v3d->camera) {
-               facx= 0.5*cam->ortho_scale*caspx;
-               facy= 0.5*cam->ortho_scale*caspy;
-               shx= cam->shiftx * cam->ortho_scale;
-               shy= cam->shifty * cam->ortho_scale;
-               depth= -cam->clipsta-0.1;
+       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 {
-               fac= cam->drawsize;
-               if(rv3d->persp==RV3D_CAMOB && ob==v3d->camera) fac= cam->clipsta+0.1; /* that way it's always visible */
+               /* that way it's always visible - clipsta+0.1 */
+               float fac;
+               drawsize= cam->drawsize / ((scax + scay + scaz) / 3.0f);
+               fac= is_view ? (cam->clipsta + 0.1f) : drawsize;
+               depth= - fac*cam->lens/16.0 * scaz;
+               facx= fac * caspx * scax;
+               facy= fac * caspy * scay;
+               shx= cam->shiftx*fac*2 * scax;
+               shy= cam->shifty*fac*2 * scay;
                
-               depth= - fac*cam->lens/16.0;
-               facx= fac*caspx;
-               facy= fac*caspy;
-               shx= cam->shiftx*fac*2;
-               shy= cam->shifty*fac*2;
        }
        
-       vec[0][0]= 0.0; vec[0][1]= 0.0; vec[0][2]= 0.001;       /* GLBUG: for picking at iris Entry (well thats old!) */
+       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;
 
+       /* camera frame */
        glBegin(GL_LINE_LOOP);
                glVertex3fv(vec[1]); 
                glVertex3fv(vec[2]); 
                glVertex3fv(vec[3]); 
                glVertex3fv(vec[4]);
        glEnd();
-       
 
-       if(rv3d->persp==RV3D_CAMOB && ob==v3d->camera) return;
-       
+       if(is_view)
+               return;
+
+       /* center point to camera frame */
        glBegin(GL_LINE_STRIP);
                glVertex3fv(vec[2]); 
                glVertex3fv(vec[0]);
@@ -1285,7 +1291,7 @@ static void drawcamera(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob
        /* arrow on top */
        vec[0][2]= depth;
 
-       
+
        /* draw an outline arrow for inactive cameras and filled
         * for active cameras. We actually draw both outline+filled
         * for active cameras so the wire can be seen side-on */        
@@ -1294,15 +1300,15 @@ 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]= shx + (-0.7 * cam->drawsize);
-               vec[0][1]= shy + (cam->drawsize * (caspy + 0.1));
+               vec[0][0]= shx + ((-0.7 * drawsize) * scax);
+               vec[0][1]= shy + ((drawsize * (caspy + 0.1)) * scay);
                glVertex3fv(vec[0]); /* left */
                
-               vec[0][0]= shx + (0.7 * cam->drawsize);
+               vec[0][0]= shx + ((0.7 * drawsize) * scax);
                glVertex3fv(vec[0]); /* right */
                
                vec[0][0]= shx;
-               vec[0][1]= shy + (1.1 * cam->drawsize * (caspy + 0.7));
+               vec[0][1]= shy + ((1.1 * drawsize * (caspy + 0.7)) * scay);
                glVertex3fv(vec[0]); /* top */
        
                glEnd();
@@ -1310,6 +1316,9 @@ static void drawcamera(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob
 
        if(flag==0) {
                if(cam->flag & (CAM_SHOWLIMITS+CAM_SHOWMIST)) {
+                       float nobmat[4][4];
+                       World *wrld;
+       
                        /* draw in normalized object matrix space */
                        copy_m4_m4(nobmat, ob->obmat);
                        normalize_m4(nobmat);
@@ -2321,7 +2330,7 @@ static void draw_em_fancy(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object
                }
        }
        
-       if((me->drawflag & (ME_DRAWFACES)) || paint_facesel_test(ob)) { /* transp faces */
+       if(me->drawflag & ME_DRAWFACES) {       /* transp faces */
                unsigned char col1[4], col2[4], col3[4];
                        
                UI_GetThemeColor4ubv(TH_FACE, (char *)col1);
@@ -2458,7 +2467,8 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
        Object *ob= base->object;
        Mesh *me = ob->data;
        Material *ma= give_current_material(ob, 1);
-       int hasHaloMat = (ma && (ma->material_type == MA_TYPE_HALO));
+       const short hasHaloMat = (ma && (ma->material_type == MA_TYPE_HALO));
+       const short is_paint_sel= (ob==OBACT && paint_facesel_test(ob));
        int draw_wire = 0;
        int totvert, totedge, totface;
        DispList *dl;
@@ -2480,7 +2490,7 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
                glFrontFace((ob->transflag&OB_NEG_SCALE)?GL_CW:GL_CCW);
 
                // Unwanted combination.
-       if (ob==OBACT && paint_facesel_test(ob)) draw_wire = 0;
+       if (is_paint_sel) draw_wire = 0;
 
        if(dt==OB_BOUNDBOX) {
                if((v3d->flag2 & V3D_RENDER_OVERRIDE && v3d->drawtype >= OB_WIRE)==0)
@@ -2494,11 +2504,10 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
        else if(dt==OB_WIRE || totface==0) {
                draw_wire = 1; /* draw wire only, no depth buffer stuff  */
        }
-       else if(        (ob==OBACT && (ob->mode & OB_MODE_TEXTURE_PAINT || paint_facesel_test(ob))) ||
+       else if(        (is_paint_sel || (ob==OBACT && ob->mode & OB_MODE_TEXTURE_PAINT)) ||
                                CHECK_OB_DRAWTEXTURE(v3d, dt))
        {
-               int faceselect= (ob==OBACT && paint_facesel_test(ob));
-               if ((v3d->flag&V3D_SELECT_OUTLINE) && ((v3d->flag2 & V3D_RENDER_OVERRIDE)==0) && (base->flag&SELECT) && !(G.f&G_PICKSEL || paint_facesel_test(ob)) && !draw_wire) {
+               if ((v3d->flag&V3D_SELECT_OUTLINE) && ((v3d->flag2 & V3D_RENDER_OVERRIDE)==0) && (base->flag&SELECT) && !(G.f&G_PICKSEL || is_paint_sel) && !draw_wire) {
                        draw_mesh_object_outline(v3d, ob, dm);
                }
 
@@ -2513,10 +2522,10 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
                        glFrontFace(GL_CCW);
                }
                else {
-                       draw_mesh_textured(scene, v3d, rv3d, ob, dm, faceselect);
+                       draw_mesh_textured(scene, v3d, rv3d, ob, dm, is_paint_sel);
                }
 
-               if(!faceselect) {
+               if(!is_paint_sel) {
                        if(base->flag & SELECT)
                                UI_ThemeColor((ob==OBACT)?TH_ACTIVE:TH_SELECT);
                        else
@@ -3545,6 +3554,11 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
                case PART_DRAW_AXIS:
                        /* lets calculate the scale: */
                        pixsize= view3d_pixel_size(rv3d, ob->obmat[3]);
+                       
+                       if(part->draw_size==0.0)
+                               pixsize*=2.0;
+                       else
+                               pixsize*=part->draw_size;
 
                        if(draw_as==PART_DRAW_AXIS)
                                create_cdata = 1;
@@ -4086,8 +4100,8 @@ static void draw_ptcache_edit(Scene *scene, View3D *v3d, PTCacheEdit *edit)
        glEnableClientState(GL_VERTEX_ARRAY);
        glEnableClientState(GL_COLOR_ARRAY);
 
-       glEnable(GL_COLOR_MATERIAL);
        glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
+       glEnable(GL_COLOR_MATERIAL);
        glShadeModel(GL_SMOOTH);
 
        if(pset->brushtype == PE_BRUSH_WEIGHT) {
@@ -5338,10 +5352,12 @@ static void draw_bounding_volume(Scene *scene, Object *ob)
                bb= ob->bb ? ob->bb : ( (Curve *)ob->data )->bb;
        }
        else if(ob->type==OB_MBALL) {
-               bb= ob->bb;
-               if(bb==0) {
-                       makeDispListMBall(scene, ob);
+               if(is_basis_mball(ob)) {
                        bb= ob->bb;
+                       if(bb==0) {
+                               makeDispListMBall(scene, ob);
+                               bb= ob->bb;
+                       }
                }
        }
        else {
@@ -5392,7 +5408,7 @@ static void drawtexspace(Object *ob)
 }
 
 /* draws wire outline */
-static void drawSolidSelect(Scene *scene, View3D *v3d, ARegion *ar, Base *base) 
+static void drawObjectSelect(Scene *scene, View3D *v3d, ARegion *ar, Base *base)
 {
        RegionView3D *rv3d= ar->regiondata;
        Object *ob= base->object;
@@ -5421,8 +5437,10 @@ static void drawSolidSelect(Scene *scene, View3D *v3d, ARegion *ar, Base *base)
                        draw_index_wire= 1;
                }
        } else if (ob->type==OB_MBALL) {
-               if((base->flag & OB_FROMDUPLI)==0) 
-                       drawDispListwire(&ob->disp);
+               if(is_basis_mball(ob)) {
+                       if((base->flag & OB_FROMDUPLI)==0)
+                               drawDispListwire(&ob->disp);
+               }
        }
        else if(ob->type==OB_ARMATURE) {
                if(!(ob->mode & OB_MODE_POSE))
@@ -5476,7 +5494,9 @@ static void drawWireExtra(Scene *scene, RegionView3D *rv3d, Object *ob)
                                draw_index_wire= 1;
                }
        } else if (ob->type==OB_MBALL) {
-               drawDispListwire(&ob->disp);
+               if(is_basis_mball(ob)) {
+                       drawDispListwire(&ob->disp);
+               }
        }
 
        glDepthMask(1);
@@ -5786,12 +5806,12 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                if (cu->disp.first==NULL) makeDispListCurveTypes(scene, ob, 0);
        }
        
-       /* draw outline for selected solid objects, mesh does itself */
+       /* draw outline for selected objects, mesh does itself */
        if((v3d->flag & V3D_SELECT_OUTLINE) && ((v3d->flag2 & V3D_RENDER_OVERRIDE)==0) && ob->type!=OB_MESH) {
-               if(dt>OB_WIRE && dt<OB_TEXTURE && (ob->mode & OB_MODE_EDIT)==0 && (flag & DRAW_SCENESET)==0) {
+               if(dt>OB_WIRE && (ob->mode & OB_MODE_EDIT)==0 && (flag & DRAW_SCENESET)==0) {
                        if (!(ob->dtx&OB_DRAWWIRE) && (ob->flag&SELECT) && !(flag&DRAW_PICKING)) {
                                
-                               drawSolidSelect(scene, v3d, ar, base);
+                               drawObjectSelect(scene, v3d, ar, base);
                        }
                }
        }
@@ -6253,10 +6273,10 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                if (list) {
                        bConstraint *curcon;
                        bConstraintOb *cob;
-                       char col[4], col2[4];
+                       char col1[4], col2[4];
                        
-                       UI_GetThemeColor3ubv(TH_GRID, col);
-                       UI_make_axis_color(col, col2, 'z');
+                       UI_GetThemeColor3ubv(TH_GRID, col1);
+                       UI_make_axis_color(col1, col2, 'z');
                        glColor3ubv((GLubyte *)col2);
                        
                        cob= constraints_make_evalob(scene, ob, NULL, CONSTRAINT_OBTYPE_OBJECT);