edits ontop of Alex's patch from r41292.
[blender.git] / source / blender / blenkernel / intern / object.c
index 3644b02..819a982 100644 (file)
@@ -1,8 +1,4 @@
-/* object.c
- *
- * 
- * $Id$
- *
+/*
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
@@ -760,9 +756,7 @@ void make_local_camera(Camera *cam)
        
        if(cam->id.lib==NULL) return;
        if(cam->id.us==1) {
-               cam->id.lib= NULL;
-               cam->id.flag= LIB_LOCAL;
-               new_id(&bmain->camera, (ID *)cam, NULL);
+               id_clear_lib_data(bmain, (ID *)cam);
                return;
        }
        
@@ -774,9 +768,7 @@ void make_local_camera(Camera *cam)
        }
        
        if(local && lib==0) {
-               cam->id.lib= NULL;
-               cam->id.flag= LIB_LOCAL;
-               new_id(&bmain->camera, (ID *)cam, NULL);
+               id_clear_lib_data(bmain, (ID *)cam);
        }
        else if(local && lib) {
                Camera *camn= copy_camera(cam);
@@ -925,9 +917,7 @@ void make_local_lamp(Lamp *la)
        
        if(la->id.lib==NULL) return;
        if(la->id.us==1) {
-               la->id.lib= NULL;
-               la->id.flag= LIB_LOCAL;
-               new_id(&bmain->lamp, (ID *)la, NULL);
+               id_clear_lib_data(bmain, (ID *)la);
                return;
        }
        
@@ -941,9 +931,7 @@ void make_local_lamp(Lamp *la)
        }
        
        if(local && lib==0) {
-               la->id.lib= NULL;
-               la->id.flag= LIB_LOCAL;
-               new_id(&bmain->lamp, (ID *)la, NULL);
+               id_clear_lib_data(bmain, (ID *)la);
        }
        else if(local && lib) {
                lan= copy_lamp(la);
@@ -1472,9 +1460,8 @@ void make_local_object(Object *ob)
        ob->proxy= ob->proxy_from= NULL;
        
        if(ob->id.us==1) {
-               ob->id.lib= NULL;
-               ob->id.flag= LIB_LOCAL;
-               new_id(&bmain->object, (ID *)ob, NULL);
+               id_clear_lib_data(bmain, (ID *)ob);
+               extern_local_object(ob);
        }
        else {
                for(sce= bmain->scene.first; sce && ELEM(0, lib, local); sce= sce->id.next) {
@@ -1485,9 +1472,8 @@ void make_local_object(Object *ob)
                }
 
                if(local && lib==0) {
-                       ob->id.lib= NULL;
-                       ob->id.flag= LIB_LOCAL;
-                       new_id(&bmain->object, (ID *)ob, NULL);
+                       id_clear_lib_data(bmain, (ID *)ob);
+                       extern_local_object(ob);
                }
                else if(local && lib) {
                        Object *obn= copy_object(ob);
@@ -1510,8 +1496,6 @@ void make_local_object(Object *ob)
                        }
                }
        }
-       
-       extern_local_object(ob);
 }
 
 /*
@@ -1649,7 +1633,7 @@ void object_make_proxy(Object *ob, Object *target, Object *gob)
        if(ob->matbits) MEM_freeN(ob->matbits);
        ob->mat = NULL;
        ob->matbits= NULL;
-       if ((target->totcol) && (target->mat) && ELEM5(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL)) { //XXX OB_SUPPORT_MATERIAL
+       if ((target->totcol) && (target->mat) && OB_TYPE_SUPPORT_MATERIAL(ob->type)) {
                int i;
                ob->colbits = target->colbits;
                
@@ -2350,7 +2334,7 @@ BoundBox *unit_boundbox(void)
        BoundBox *bb;
        float min[3] = {-1.0f,-1.0f,-1.0f}, max[3] = {-1.0f,-1.0f,-1.0f};
 
-       bb= MEM_callocN(sizeof(BoundBox), "bb");
+       bb= MEM_callocN(sizeof(BoundBox), "OB-BoundBox");
        boundbox_set_from_min_max(bb, min, max);
        
        return bb;
@@ -2829,7 +2813,8 @@ void object_sculpt_modifiers_changed(Object *ob)
        }
 }
 
-float give_timeoffset(Object *ob) {
+float give_timeoffset(Object *ob)
+{
        if ((ob->ipoflag & OB_OFFS_PARENTADD) && ob->parent) {
                return ob->sf + give_timeoffset(ob->parent);
        } else {
@@ -2837,7 +2822,8 @@ float give_timeoffset(Object *ob) {
        }
 }
 
-int give_obdata_texspace(Object *ob, short **texflag, float **loc, float **size, float **rot) {
+int give_obdata_texspace(Object *ob, short **texflag, float **loc, float **size, float **rot)
+{
        
        if (ob->data==NULL)
                return 0;
@@ -3055,6 +3041,79 @@ void object_camera_matrix(
 
 }
 
+void camera_view_frame_ex(Scene *scene, Camera *camera, float drawsize, const short do_clip, const float scale[3],
+                          float r_asp[2], float r_shift[2], float *r_drawsize, float r_vec[4][3])
+{
+       float facx, facy;
+       float depth;
+
+       /* aspect correcton */
+       if (scene) {
+               float aspx= (float) scene->r.xsch*scene->r.xasp;
+               float aspy= (float) scene->r.ysch*scene->r.yasp;
+
+               if(aspx < aspy) {
+                       r_asp[0]= aspx / aspy;
+                       r_asp[1]= 1.0;
+               }
+               else {
+                       r_asp[0]= 1.0;
+                       r_asp[1]= aspy / aspx;
+               }
+       }
+       else {
+               r_asp[0]= 1.0f;
+               r_asp[1]= 1.0f;
+       }
+
+       if(camera->type==CAM_ORTHO) {
+               facx= 0.5f * camera->ortho_scale * r_asp[0] * scale[0];
+               facy= 0.5f * camera->ortho_scale * r_asp[1] * scale[1];
+               r_shift[0]= camera->shiftx * camera->ortho_scale * scale[0];
+               r_shift[1]= camera->shifty * camera->ortho_scale * scale[1];
+               depth= do_clip ? -((camera->clipsta * scale[2]) + 0.1f) : - drawsize * camera->ortho_scale * scale[2];
+
+               *r_drawsize= 0.5f * camera->ortho_scale;
+       }
+       else {
+               /* that way it's always visible - clipsta+0.1 */
+               float fac;
+               *r_drawsize= drawsize / ((scale[0] + scale[1] + scale[2]) / 3.0f);
+
+               if(do_clip) {
+                       /* fixed depth, variable size (avoids exceeding clipping range) */
+                       depth = -(camera->clipsta + 0.1f);
+                       fac = depth / (camera->lens/-16.0f * scale[2]);
+               }
+               else {
+                       /* fixed size, variable depth (stays a reasonable size in the 3D view) */
+                       depth= *r_drawsize * camera->lens/-16.0f * scale[2];
+                       fac= *r_drawsize;
+               }
+
+               facx= fac * r_asp[0] * scale[0];
+               facy= fac * r_asp[1] * scale[1];
+               r_shift[0]= camera->shiftx*fac*2 * scale[0];
+               r_shift[1]= camera->shifty*fac*2 * scale[1];
+       }
+
+       r_vec[0][0]= r_shift[0] + facx; r_vec[0][1]= r_shift[1] + facy; r_vec[0][2]= depth;
+       r_vec[1][0]= r_shift[0] + facx; r_vec[1][1]= r_shift[1] - facy; r_vec[1][2]= depth;
+       r_vec[2][0]= r_shift[0] - facx; r_vec[2][1]= r_shift[1] - facy; r_vec[2][2]= depth;
+       r_vec[3][0]= r_shift[0] - facx; r_vec[3][1]= r_shift[1] + facy; r_vec[3][2]= depth;
+}
+
+void camera_view_frame(Scene *scene, Camera *camera, float r_vec[4][3])
+{
+       float dummy_asp[2];
+       float dummy_shift[2];
+       float dummy_drawsize;
+       const float dummy_scale[3]= {1.0f, 1.0f, 1.0f};
+
+       camera_view_frame_ex(scene, camera, FALSE, 1.0, dummy_scale,
+                            dummy_asp, dummy_shift, &dummy_drawsize, r_vec);
+}
+
 #if 0
 static int pc_findindex(ListBase *listbase, int index)
 {