Merging r41597 through r41607 from trunk into soc-2011-tomato
[blender.git] / source / blender / editors / space_view3d / drawobject.c
index 491959cbb5558080923d359de383a4d0ed0cc08f..4809e463d7520fb83589dddceb1c237eba453873 100644 (file)
@@ -55,6 +55,7 @@
 #include "BLI_utildefines.h"
 
 #include "BKE_anim.h"                  //for the where_on_path function
+#include "BKE_camera.h"
 #include "BKE_constraint.h" // for the get_constraint_target function
 #include "BKE_curve.h"
 #include "BKE_DerivedMesh.h"
@@ -73,6 +74,7 @@
 #include "BKE_paint.h"
 #include "BKE_particle.h"
 #include "BKE_pointcache.h"
+#include "BKE_scene.h"
 #include "BKE_unit.h"
 #include "BKE_movieclip.h"
 #include "BKE_tracking.h"
 
 
 /* this condition has been made more complex since editmode can draw textures */
-#define CHECK_OB_DRAWTEXTURE(vd, dt) \
-((vd->drawtype==OB_TEXTURE && dt>OB_SOLID) || \
+#define CHECK_OB_DRAWTEXTURE(vd, dt)                                          \
+       ((vd->drawtype==OB_TEXTURE && dt>OB_SOLID) ||                             \
        (vd->drawtype==OB_SOLID && vd->flag2 & V3D_SOLID_TEX))
 
-static void draw_bounding_volume(Scene *scene, Object *ob);
+static void draw_bounding_volume(Scene *scene, Object *ob, char type);
 
 static void drawcube_size(float size);
 static void drawcircle_size(float size);
@@ -2924,15 +2926,14 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
        totface = dm->getNumFaces(dm);
        
        /* vertexpaint, faceselect wants this, but it doesnt work for shaded? */
-       if(dt!=OB_SHADED)
-               glFrontFace((ob->transflag&OB_NEG_SCALE)?GL_CW:GL_CCW);
+       glFrontFace((ob->transflag&OB_NEG_SCALE)?GL_CW:GL_CCW);
 
                // Unwanted combination.
        if (is_paint_sel) draw_wire = 0;
 
        if(dt==OB_BOUNDBOX) {
                if((v3d->flag2 & V3D_RENDER_OVERRIDE && v3d->drawtype >= OB_WIRE)==0)
-                       draw_bounding_volume(scene, ob);
+                       draw_bounding_volume(scene, ob, ob->boundtype);
        }
        else if(hasHaloMat || (totface==0 && totedge==0)) {
                glPointSize(1.5);
@@ -3042,7 +3043,7 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
                                dm->drawLooseEdges(dm);
                }
        }
-       else if(dt==OB_SHADED) {
+       else if(dt==OB_PAINT) {
                if(ob==OBACT) {
                        if(ob && ob->mode & OB_MODE_WEIGHT_PAINT) {
                                /* enforce default material settings */
@@ -3900,7 +3901,7 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
 
        totpart=psys->totpart;
 
-       cfra= bsystem_time(scene, NULL, (float)CFRA, 0.0f);
+       cfra= BKE_curframe(scene);
 
        if(draw_as==PART_DRAW_PATH && psys->pathcache==NULL && psys->childcache==NULL)
                draw_as=PART_DRAW_DOT;
@@ -5149,7 +5150,7 @@ static void drawnurb(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
                        int skip= nu->resolu/16;
                        
                        while (nr-->0) { /* accounts for empty bevel lists */
-                               float fac= bevp->radius * ts->normalsize;
+                               const float fac= bevp->radius * ts->normalsize;
                                float vec_a[3]; // Offset perpendicular to the curve
                                float vec_b[3]; // Delta along the curve
 
@@ -5165,9 +5166,9 @@ static void drawnurb(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
                                mul_qt_v3(bevp->quat, vec_b);
                                add_v3_v3(vec_a, bevp->vec);
                                add_v3_v3(vec_b, bevp->vec);
-                               
-                               VECSUBFAC(vec_a, vec_a, bevp->dir, fac);
-                               VECSUBFAC(vec_b, vec_b, bevp->dir, fac);
+
+                               madd_v3_v3fl(vec_a, bevp->dir, -fac);
+                               madd_v3_v3fl(vec_b, bevp->dir, -fac);
 
                                glBegin(GL_LINE_STRIP);
                                glVertex3fv(vec_a);
@@ -5698,7 +5699,7 @@ static void get_local_bounds(Object *ob, float center[3], float size[3])
 }
 #endif
 
-static void draw_bb_quadric(BoundBox *bb, short type)
+static void draw_bb_quadric(BoundBox *bb, char type)
 {
        float size[3], cent[3];
        GLUquadricObj *qobj = gluNewQuadric(); 
@@ -5737,7 +5738,7 @@ static void draw_bb_quadric(BoundBox *bb, short type)
        gluDeleteQuadric(qobj); 
 }
 
-static void draw_bounding_volume(Scene *scene, Object *ob)
+static void draw_bounding_volume(Scene *scene, Object *ob, char type)
 {
        BoundBox *bb= NULL;
        
@@ -5763,8 +5764,8 @@ static void draw_bounding_volume(Scene *scene, Object *ob)
        
        if(bb==NULL) return;
        
-       if(ob->boundtype==OB_BOUND_BOX) draw_box(bb->vec);
-       else draw_bb_quadric(bb, ob->boundtype);
+       if(type==OB_BOUND_BOX) draw_box(bb->vec);
+       else draw_bb_quadric(bb, type);
        
 }
 
@@ -5976,7 +5977,6 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
        Object *ob;
        Curve *cu;
        RegionView3D *rv3d= ar->regiondata;
-       //float cfraont;
        float vec1[3], vec2[3];
        unsigned int col=0;
        int /*sel, drawtype,*/ colindex= 0;
@@ -6015,83 +6015,6 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
        /* no return after this point, otherwise leaks */
        view3d_cached_text_draw_begin();
        
-
-       /* draw keys? */
-#if 0 // XXX old animation system
-       if(base==(scene->basact) || (base->flag & (SELECT+BA_WAS_SEL))) {
-               if(flag==0 && warning_recursive==0 && ob!=scene->obedit) {
-                       if(ob->ipo && ob->ipo->showkey && (ob->ipoflag & OB_DRAWKEY)) {
-                               ListBase elems;
-                               CfraElem *ce;
-                               float temp[7][3];
-
-                               warning_recursive= 1;
-
-                               elems.first= elems.last= 0;
-                               // warning: no longer checks for certain ob-keys only... (so does this need to use the proper ipokeys then?)
-                               make_cfra_list(ob->ipo, &elems); 
-
-                               cfraont= (scene->r.cfra);
-                               drawtype= v3d->drawtype;
-                               if(drawtype>OB_WIRE) v3d->drawtype= OB_WIRE;
-                               sel= base->flag;
-                               memcpy(temp, &ob->loc, 7*3*sizeof(float));
-
-                               ipoflag= ob->ipoflag;
-                               ob->ipoflag &= ~OB_OFFS_OB;
-
-                               set_no_parent_ipo(1);
-                               disable_speed_curve(1);
-
-                               if ((ob->ipoflag & OB_DRAWKEYSEL)==0) {
-                                       ce= elems.first;
-                                       while(ce) {
-                                               if(!ce->sel) {
-                                                       (scene->r.cfra)= ce->cfra/scene->r.framelen;
-
-                                                       base->flag= 0;
-
-                                                       where_is_object_time(scene, ob, (scene->r.cfra));
-                                                       draw_object(scene, ar, v3d, base, 0);
-                                               }
-                                               ce= ce->next;
-                                       }
-                               }
-
-                               ce= elems.first;
-                               while(ce) {
-                                       if(ce->sel) {
-                                               (scene->r.cfra)= ce->cfra/scene->r.framelen;
-
-                                               base->flag= SELECT;
-
-                                               where_is_object_time(scene, ob, (scene->r.cfra));
-                                               draw_object(scene, ar, v3d, base, 0);
-                                       }
-                                       ce= ce->next;
-                               }
-
-                               set_no_parent_ipo(0);
-                               disable_speed_curve(0);
-
-                               base->flag= sel;
-                               ob->ipoflag= ipoflag;
-
-                               /* restore icu->curval */
-                               (scene->r.cfra)= cfraont;
-
-                               memcpy(&ob->loc, temp, 7*3*sizeof(float));
-                               where_is_object(scene, ob);
-                               v3d->drawtype= drawtype;
-
-                               BLI_freelistN(&elems);
-
-                               warning_recursive= 0;
-                       }
-               }
-       }
-#endif // XXX old animation system
-
        /* patch? children objects with a timeoffs change the parents. How to solve! */
        /* if( ((int)ob->ctime) != F_(scene->r.cfra)) where_is_object(scene, ob); */
        
@@ -6149,7 +6072,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                                        if(base->flag & (SELECT+BA_WAS_SEL)) {
                                                /* uses darker active color for non-active + selected*/
                                                theme_id= TH_GROUP_ACTIVE;
-
+                                               
                                                if(scene->basact != base) {
                                                        theme_shade= -16;
                                                }
@@ -6183,7 +6106,9 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
        }
 
        /* maximum drawtype */
-       dt= MIN2(v3d->drawtype, ob->dt);
+       dt= v3d->drawtype;
+       if(dt==OB_RENDER) dt= OB_SOLID;
+       dt= MIN2(dt, ob->dt);
        if(v3d->zbuf==0 && dt>OB_WIRE) dt= OB_WIRE;
        dtx= 0;
 
@@ -6198,7 +6123,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                                        dt= OB_SOLID;
                                }
                                else {
-                                       dt= OB_SHADED;
+                                       dt= OB_PAINT;
                                }
 
                                glEnable(GL_DEPTH_TEST);
@@ -6328,7 +6253,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                        }
                        else if(dt==OB_BOUNDBOX) {
                                if((v3d->flag2 & V3D_RENDER_OVERRIDE && v3d->drawtype >= OB_WIRE)==0)
-                                       draw_bounding_volume(scene, ob);
+                                       draw_bounding_volume(scene, ob, ob->boundtype);
                        }
                        else if(ED_view3d_boundbox_clip(rv3d, ob->obmat, ob->bb ? ob->bb : cu->bb))
                                empty_object= drawDispList(scene, v3d, rv3d, base, dt);
@@ -6344,7 +6269,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                        }
                        else if(dt==OB_BOUNDBOX) {
                                if((v3d->flag2 & V3D_RENDER_OVERRIDE && v3d->drawtype >= OB_WIRE)==0)
-                                       draw_bounding_volume(scene, ob);
+                                       draw_bounding_volume(scene, ob, ob->boundtype);
                        }
                        else if(ED_view3d_boundbox_clip(rv3d, ob->obmat, ob->bb ? ob->bb : cu->bb)) {
                                empty_object= drawDispList(scene, v3d, rv3d, base, dt);
@@ -6361,7 +6286,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                                drawmball(scene, v3d, rv3d, base, dt);
                        else if(dt==OB_BOUNDBOX) {
                                if((v3d->flag2 & V3D_RENDER_OVERRIDE && v3d->drawtype >= OB_WIRE)==0)
-                                       draw_bounding_volume(scene, ob);
+                                       draw_bounding_volume(scene, ob, ob->boundtype);
                        }
                        else 
                                empty_object= drawmball(scene, v3d, rv3d, base, dt);
@@ -6603,6 +6528,14 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                        }
                }
 
+               if(ob->gameflag & OB_BOUNDS) {
+                       if(ob->boundtype!=ob->collision_boundtype || (dtx & OB_BOUNDBOX)==0) {
+                               setlinestyle(2);
+                               draw_bounding_volume(scene, ob, ob->collision_boundtype);
+                               setlinestyle(0);
+                       }
+               }
+
                /* draw extra: after normal draw because of makeDispList */
                if(dtx && (G.f & G_RENDER_OGL)==0) {
 
@@ -6610,8 +6543,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                                drawaxes(1.0f, OB_ARROWS);
                        }
                        if(dtx & OB_BOUNDBOX) {
-                               if((v3d->flag2 & V3D_RENDER_OVERRIDE)==0)
-                                       draw_bounding_volume(scene, ob);
+                               draw_bounding_volume(scene, ob, ob->boundtype);
                        }
                        if(dtx & OB_TEXSPACE) drawtexspace(ob);
                        if(dtx & OB_DRAWNAME) {
@@ -6729,7 +6661,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                                        for (ct= targets.first; ct; ct= ct->next) {
                                                /* calculate target's matrix */
                                                if (cti->get_target_matrix) 
-                                                       cti->get_target_matrix(curcon, cob, ct, bsystem_time(scene, ob, (float)(scene->r.cfra), give_timeoffset(ob)));
+                                                       cti->get_target_matrix(curcon, cob, ct, BKE_curframe(scene));
                                                else
                                                        unit_m4(ct->matrix);