Merging r39717 through r39983 from trunk into soc-2011-tomato
[blender.git] / source / blender / blenkernel / intern / object.c
index 0dc8308..6fc0919 100644 (file)
@@ -714,6 +714,7 @@ void *add_camera(const char *name)
        cam=  alloc_libblock(&G.main->camera, ID_CA, name);
 
        cam->lens= 35.0f;
+       cam->sensor_x = 32.f;
        cam->clipsta= 0.1f;
        cam->clipend= 100.0f;
        cam->drawsize= 0.5f;
@@ -2146,6 +2147,39 @@ void where_is_object_time(Scene *scene, Object *ob, float ctime)
        else                                                    ob->transflag &= ~OB_NEG_SCALE;
 }
 
+/* get object transformation matrix without recalculating dependencies and
+   constraints -- assume dependencies are already solved by depsgraph.
+   no changes to object and it's parent would be done.
+   used for bundles orientation in 3d space relative to parented blender camera */
+void where_is_object_mat(Scene *scene, Object *ob, float obmat[4][4])
+{
+       float *fp1, *fp2, slowmat[4][4] = MAT4_UNITY;
+       float fac1, fac2;
+       int a;
+
+       if(ob->parent) {
+               Object *par= ob->parent;
+
+               solve_parenting(scene, ob, par, obmat, slowmat, 1);
+
+               if(ob->partype & PARSLOW) {
+                       // include framerate
+                       fac1= ( 1.0f / (1.0f + (float)fabs(give_timeoffset(ob))) );
+                       if(fac1 >= 1.0f) return;
+                       fac2= 1.0f-fac1;
+
+                       fp1= obmat[0];
+                       fp2= slowmat[0];
+                       for(a=0; a<16; a++, fp1++, fp2++) {
+                               fp1[0]= fac1*fp1[0] + fac2*fp2[0];
+                       }
+               }
+       }
+       else {
+               object_to_mat4(ob, obmat);
+       }
+}
+
 static void solve_parenting (Scene *scene, Object *ob, Object *par, float obmat[][4], float slowmat[][4], int simul)
 {
        float totmat[4][4];
@@ -2876,7 +2910,7 @@ void object_camera_mode(RenderData *rd, Object *camera)
 /* 'lens' may be set for envmap only */
 void object_camera_matrix(
                RenderData *rd, Object *camera, int winx, int winy, short field_second,
-               float winmat[][4], rctf *viewplane, float *clipsta, float *clipend, float *lens, float *ycor,
+               float winmat[][4], rctf *viewplane, float *clipsta, float *clipend, float *lens, float *sensor_x, float *ycor,
                float *viewdx, float *viewdy
 ) {
        Camera *cam=NULL;
@@ -2909,6 +2943,7 @@ void object_camera_matrix(
                shiftx=cam->shiftx;
                shifty=cam->shifty;
                (*lens)= cam->lens;
+               (*sensor_x)= cam->sensor_x;
                (*clipsta)= cam->clipsta;
                (*clipend)= cam->clipend;
        }
@@ -2924,7 +2959,7 @@ void object_camera_matrix(
                (*clipend)= la->clipend;
        }
        else {  /* envmap exception... */;
-               if((*lens)==0.0f)
+               if((*lens)==0.0f) /* is this needed anymore? */
                        (*lens)= 16.0f;
 
                if((*clipsta)==0.0f || (*clipend)==0.0f) {
@@ -2945,8 +2980,8 @@ void object_camera_matrix(
                pixsize= cam->ortho_scale/viewfac;
        }
        else {
-               if(rd->xasp*winx >= rd->yasp*winy)      viewfac= ((*lens) * winx)/32.0f;
-               else                                                            viewfac= (*ycor) * ((*lens) * winy)/32.0f;
+               if(rd->xasp*winx >= rd->yasp*winy)      viewfac= ((*lens) * winx) / (*sensor_x);
+               else                                    viewfac= (*ycor) * ((*lens) * winy) / (*sensor_x);
                pixsize= (*clipsta) / viewfac;
        }